summaryrefslogtreecommitdiff
path: root/gcc/tests/support
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2017-03-26 17:07:27 -0700
committerDaniel Mueller <deso@posteo.net>2017-03-26 17:07:27 -0700
commit86415f23a86b5a44aa000d513500a9d1d0df4bba (patch)
tree5a9c513c9531414502de67dda322fca9baac7563 /gcc/tests/support
parent547085cdefb3372e8c42beabac5d45f2f6b1a535 (diff)
downloadnitrocli-86415f23a86b5a44aa000d513500a9d1d0df4bba.tar.gz
nitrocli-86415f23a86b5a44aa000d513500a9d1d0df4bba.tar.bz2
Import subrepo gcc/:gcc at cf1f00bc038a0df769e14bb85480ab9c12eae08d
Diffstat (limited to 'gcc/tests/support')
-rw-r--r--gcc/tests/support/mod.rs112
1 files changed, 112 insertions, 0 deletions
diff --git a/gcc/tests/support/mod.rs b/gcc/tests/support/mod.rs
new file mode 100644
index 0000000..135a663
--- /dev/null
+++ b/gcc/tests/support/mod.rs
@@ -0,0 +1,112 @@
+#![allow(dead_code)]
+
+use std::env;
+use std::ffi::OsStr;
+use std::fs::{self, File};
+use std::io::prelude::*;
+use std::path::PathBuf;
+
+use gcc;
+use tempdir::TempDir;
+
+pub struct Test {
+ pub td: TempDir,
+ pub gcc: PathBuf,
+ pub msvc: bool,
+}
+
+pub struct Execution {
+ args: Vec<String>,
+}
+
+impl Test {
+ pub fn new() -> Test {
+ let mut gcc = PathBuf::from(env::current_exe().unwrap());
+ gcc.pop();
+ if gcc.ends_with("deps") {
+ gcc.pop();
+ }
+ gcc.push(format!("gcc-shim{}", env::consts::EXE_SUFFIX));
+ Test {
+ td: TempDir::new("gcc-test").unwrap(),
+ gcc: gcc,
+ msvc: false,
+ }
+ }
+
+ pub fn gnu() -> Test {
+ let t = Test::new();
+ t.shim("cc").shim("ar");
+ t
+ }
+
+ pub fn msvc() -> Test {
+ let mut t = Test::new();
+ t.shim("cl").shim("lib.exe");
+ t.msvc = true;
+ t
+ }
+
+ pub fn shim(&self, name: &str) -> &Test {
+ let fname = format!("{}{}", name, env::consts::EXE_SUFFIX);
+ fs::hard_link(&self.gcc, self.td.path().join(&fname))
+ .or_else(|_| fs::copy(&self.gcc, self.td.path().join(&fname)).map(|_| ()))
+ .unwrap();
+ self
+ }
+
+ pub fn gcc(&self) -> gcc::Config {
+ let mut cfg = gcc::Config::new();
+ let mut path = env::split_paths(&env::var_os("PATH").unwrap()).collect::<Vec<_>>();
+ path.insert(0, self.td.path().to_owned());
+ let target = if self.msvc {
+ "x86_64-pc-windows-msvc"
+ } else {
+ "x86_64-unknown-linux-gnu"
+ };
+
+ cfg.target(target)
+ .host(target)
+ .opt_level(2)
+ .debug(false)
+ .out_dir(self.td.path())
+ .__set_env("PATH", env::join_paths(path).unwrap())
+ .__set_env("GCCTEST_OUT_DIR", self.td.path());
+ if self.msvc {
+ cfg.compiler(self.td.path().join("cl"));
+ cfg.archiver(self.td.path().join("lib.exe"));
+ }
+ cfg
+ }
+
+ pub fn cmd(&self, i: u32) -> Execution {
+ let mut s = String::new();
+ File::open(self.td.path().join(format!("out{}", i)))
+ .unwrap()
+ .read_to_string(&mut s)
+ .unwrap();
+ Execution { args: s.lines().map(|s| s.to_string()).collect() }
+ }
+}
+
+impl Execution {
+ pub fn must_have<P: AsRef<OsStr>>(&self, p: P) -> &Execution {
+ if !self.has(p.as_ref()) {
+ panic!("didn't find {:?} in {:?}", p.as_ref(), self.args);
+ } else {
+ self
+ }
+ }
+
+ pub fn must_not_have<P: AsRef<OsStr>>(&self, p: P) -> &Execution {
+ if self.has(p.as_ref()) {
+ panic!("found {:?}", p.as_ref());
+ } else {
+ self
+ }
+ }
+
+ pub fn has(&self, p: &OsStr) -> bool {
+ self.args.iter().any(|arg| OsStr::new(arg) == p)
+ }
+}