2018-04-03 13:06:56 +00:00
|
|
|
use std::env;
|
2018-08-28 09:20:03 +00:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::path::Path;
|
2018-04-03 13:06:56 +00:00
|
|
|
|
2018-07-21 21:17:44 +00:00
|
|
|
use support::hamcrest::assert_that;
|
2018-04-03 13:06:56 +00:00
|
|
|
|
2018-07-24 22:35:01 +00:00
|
|
|
use support::{basic_manifest, execs, project};
|
2018-08-28 09:20:03 +00:00
|
|
|
use support::{process, sleep_ms};
|
2018-04-03 06:51:52 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn binary_with_debug() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 06:51:52 +00:00
|
|
|
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 06:51:52 +00:00
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["foo"],
|
2018-04-03 15:23:02 +00:00
|
|
|
&["foo", "foo.dSYM"],
|
2018-04-03 06:51:52 +00:00
|
|
|
&["foo.exe", "foo.pdb"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn static_library_with_debug() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 06:51:52 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
crate-type = ["staticlib"]
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-04-03 06:51:52 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn foo() { println!("Hello, World!") }
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-04-03 06:51:52 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 06:51:52 +00:00
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["libfoo.a"],
|
|
|
|
&["libfoo.a"],
|
|
|
|
&["foo.lib"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dynamic_library_with_debug() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 06:51:52 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
crate-type = ["cdylib"]
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-04-03 06:51:52 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn foo() { println!("Hello, World!") }
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-04-03 06:51:52 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 06:51:52 +00:00
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["libfoo.so"],
|
2018-04-03 15:23:02 +00:00
|
|
|
&["libfoo.dylib"],
|
2018-04-03 06:51:52 +00:00
|
|
|
&["foo.dll", "foo.dll.lib"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rlib_with_debug() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 06:51:52 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
crate-type = ["rlib"]
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-04-03 06:51:52 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() { println!("Hello, World!") }
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-04-03 06:51:52 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 06:51:52 +00:00
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["libfoo.rlib"],
|
|
|
|
&["libfoo.rlib"],
|
|
|
|
&["libfoo.rlib"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn include_only_the_binary_from_the_current_package() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 06:51:52 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
utils = { path = "./utils" }
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/lib.rs", "extern crate utils;")
|
2018-04-03 06:51:52 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
extern crate foo;
|
|
|
|
extern crate utils;
|
|
|
|
fn main() {
|
|
|
|
println!("Hello, World!")
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("utils/Cargo.toml", &basic_manifest("utils", "0.0.1"))
|
2018-04-03 06:51:52 +00:00
|
|
|
.file("utils/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --bin foo --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 06:51:52 +00:00
|
|
|
check_dir_contents(
|
|
|
|
&p.root().join("out"),
|
|
|
|
&["foo"],
|
2018-04-03 15:23:02 +00:00
|
|
|
&["foo", "foo.dSYM"],
|
2018-04-03 06:51:52 +00:00
|
|
|
&["foo.exe", "foo.pdb"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-03 13:06:56 +00:00
|
|
|
#[test]
|
|
|
|
fn out_dir_is_a_file() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 13:06:56 +00:00
|
|
|
.file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#)
|
|
|
|
.build();
|
|
|
|
File::create(p.root().join("out")).unwrap();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[ERROR] failed to link or copy [..]")
|
|
|
|
.run();
|
2018-04-03 13:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn replaces_artifacts() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-03 13:06:56 +00:00
|
|
|
.file("src/main.rs", r#"fn main() { println!("foo") }"#)
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 13:06:56 +00:00
|
|
|
assert_that(
|
2018-08-28 09:20:03 +00:00
|
|
|
process(
|
|
|
|
&p.root()
|
|
|
|
.join(&format!("out/foo{}", env::consts::EXE_SUFFIX)),
|
|
|
|
),
|
2018-04-03 13:06:56 +00:00
|
|
|
execs().with_stdout("foo"),
|
|
|
|
);
|
|
|
|
|
2018-04-03 15:23:02 +00:00
|
|
|
sleep_ms(1000);
|
|
|
|
p.change_file("src/main.rs", r#"fn main() { println!("bar") }"#);
|
2018-04-03 13:06:56 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -Z unstable-options --out-dir out")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
2018-04-03 13:06:56 +00:00
|
|
|
assert_that(
|
2018-08-28 09:20:03 +00:00
|
|
|
process(
|
|
|
|
&p.root()
|
|
|
|
.join(&format!("out/foo{}", env::consts::EXE_SUFFIX)),
|
|
|
|
),
|
2018-04-03 13:06:56 +00:00
|
|
|
execs().with_stdout("bar"),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-03 06:51:52 +00:00
|
|
|
fn check_dir_contents(
|
|
|
|
out_dir: &Path,
|
|
|
|
expected_linux: &[&str],
|
|
|
|
expected_mac: &[&str],
|
|
|
|
expected_win: &[&str],
|
|
|
|
) {
|
|
|
|
let expected = if cfg!(target_os = "windows") {
|
|
|
|
expected_win
|
|
|
|
} else if cfg!(target_os = "macos") {
|
|
|
|
expected_mac
|
|
|
|
} else {
|
|
|
|
expected_linux
|
|
|
|
};
|
|
|
|
|
|
|
|
let actual = list_dir(out_dir);
|
|
|
|
let mut expected = expected.iter().map(|s| s.to_string()).collect::<Vec<_>>();
|
2018-07-16 20:23:48 +00:00
|
|
|
expected.sort_unstable();
|
2018-04-03 06:51:52 +00:00
|
|
|
assert_eq!(actual, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn list_dir(dir: &Path) -> Vec<String> {
|
|
|
|
let mut res = Vec::new();
|
|
|
|
for entry in fs::read_dir(dir).unwrap() {
|
|
|
|
let entry = entry.unwrap();
|
|
|
|
res.push(entry.file_name().into_string().unwrap());
|
|
|
|
}
|
2018-07-16 20:23:48 +00:00
|
|
|
res.sort_unstable();
|
2018-04-03 06:51:52 +00:00
|
|
|
res
|
|
|
|
}
|