cargo/tests/testsuite/build_script_env.rs

123 lines
2.4 KiB
Rust
Raw Normal View History

use std::fs::File;
use support::sleep_ms;
use support::{execs, project};
use support::hamcrest::assert_that;
#[test]
fn rerun_if_env_changes() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"src/main.rs",
r#"
fn main() {}
2018-03-14 15:17:44 +00:00
"#,
)
.file(
"build.rs",
r#"
fn main() {
println!("cargo:rerun-if-env-changed=FOO");
}
2018-03-14 15:17:44 +00:00
"#,
)
.build();
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 ([..])
[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 ([..])
[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 ([..])
[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 ([..])
[FINISHED] [..]
2018-03-14 15:17:44 +00:00
",
),
);
}
#[test]
fn rerun_if_env_or_file_changes() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"src/main.rs",
r#"
fn main() {}
2018-03-14 15:17:44 +00:00
"#,
)
.file(
"build.rs",
r#"
fn main() {
println!("cargo:rerun-if-env-changed=FOO");
println!("cargo:rerun-if-changed=foo");
}
2018-03-14 15:17:44 +00:00
"#,
)
.file("foo", "")
.build();
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 ([..])
[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 ([..])
[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
);
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 ([..])
[FINISHED] [..]
2018-03-14 15:17:44 +00:00
",
),
);
}