aboutsummaryrefslogtreecommitdiff
path: root/cc/tests
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2018-12-10 21:02:04 -0800
committerDaniel Mueller <deso@posteo.net>2018-12-10 21:02:04 -0800
commit8898de1f97aff9965e1518ca5abb554275183a14 (patch)
treeac7deb92599ec56d67432766b2cf4cd63388833a /cc/tests
parente2604a756aaddcd5919ee2f1b9cc0055d200f846 (diff)
downloadnitrocli-8898de1f97aff9965e1518ca5abb554275183a14.tar.gz
nitrocli-8898de1f97aff9965e1518ca5abb554275183a14.tar.bz2
Update cc crate to 1.0.25
This change updates the cc crate to version 1.0.25. Import subrepo cc/:cc at fe0a7acb6d3e22e03bf83bcbf89367be888b5448
Diffstat (limited to 'cc/tests')
-rw-r--r--cc/tests/cc_env.rs46
-rw-r--r--cc/tests/support/mod.rs19
-rw-r--r--cc/tests/test.rs142
3 files changed, 136 insertions, 71 deletions
diff --git a/cc/tests/cc_env.rs b/cc/tests/cc_env.rs
index 8ffe651..f9386d7 100644
--- a/cc/tests/cc_env.rs
+++ b/cc/tests/cc_env.rs
@@ -14,6 +14,10 @@ fn main() {
distcc();
ccache_spaces();
ccache_env_flags();
+ leading_spaces();
+ extra_flags();
+ path_to_ccache();
+ more_spaces();
}
fn ccache() {
@@ -71,3 +75,45 @@ fn ccache_env_flags() {
env::set_var("CC", "");
}
+
+fn leading_spaces() {
+ let test = Test::gnu();
+ test.shim("ccache");
+
+ env::set_var("CC", " test ");
+ let compiler = test.gcc().file("foo.c").get_compiler();
+ assert_eq!(compiler.path(), Path::new("test"));
+
+ env::set_var("CC", "");
+}
+
+fn extra_flags() {
+ let test = Test::gnu();
+ test.shim("ccache");
+
+ env::set_var("CC", "ccache cc -m32");
+ let compiler = test.gcc().file("foo.c").get_compiler();
+ assert_eq!(compiler.path(), Path::new("cc"));
+}
+
+fn path_to_ccache() {
+ let test = Test::gnu();
+ test.shim("ccache");
+
+ env::set_var("CC", "/path/to/ccache.exe cc -m32");
+ let compiler = test.gcc().file("foo.c").get_compiler();
+ assert_eq!(compiler.path(), Path::new("cc"));
+ assert_eq!(
+ compiler.cc_env(),
+ OsString::from("/path/to/ccache.exe cc -m32"),
+ );
+}
+
+fn more_spaces() {
+ let test = Test::gnu();
+ test.shim("ccache");
+
+ env::set_var("CC", "cc -m32");
+ let compiler = test.gcc().file("foo.c").get_compiler();
+ assert_eq!(compiler.path(), Path::new("cc"));
+}
diff --git a/cc/tests/support/mod.rs b/cc/tests/support/mod.rs
index bb56bf3..cae8151 100644
--- a/cc/tests/support/mod.rs
+++ b/cc/tests/support/mod.rs
@@ -85,7 +85,9 @@ impl Test {
.unwrap()
.read_to_string(&mut s)
.unwrap();
- Execution { args: s.lines().map(|s| s.to_string()).collect() }
+ Execution {
+ args: s.lines().map(|s| s.to_string()).collect(),
+ }
}
}
@@ -111,11 +113,18 @@ impl Execution {
}
pub fn must_have_in_order(&self, before: &str, after: &str) -> &Execution {
- let before_position = self.args.iter().rposition(|x| OsStr::new(x) == OsStr::new(before));
- let after_position = self.args.iter().rposition(|x| OsStr::new(x) == OsStr::new(after));
+ let before_position = self.args
+ .iter()
+ .rposition(|x| OsStr::new(x) == OsStr::new(before));
+ let after_position = self.args
+ .iter()
+ .rposition(|x| OsStr::new(x) == OsStr::new(after));
match (before_position, after_position) {
- (Some(b), Some(a)) if b < a => {},
- (b, a) => { panic!("{:?} (last position: {:?}) did not appear before {:?} (last position: {:?})", before, b, after, a) },
+ (Some(b), Some(a)) if b < a => {}
+ (b, a) => panic!(
+ "{:?} (last position: {:?}) did not appear before {:?} (last position: {:?})",
+ before, b, after, a
+ ),
};
self
}
diff --git a/cc/tests/test.rs b/cc/tests/test.rs
index 7e5a28d..820072f 100644
--- a/cc/tests/test.rs
+++ b/cc/tests/test.rs
@@ -1,6 +1,7 @@
extern crate cc;
extern crate tempdir;
+use std::env;
use support::Test;
mod support;
@@ -8,9 +9,7 @@ mod support;
#[test]
fn gnu_smoke() {
let test = Test::gnu();
- test.gcc()
- .file("foo.c")
- .compile("foo");
+ test.gcc().file("foo.c").compile("foo");
test.cmd(0)
.must_have("-O2")
@@ -25,23 +24,15 @@ fn gnu_smoke() {
#[test]
fn gnu_opt_level_1() {
let test = Test::gnu();
- test.gcc()
- .opt_level(1)
- .file("foo.c")
- .compile("foo");
+ test.gcc().opt_level(1).file("foo.c").compile("foo");
- test.cmd(0)
- .must_have("-O1")
- .must_not_have("-O2");
+ test.cmd(0).must_have("-O1").must_not_have("-O2");
}
#[test]
fn gnu_opt_level_s() {
let test = Test::gnu();
- test.gcc()
- .opt_level_str("s")
- .file("foo.c")
- .compile("foo");
+ test.gcc().opt_level_str("s").file("foo.c").compile("foo");
test.cmd(0)
.must_have("-Os")
@@ -54,10 +45,7 @@ fn gnu_opt_level_s() {
#[test]
fn gnu_debug() {
let test = Test::gnu();
- test.gcc()
- .debug(true)
- .file("foo.c")
- .compile("foo");
+ test.gcc().debug(true).file("foo.c").compile("foo");
test.cmd(0).must_have("-g");
}
@@ -81,8 +69,33 @@ fn gnu_warnings() {
.file("foo.c")
.compile("foo");
- test.cmd(0).must_have("-Wall")
- .must_have("-Wextra");
+ test.cmd(0).must_have("-Wall").must_have("-Wextra");
+}
+
+#[test]
+fn gnu_extra_warnings0() {
+ let test = Test::gnu();
+ test.gcc()
+ .warnings(true)
+ .extra_warnings(false)
+ .flag("-Wno-missing-field-initializers")
+ .file("foo.c")
+ .compile("foo");
+
+ test.cmd(0).must_have("-Wall").must_not_have("-Wextra");
+}
+
+#[test]
+fn gnu_extra_warnings1() {
+ let test = Test::gnu();
+ test.gcc()
+ .warnings(false)
+ .extra_warnings(true)
+ .flag("-Wno-missing-field-initializers")
+ .file("foo.c")
+ .compile("foo");
+
+ test.cmd(0).must_not_have("-Wall").must_have("-Wextra");
}
#[test]
@@ -94,7 +107,32 @@ fn gnu_warnings_overridable() {
.file("foo.c")
.compile("foo");
- test.cmd(0).must_have_in_order("-Wall", "-Wno-missing-field-initializers");
+ test.cmd(0)
+ .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]
@@ -108,9 +146,7 @@ fn gnu_x86_64() {
.file("foo.c")
.compile("foo");
- test.cmd(0)
- .must_have("-fPIC")
- .must_have("-m64");
+ test.cmd(0).must_have("-fPIC").must_have("-m64");
}
}
@@ -141,8 +177,7 @@ fn gnu_i686() {
.file("foo.c")
.compile("foo");
- test.cmd(0)
- .must_have("-m32");
+ test.cmd(0).must_have("-m32");
}
}
@@ -176,10 +211,7 @@ fn gnu_set_stdlib() {
#[test]
fn gnu_include() {
let test = Test::gnu();
- test.gcc()
- .include("foo/bar")
- .file("foo.c")
- .compile("foo");
+ test.gcc().include("foo/bar").file("foo.c").compile("foo");
test.cmd(0).must_have("-I").must_have("foo/bar");
}
@@ -199,9 +231,7 @@ fn gnu_define() {
#[test]
fn gnu_compile_assembly() {
let test = Test::gnu();
- test.gcc()
- .file("foo.S")
- .compile("foo");
+ test.gcc().file("foo.S").compile("foo");
test.cmd(0).must_have("foo.S");
}
@@ -214,25 +244,25 @@ fn gnu_shared() {
.static_flag(false)
.compile("foo");
- test.cmd(0)
- .must_have("-shared")
- .must_not_have("-static");
+ test.cmd(0).must_have("-shared").must_not_have("-static");
}
#[test]
fn gnu_flag_if_supported() {
if cfg!(windows) {
- return
+ return;
}
let test = Test::gnu();
test.gcc()
.file("foo.c")
+ .flag("-v")
.flag_if_supported("-Wall")
.flag_if_supported("-Wflag-does-not-exist")
.flag_if_supported("-std=c++11")
.compile("foo");
test.cmd(0)
+ .must_have("-v")
.must_have("-Wall")
.must_not_have("-Wflag-does-not-exist")
.must_not_have("-std=c++11");
@@ -241,7 +271,7 @@ fn gnu_flag_if_supported() {
#[test]
fn gnu_flag_if_supported_cpp() {
if cfg!(windows) {
- return
+ return;
}
let test = Test::gnu();
test.gcc()
@@ -250,8 +280,7 @@ fn gnu_flag_if_supported_cpp() {
.flag_if_supported("-std=c++11")
.compile("foo");
- test.cmd(0)
- .must_have("-std=c++11");
+ test.cmd(0).must_have("-std=c++11");
}
#[test]
@@ -263,17 +292,13 @@ fn gnu_static() {
.static_flag(true)
.compile("foo");
- test.cmd(0)
- .must_have("-static")
- .must_not_have("-shared");
+ test.cmd(0).must_have("-static").must_not_have("-shared");
}
#[test]
fn msvc_smoke() {
let test = Test::msvc();
- test.gcc()
- .file("foo.c")
- .compile("foo");
+ test.gcc().file("foo.c").compile("foo");
test.cmd(0)
.must_have("/O2")
@@ -287,10 +312,7 @@ fn msvc_smoke() {
#[test]
fn msvc_opt_level_0() {
let test = Test::msvc();
- test.gcc()
- .opt_level(0)
- .file("foo.c")
- .compile("foo");
+ test.gcc().opt_level(0).file("foo.c").compile("foo");
test.cmd(0).must_not_have("/O2");
}
@@ -298,20 +320,14 @@ fn msvc_opt_level_0() {
#[test]
fn msvc_debug() {
let test = Test::msvc();
- test.gcc()
- .debug(true)
- .file("foo.c")
- .compile("foo");
+ test.gcc().debug(true).file("foo.c").compile("foo");
test.cmd(0).must_have("/Z7");
}
#[test]
fn msvc_include() {
let test = Test::msvc();
- test.gcc()
- .include("foo/bar")
- .file("foo.c")
- .compile("foo");
+ test.gcc().include("foo/bar").file("foo.c").compile("foo");
test.cmd(0).must_have("/I").must_have("foo/bar");
}
@@ -331,10 +347,7 @@ fn msvc_define() {
#[test]
fn msvc_static_crt() {
let test = Test::msvc();
- test.gcc()
- .static_crt(true)
- .file("foo.c")
- .compile("foo");
+ test.gcc().static_crt(true).file("foo.c").compile("foo");
test.cmd(0).must_have("/MT");
}
@@ -342,10 +355,7 @@ fn msvc_static_crt() {
#[test]
fn msvc_no_static_crt() {
let test = Test::msvc();
- test.gcc()
- .static_crt(false)
- .file("foo.c")
- .compile("foo");
+ test.gcc().static_crt(false).file("foo.c").compile("foo");
test.cmd(0).must_have("/MD");
}