Browse Source

Move env var tests into separate modules

Tests that modify environment variables (e.g. CFLAGS and CXXFLAGS) can
cause tests to fail when run in parallel because they change a shared
context.

This change moves the problematic tests into separate modules. Since
each `tests/*.rs` is compiled as a separate crate, these tests are not
run in parallel with other tests.
wip-new-parallel
Sean Leather 6 years ago
parent
commit
d09804846d
  1. 18
      tests/cflags.rs
  2. 18
      tests/cxxflags.rs
  3. 21
      tests/test.rs

18
tests/cflags.rs

@ -0,0 +1,18 @@
extern crate cc;
extern crate tempdir;
mod support;
use std::env;
use support::Test;
/// This test is in its own module because it modifies the environment and would affect other tests
/// when run in parallel with them.
#[test]
fn gnu_no_warnings_if_cflags() {
env::set_var("CFLAGS", "-arbitrary");
let test = Test::gnu();
test.gcc().file("foo.c").compile("foo");
test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra");
}

18
tests/cxxflags.rs

@ -0,0 +1,18 @@
extern crate cc;
extern crate tempdir;
mod support;
use std::env;
use support::Test;
/// This test is in its own module because it modifies the environment and would affect other tests
/// when run in parallel with them.
#[test]
fn gnu_no_warnings_if_cxxflags() {
env::set_var("CXXFLAGS", "-arbitrary");
let test = Test::gnu();
test.gcc().file("foo.cpp").cpp(true).compile("foo");
test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra");
}

21
tests/test.rs

@ -1,7 +1,6 @@
extern crate cc; extern crate cc;
extern crate tempdir; extern crate tempdir;
use std::env;
use support::Test; use support::Test;
mod support; mod support;
@ -111,26 +110,6 @@ fn gnu_warnings_overridable() {
.must_have_in_order("-Wall", "-Wno-missing-field-initializers"); .must_have_in_order("-Wall", "-Wno-missing-field-initializers");
} }
#[test]
fn gnu_no_warnings_if_cflags() {
env::set_var("CFLAGS", "-Wflag-does-not-exist");
let test = Test::gnu();
test.gcc().file("foo.c").compile("foo");
test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra");
env::set_var("CFLAGS", "");
}
#[test]
fn gnu_no_warnings_if_cxxflags() {
env::set_var("CXXFLAGS", "-Wflag-does-not-exist");
let test = Test::gnu();
test.gcc().file("foo.c").compile("foo");
test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra");
env::set_var("CXXFLAGS", "");
}
#[test] #[test]
fn gnu_x86_64() { fn gnu_x86_64() {
for vendor in &["unknown-linux-gnu", "apple-darwin"] { for vendor in &["unknown-linux-gnu", "apple-darwin"] {

Loading…
Cancel
Save