mirror of
https://github.com/rust-lang/cargo
synced 2024-11-05 18:50:39 +00:00
99 lines
1.9 KiB
Rust
99 lines
1.9 KiB
Rust
use std::fs::File;
|
|
|
|
use support::project;
|
|
use support::sleep_ms;
|
|
|
|
#[test]
|
|
fn rerun_if_env_changes() {
|
|
let p = project()
|
|
.file("src/main.rs", "fn main() {}")
|
|
.file(
|
|
"build.rs",
|
|
r#"
|
|
fn main() {
|
|
println!("cargo:rerun-if-env-changed=FOO");
|
|
}
|
|
"#,
|
|
).build();
|
|
|
|
p.cargo("build")
|
|
.with_stderr(
|
|
"\
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
[FINISHED] [..]
|
|
",
|
|
).run();
|
|
p.cargo("build")
|
|
.env("FOO", "bar")
|
|
.with_stderr(
|
|
"\
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
[FINISHED] [..]
|
|
",
|
|
).run();
|
|
p.cargo("build")
|
|
.env("FOO", "baz")
|
|
.with_stderr(
|
|
"\
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
[FINISHED] [..]
|
|
",
|
|
).run();
|
|
p.cargo("build")
|
|
.env("FOO", "baz")
|
|
.with_stderr("[FINISHED] [..]")
|
|
.run();
|
|
p.cargo("build")
|
|
.with_stderr(
|
|
"\
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
[FINISHED] [..]
|
|
",
|
|
).run();
|
|
}
|
|
|
|
#[test]
|
|
fn rerun_if_env_or_file_changes() {
|
|
let p = project()
|
|
.file("src/main.rs", "fn main() {}")
|
|
.file(
|
|
"build.rs",
|
|
r#"
|
|
fn main() {
|
|
println!("cargo:rerun-if-env-changed=FOO");
|
|
println!("cargo:rerun-if-changed=foo");
|
|
}
|
|
"#,
|
|
).file("foo", "")
|
|
.build();
|
|
|
|
p.cargo("build")
|
|
.with_stderr(
|
|
"\
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
[FINISHED] [..]
|
|
",
|
|
).run();
|
|
p.cargo("build")
|
|
.env("FOO", "bar")
|
|
.with_stderr(
|
|
"\
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
[FINISHED] [..]
|
|
",
|
|
).run();
|
|
p.cargo("build")
|
|
.env("FOO", "bar")
|
|
.with_stderr("[FINISHED] [..]")
|
|
.run();
|
|
sleep_ms(1000);
|
|
File::create(p.root().join("foo")).unwrap();
|
|
p.cargo("build")
|
|
.env("FOO", "bar")
|
|
.with_stderr(
|
|
"\
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
[FINISHED] [..]
|
|
",
|
|
).run();
|
|
}
|