2017-06-05 14:52:31 +00:00
|
|
|
use std::fs::File;
|
|
|
|
|
2018-07-21 21:17:44 +00:00
|
|
|
use support::sleep_ms;
|
|
|
|
use support::{execs, project};
|
|
|
|
use support::hamcrest::assert_that;
|
2017-06-05 14:52:31 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rerun_if_env_changes() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-06-05 14:52:31 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
2017-06-05 14:52:31 +00:00
|
|
|
fn main() {
|
|
|
|
println!("cargo:rerun-if-env-changed=FOO");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-06-05 14:52:31 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2018-07-24 13:01:56 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-06-05 14:52:31 +00:00
|
|
|
[FINISHED] [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").env("FOO", "bar"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2018-07-24 13:01:56 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-06-05 14:52:31 +00:00
|
|
|
[FINISHED] [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").env("FOO", "baz"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2018-07-24 13:01:56 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-06-05 14:52:31 +00:00
|
|
|
[FINISHED] [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").env("FOO", "baz"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs().with_status(0).with_stderr("[FINISHED] [..]"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2018-07-24 13:01:56 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-06-05 14:52:31 +00:00
|
|
|
[FINISHED] [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2017-06-05 14:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rerun_if_env_or_file_changes() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-06-05 14:52:31 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
2017-06-05 14:52:31 +00:00
|
|
|
fn main() {
|
|
|
|
println!("cargo:rerun-if-env-changed=FOO");
|
|
|
|
println!("cargo:rerun-if-changed=foo");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("foo", "")
|
|
|
|
.build();
|
2017-06-05 14:52:31 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2018-07-24 13:01:56 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-06-05 14:52:31 +00:00
|
|
|
[FINISHED] [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").env("FOO", "bar"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2018-07-24 13:01:56 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-06-05 14:52:31 +00:00
|
|
|
[FINISHED] [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
p.cargo("build").env("FOO", "bar"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs().with_status(0).with_stderr("[FINISHED] [..]"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2017-06-05 14:52:31 +00:00
|
|
|
sleep_ms(1000);
|
|
|
|
File::create(p.root().join("foo")).unwrap();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build").env("FOO", "bar"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2018-07-24 13:01:56 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-06-05 14:52:31 +00:00
|
|
|
[FINISHED] [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2017-06-05 14:52:31 +00:00
|
|
|
}
|