cargo/tests/testsuite/dep_info.rs

113 lines
2.7 KiB
Rust
Raw Normal View History

2018-12-06 19:17:36 +00:00
use crate::support::{basic_bin_manifest, main_file, project};
2018-12-08 11:19:47 +00:00
use filetime::FileTime;
#[cargo_test]
fn build_dep_info() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.build();
p.cargo("build").run();
let depinfo_bin_path = &p.bin("foo").with_extension("d");
2018-08-29 06:11:10 +00:00
assert!(depinfo_bin_path.is_file());
let depinfo = p.read_file(depinfo_bin_path.to_str().unwrap());
let bin_path = p.bin("foo");
let src_path = p.root().join("src").join("foo.rs");
let expected_depinfo = format!("{}: {}\n", bin_path.display(), src_path.display());
assert_eq!(depinfo, expected_depinfo);
}
#[cargo_test]
fn build_dep_info_lib() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[[example]]
name = "ex"
crate-type = ["lib"]
2018-03-14 15:17:44 +00:00
"#,
2018-12-08 11:19:47 +00:00
)
.file("build.rs", "fn main() {}")
.file("src/lib.rs", "")
.file("examples/ex.rs", "")
.build();
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());
}
#[cargo_test]
fn build_dep_info_rlib() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[[example]]
name = "ex"
crate-type = ["rlib"]
2018-03-14 15:17:44 +00:00
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.file("examples/ex.rs", "")
.build();
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());
}
#[cargo_test]
fn build_dep_info_dylib() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[[example]]
name = "ex"
crate-type = ["dylib"]
2018-03-14 15:17:44 +00:00
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.file("examples/ex.rs", "")
.build();
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());
}
#[cargo_test]
fn no_rewrite_if_no_change() {
let p = project().file("src/lib.rs", "").build();
p.cargo("build").run();
let dep_info = p.root().join("target/debug/libfoo.d");
let metadata1 = dep_info.metadata().unwrap();
p.cargo("build").run();
let metadata2 = dep_info.metadata().unwrap();
assert_eq!(
FileTime::from_last_modification_time(&metadata1),
FileTime::from_last_modification_time(&metadata2),
);
}