From 650f1671ff92e81c061e544afa4fbc8b0c99930f Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Tue, 25 Feb 2020 18:27:35 +0100 Subject: [PATCH] make tests compile --- src/compiler/compiler.rs | 40 +++++++++++++++++++++------------------- src/mock_command.rs | 3 ++- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index 7f37f6c983..9fdf89ff5b 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -1258,7 +1258,7 @@ 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()); @@ -1266,6 +1266,7 @@ LLVM version: 6.0", #[test] fn test_detect_compiler_kind_unknown() { + let f = TestFixture::new(); let creator = new_creator(); let pool = CpuPool::new(1); next_command( @@ -1273,7 +1274,7 @@ LLVM version: 6.0", 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() ); @@ -1281,11 +1282,12 @@ LLVM version: 6.0", #[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() ); @@ -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. @@ -1316,7 +1318,7 @@ LLVM version: 6.0", let storage: Arc = 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. @@ -1420,9 +1422,9 @@ LLVM version: 6.0", let storage: Arc = 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, @@ -1520,9 +1522,9 @@ LLVM version: 6.0", let storage: Arc = 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, @@ -1594,9 +1596,9 @@ LLVM version: 6.0", let storage: Arc = 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 @@ -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. @@ -1768,9 +1770,9 @@ LLVM version: 6.0", let storage: Arc = 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 diff --git a/src/mock_command.rs b/src/mock_command.rs index 99fcd95d18..cf58dcc694 100644 --- a/src/mock_command.rs +++ b/src/mock_command.rs @@ -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(), } @@ -533,6 +533,7 @@ impl CommandCreator for MockCommandCreator { } } + /// To simplify life for using a `CommandCreator` across multiple threads. impl CommandCreatorSync for Arc> { type Cmd = T::Cmd;