5 use std::fs::{self, File};
6 use std::io::prelude::*;
7 use std::path::PathBuf;
18 pub struct Execution {
23 pub fn new() -> Test {
24 let mut gcc = PathBuf::from(env::current_exe().unwrap());
26 if gcc.ends_with("deps") {
29 gcc.push(format!("gcc-shim{}", env::consts::EXE_SUFFIX));
31 td: TempDir::new("gcc-test").unwrap(),
37 pub fn gnu() -> Test {
39 t.shim("cc").shim("ar");
43 pub fn msvc() -> Test {
44 let mut t = Test::new();
45 t.shim("cl").shim("lib.exe");
50 pub fn shim(&self, name: &str) -> &Test {
51 let fname = format!("{}{}", name, env::consts::EXE_SUFFIX);
52 fs::hard_link(&self.gcc, self.td.path().join(&fname))
53 .or_else(|_| fs::copy(&self.gcc, self.td.path().join(&fname)).map(|_| ()))
58 pub fn gcc(&self) -> gcc::Config {
59 let mut cfg = gcc::Config::new();
60 let mut path = env::split_paths(&env::var_os("PATH").unwrap()).collect::<Vec<_>>();
61 path.insert(0, self.td.path().to_owned());
62 let target = if self.msvc {
63 "x86_64-pc-windows-msvc"
65 "x86_64-unknown-linux-gnu"
72 .out_dir(self.td.path())
73 .__set_env("PATH", env::join_paths(path).unwrap())
74 .__set_env("GCCTEST_OUT_DIR", self.td.path());
76 cfg.compiler(self.td.path().join("cl"));
77 cfg.archiver(self.td.path().join("lib.exe"));
82 pub fn cmd(&self, i: u32) -> Execution {
83 let mut s = String::new();
84 File::open(self.td.path().join(format!("out{}", i)))
86 .read_to_string(&mut s)
88 Execution { args: s.lines().map(|s| s.to_string()).collect() }
93 pub fn must_have<P: AsRef<OsStr>>(&self, p: P) -> &Execution {
94 if !self.has(p.as_ref()) {
95 panic!("didn't find {:?} in {:?}", p.as_ref(), self.args);
101 pub fn must_not_have<P: AsRef<OsStr>>(&self, p: P) -> &Execution {
102 if self.has(p.as_ref()) {
103 panic!("found {:?}", p.as_ref());
109 pub fn has(&self, p: &OsStr) -> bool {
110 self.args.iter().any(|arg| OsStr::new(arg) == p)