Skip to content

Commit d098048

Browse files
committed
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.
1 parent 17ef91a commit d098048

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

tests/cflags.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
extern crate cc;
2+
extern crate tempdir;
3+
4+
mod support;
5+
6+
use std::env;
7+
use support::Test;
8+
9+
/// This test is in its own module because it modifies the environment and would affect other tests
10+
/// when run in parallel with them.
11+
#[test]
12+
fn gnu_no_warnings_if_cflags() {
13+
env::set_var("CFLAGS", "-arbitrary");
14+
let test = Test::gnu();
15+
test.gcc().file("foo.c").compile("foo");
16+
17+
test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra");
18+
}

tests/cxxflags.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
extern crate cc;
2+
extern crate tempdir;
3+
4+
mod support;
5+
6+
use std::env;
7+
use support::Test;
8+
9+
/// This test is in its own module because it modifies the environment and would affect other tests
10+
/// when run in parallel with them.
11+
#[test]
12+
fn gnu_no_warnings_if_cxxflags() {
13+
env::set_var("CXXFLAGS", "-arbitrary");
14+
let test = Test::gnu();
15+
test.gcc().file("foo.cpp").cpp(true).compile("foo");
16+
17+
test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra");
18+
}

tests/test.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
extern crate cc;
22
extern crate tempdir;
33

4-
use std::env;
54
use support::Test;
65

76
mod support;
@@ -111,26 +110,6 @@ fn gnu_warnings_overridable() {
111110
.must_have_in_order("-Wall", "-Wno-missing-field-initializers");
112111
}
113112

114-
#[test]
115-
fn gnu_no_warnings_if_cflags() {
116-
env::set_var("CFLAGS", "-Wflag-does-not-exist");
117-
let test = Test::gnu();
118-
test.gcc().file("foo.c").compile("foo");
119-
120-
test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra");
121-
env::set_var("CFLAGS", "");
122-
}
123-
124-
#[test]
125-
fn gnu_no_warnings_if_cxxflags() {
126-
env::set_var("CXXFLAGS", "-Wflag-does-not-exist");
127-
let test = Test::gnu();
128-
test.gcc().file("foo.c").compile("foo");
129-
130-
test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra");
131-
env::set_var("CXXFLAGS", "");
132-
}
133-
134113
#[test]
135114
fn gnu_x86_64() {
136115
for vendor in &["unknown-linux-gnu", "apple-darwin"] {

0 commit comments

Comments
 (0)