Skip to content

Commit

Permalink
make tests compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schuster authored and drahnr committed Feb 26, 2020
1 parent 758dddf commit 650f167
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
40 changes: 21 additions & 19 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ mod test {
&creator,
Ok(MockChild::new(exit_status(0), "foo\nbar\ngcc", "")),
);
let c = detect_compiler(&creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
let c = detect_compiler(creator.clone(), &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap().0;
assert_eq!(CompilerKind::C(CCompilerKind::GCC), c.kind());
Expand All @@ -1180,7 +1180,7 @@ mod test {
&creator,
Ok(MockChild::new(exit_status(0), "clang\nfoo", "")),
);
let c = detect_compiler(&creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
let c = detect_compiler(creator.clone(), &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap().0;
assert_eq!(CompilerKind::C(CCompilerKind::Clang), c.kind());
Expand Down Expand Up @@ -1209,7 +1209,7 @@ mod test {
&creator,
Ok(MockChild::new(exit_status(0), &stdout, &String::new())),
);
let c = detect_compiler(&creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
let c = detect_compiler(creator.clone(), &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap().0;
assert_eq!(CompilerKind::C(CCompilerKind::MSVC), c.kind());
Expand Down Expand Up @@ -1243,7 +1243,7 @@ LLVM version: 6.0",
// rustc --print=sysroot
let sysroot = f.tempdir.path().to_str().unwrap();
next_command(&creator, Ok(MockChild::new(exit_status(0), &sysroot, "")));
let c = detect_compiler(&creator, &rustc, &[], &pool, None)
let c = detect_compiler(creator.clone(), &rustc, f.tempdir.path(),&[], &pool, None)
.wait()
.unwrap().0;
assert_eq!(CompilerKind::Rust, c.kind());
Expand All @@ -1258,34 +1258,36 @@ LLVM version: 6.0",
&creator,
Ok(MockChild::new(exit_status(0), "foo\ndiab\nbar", "")),
);
let c = detect_compiler(&creator, &f.bins[0], &[], &pool, None)
let c = detect_compiler(creator.clone(), &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap().0;
assert_eq!(CompilerKind::C(CCompilerKind::Diab), c.kind());
}

#[test]
fn test_detect_compiler_kind_unknown() {
let f = TestFixture::new();
let creator = new_creator();
let pool = CpuPool::new(1);
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "something", "")),
);
assert!(
detect_compiler(&creator, "/foo/bar".as_ref(), &[], &pool, None)
detect_compiler(creator.clone(), "/foo/bar".as_ref(),f.tempdir.path(), &[], &pool, None)
.wait()
.is_err()
);
}

#[test]
fn test_detect_compiler_kind_process_fail() {
let f = TestFixture::new();
let creator = new_creator();
let pool = CpuPool::new(1);
next_command(&creator, Ok(MockChild::new(exit_status(1), "", "")));
assert!(
detect_compiler(&creator, "/foo/bar".as_ref(), &[], &pool, None)
detect_compiler(creator, "/foo/bar".as_ref(), f.tempdir.path(), &[], &pool, None)
.wait()
.is_err()
);
Expand All @@ -1298,7 +1300,7 @@ LLVM version: 6.0",
let f = TestFixture::new();
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
let c = get_compiler_info(&creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
let c = get_compiler_info(creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap().0;
// sha-1 digest of an empty file.
Expand All @@ -1316,7 +1318,7 @@ LLVM version: 6.0",
let storage: Arc<dyn Storage> = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
let c = get_compiler_info(&creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
let c = get_compiler_info(creator.clone(), &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap().0;
// The preprocessor invocation.
Expand Down Expand Up @@ -1420,9 +1422,9 @@ LLVM version: 6.0",
let storage: Arc<dyn Storage> = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
let c = get_compiler_info(&creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
let c = get_compiler_info(creator.clone(), &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap();
.unwrap().0;
// The preprocessor invocation.
next_command(
&creator,
Expand Down Expand Up @@ -1520,9 +1522,9 @@ LLVM version: 6.0",
let storage: Arc<MockStorage> = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
let c = get_compiler_info(&creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
let c = get_compiler_info(creator.clone(), &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap();
.unwrap().0;
// The preprocessor invocation.
next_command(
&creator,
Expand Down Expand Up @@ -1594,9 +1596,9 @@ LLVM version: 6.0",
let storage: Arc<dyn Storage> = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
let c = get_compiler_info(&creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
let c = get_compiler_info(creator.clone(), &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap();
.unwrap().0;
const COMPILER_STDOUT: &'static [u8] = b"compiler stdout";
const COMPILER_STDERR: &'static [u8] = b"compiler stderr";
// The compiler should be invoked twice, since we're forcing
Expand Down Expand Up @@ -1707,9 +1709,9 @@ LLVM version: 6.0",
f.write_all(b"file contents")?;
Ok(MockChild::new(exit_status(0), "gcc", ""))
});
let c = get_compiler_info(&creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
let c = get_compiler_info(creator.clone(), &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap();
.unwrap().0;
// We should now have a fake object file.
assert_eq!(fs::metadata(&obj).is_ok(), true);
// The preprocessor invocation.
Expand Down Expand Up @@ -1768,9 +1770,9 @@ LLVM version: 6.0",
let storage: Arc<dyn Storage> = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
let c = get_compiler_info(&creator, &f.bins[0], f.tempdir.path(), &[], &pool, None)
let c = get_compiler_info(creator.clone(), &f.bins[0], f.tempdir.path(), &[], &pool, None)
.wait()
.unwrap();
.unwrap().0;
const COMPILER_STDOUT: &'static [u8] = b"compiler stdout";
const COMPILER_STDERR: &'static [u8] = b"compiler stderr";
// The compiler should be invoked twice, since we're forcing
Expand Down
3 changes: 2 additions & 1 deletion src/mock_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ impl MockCommandCreator {
impl CommandCreator for MockCommandCreator {
type Cmd = MockCommand;

fn new(_client: &Client) -> MockCommandCreator {
fn new(client: &Client) -> MockCommandCreator {
MockCommandCreator {
children: Vec::new(),
}
Expand All @@ -533,6 +533,7 @@ impl CommandCreator for MockCommandCreator {
}
}


/// To simplify life for using a `CommandCreator` across multiple threads.
impl<T: CommandCreator + 'static> CommandCreatorSync for Arc<Mutex<T>> {
type Cmd = T::Cmd;
Expand Down

0 comments on commit 650f167

Please sign in to comment.