2018-03-14 20:27:54 +00:00
|
|
|
use filetime::FileTime;
|
2018-08-28 09:20:03 +00:00
|
|
|
use support::{basic_bin_manifest, main_file, project};
|
2017-01-27 00:01:36 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_dep_info() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2017-01-27 00:01:36 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
|
|
|
|
.build();
|
2017-01-27 00:01:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2017-01-27 00:01:36 +00:00
|
|
|
|
|
|
|
let depinfo_bin_path = &p.bin("foo").with_extension("d");
|
|
|
|
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(depinfo_bin_path.is_file());
|
2017-01-27 00:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_dep_info_lib() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-27 00:01:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "ex"
|
|
|
|
crate-type = ["lib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("build.rs", "fn main() {}")
|
2017-01-27 00:01:36 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/ex.rs", "")
|
|
|
|
.build();
|
2017-01-27 00:01:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=ex").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.example_lib("ex", "lib").with_extension("d").is_file());
|
2017-01-27 00:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_dep_info_rlib() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-27 00:01:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "ex"
|
|
|
|
crate-type = ["rlib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/ex.rs", "")
|
|
|
|
.build();
|
2017-01-27 00:01:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=ex").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.example_lib("ex", "rlib").with_extension("d").is_file());
|
2017-01-27 00:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_dep_info_dylib() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-27 00:01:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
name = "ex"
|
|
|
|
crate-type = ["dylib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/ex.rs", "")
|
|
|
|
.build();
|
2017-01-27 00:01:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --example=ex").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.example_lib("ex", "dylib").with_extension("d").is_file());
|
2017-01-27 00:01:36 +00:00
|
|
|
}
|
2018-03-14 20:27:54 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_rewrite_if_no_change() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2018-03-14 20:27:54 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2018-03-14 20:27:54 +00:00
|
|
|
let dep_info = p.root().join("target/debug/libfoo.d");
|
|
|
|
let metadata1 = dep_info.metadata().unwrap();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2018-03-14 20:27:54 +00:00
|
|
|
let metadata2 = dep_info.metadata().unwrap();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
FileTime::from_last_modification_time(&metadata1),
|
|
|
|
FileTime::from_last_modification_time(&metadata2),
|
|
|
|
);
|
|
|
|
}
|