0 | |
From b3efc44c3d18cec312594040f0f09f7d39f00832 Mon Sep 17 00:00:00 2001
|
1 | |
From: Robin Krahl <github@ireas.org>
|
2 | |
Date: Mon, 27 Jan 2020 20:59:52 +0100
|
3 | |
Subject: [PATCH] Clear CFLAGS and CXXFLAGS before tests (#472)
|
4 | |
|
5 | |
Some test cases check that a compiler flag is not present. But
|
6 | |
cc::Build loads additional flags from the CFLAGS and CXXFLAGS
|
7 | |
environment variables. If these are set, they might interfere with the
|
8 | |
test cases.
|
9 | |
|
10 | |
Therefore we clear the CFLAGS and CXXFLAGS environment variables before
|
11 | |
running a test that requires an absent flag.
|
12 | |
---
|
13 | |
tests/test.rs | 36 ++++++++++++++++++++++++++++++++++++
|
14 | |
1 file changed, 36 insertions(+)
|
15 | |
|
16 | |
diff --git a/tests/test.rs b/tests/test.rs
|
17 | |
index def11f02..3c9b4dc4 100644
|
18 | |
--- a/tests/test.rs
|
19 | |
+++ b/tests/test.rs
|
20 | |
@@ -2,8 +2,18 @@ use crate::support::Test;
|
21 | |
|
22 | |
mod support;
|
23 | |
|
24 | |
+// Some tests check that a flag is *not* present. These tests might fail if the flag is set in the
|
25 | |
+// CFLAGS or CXXFLAGS environment variables. This function clears the CFLAGS and CXXFLAGS
|
26 | |
+// variables to make sure that the tests can run correctly.
|
27 | |
+fn reset_env() {
|
28 | |
+ std::env::set_var("CFLAGS", "");
|
29 | |
+ std::env::set_var("CXXFLAGS", "");
|
30 | |
+}
|
31 | |
+
|
32 | |
#[test]
|
33 | |
fn gnu_smoke() {
|
34 | |
+ reset_env();
|
35 | |
+
|
36 | |
let test = Test::gnu();
|
37 | |
test.gcc().file("foo.c").compile("foo");
|
38 | |
|
39 | |
@@ -19,6 +29,8 @@ fn gnu_smoke() {
|
40 | |
|
41 | |
#[test]
|
42 | |
fn gnu_opt_level_1() {
|
43 | |
+ reset_env();
|
44 | |
+
|
45 | |
let test = Test::gnu();
|
46 | |
test.gcc().opt_level(1).file("foo.c").compile("foo");
|
47 | |
|
48 | |
@@ -27,6 +39,8 @@ fn gnu_opt_level_1() {
|
49 | |
|
50 | |
#[test]
|
51 | |
fn gnu_opt_level_s() {
|
52 | |
+ reset_env();
|
53 | |
+
|
54 | |
let test = Test::gnu();
|
55 | |
test.gcc().opt_level_str("s").file("foo.c").compile("foo");
|
56 | |
|
57 | |
@@ -56,6 +70,8 @@ fn gnu_debug_fp() {
|
58 | |
|
59 | |
#[test]
|
60 | |
fn gnu_debug_nofp() {
|
61 | |
+ reset_env();
|
62 | |
+
|
63 | |
let test = Test::gnu();
|
64 | |
test.gcc()
|
65 | |
.debug(true)
|
66 | |
@@ -100,6 +116,8 @@ fn gnu_warnings() {
|
67 | |
|
68 | |
#[test]
|
69 | |
fn gnu_extra_warnings0() {
|
70 | |
+ reset_env();
|
71 | |
+
|
72 | |
let test = Test::gnu();
|
73 | |
test.gcc()
|
74 | |
.warnings(true)
|
75 | |
@@ -113,6 +131,8 @@ fn gnu_extra_warnings0() {
|
76 | |
|
77 | |
#[test]
|
78 | |
fn gnu_extra_warnings1() {
|
79 | |
+ reset_env();
|
80 | |
+
|
81 | |
let test = Test::gnu();
|
82 | |
test.gcc()
|
83 | |
.warnings(false)
|
84 | |
@@ -126,6 +146,8 @@ fn gnu_extra_warnings1() {
|
85 | |
|
86 | |
#[test]
|
87 | |
fn gnu_warnings_overridable() {
|
88 | |
+ reset_env();
|
89 | |
+
|
90 | |
let test = Test::gnu();
|
91 | |
test.gcc()
|
92 | |
.warnings(true)
|
93 | |
@@ -154,6 +176,8 @@ fn gnu_x86_64() {
|
94 | |
|
95 | |
#[test]
|
96 | |
fn gnu_x86_64_no_pic() {
|
97 | |
+ reset_env();
|
98 | |
+
|
99 | |
for vendor in &["unknown-linux-gnu", "apple-darwin"] {
|
100 | |
let target = format!("x86_64-{}", vendor);
|
101 | |
let test = Test::gnu();
|
102 | |
@@ -215,6 +239,8 @@ fn gnu_x86_64_no_plt() {
|
103 | |
|
104 | |
#[test]
|
105 | |
fn gnu_set_stdlib() {
|
106 | |
+ reset_env();
|
107 | |
+
|
108 | |
let test = Test::gnu();
|
109 | |
test.gcc()
|
110 | |
.cpp_set_stdlib(Some("foo"))
|
111 | |
@@ -253,6 +279,8 @@ fn gnu_compile_assembly() {
|
112 | |
|
113 | |
#[test]
|
114 | |
fn gnu_shared() {
|
115 | |
+ reset_env();
|
116 | |
+
|
117 | |
let test = Test::gnu();
|
118 | |
test.gcc()
|
119 | |
.file("foo.c")
|
120 | |
@@ -265,6 +293,8 @@ fn gnu_shared() {
|
121 | |
|
122 | |
#[test]
|
123 | |
fn gnu_flag_if_supported() {
|
124 | |
+ reset_env();
|
125 | |
+
|
126 | |
if cfg!(windows) {
|
127 | |
return;
|
128 | |
}
|
129 | |
@@ -301,6 +331,8 @@ fn gnu_flag_if_supported_cpp() {
|
130 | |
|
131 | |
#[test]
|
132 | |
fn gnu_static() {
|
133 | |
+ reset_env();
|
134 | |
+
|
135 | |
let test = Test::gnu();
|
136 | |
test.gcc()
|
137 | |
.file("foo.c")
|
138 | |
@@ -313,6 +345,8 @@ fn gnu_static() {
|
139 | |
|
140 | |
#[test]
|
141 | |
fn msvc_smoke() {
|
142 | |
+ reset_env();
|
143 | |
+
|
144 | |
let test = Test::msvc();
|
145 | |
test.gcc().file("foo.c").compile("foo");
|
146 | |
|
147 | |
@@ -327,6 +361,8 @@ fn msvc_smoke() {
|
148 | |
|
149 | |
#[test]
|
150 | |
fn msvc_opt_level_0() {
|
151 | |
+ reset_env();
|
152 | |
+
|
153 | |
let test = Test::msvc();
|
154 | |
test.gcc().opt_level(0).file("foo.c").compile("foo");
|
155 | |
|