Skip to content

Commit b8fd7b3

Browse files
committed
Add some new syntax tests
Signed-off-by: hi-rustin <[email protected]>
1 parent b82742c commit b8fd7b3

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

tests/testsuite/build_script.rs

+93
Original file line numberDiff line numberDiff line change
@@ -5165,3 +5165,96 @@ fn custom_build_closes_stdin() {
51655165
.build();
51665166
p.cargo("build").run();
51675167
}
5168+
5169+
#[cargo_test]
5170+
fn test_both_two_semicolons_and_one_semicolon_syntax() {
5171+
let p = project()
5172+
.file(
5173+
"Cargo.toml",
5174+
r#"
5175+
[package]
5176+
name = "foo"
5177+
version = "0.0.1"
5178+
authors = []
5179+
build = "build.rs"
5180+
"#,
5181+
)
5182+
.file(
5183+
"src/main.rs",
5184+
r#"
5185+
const FOO: &'static str = env!("FOO");
5186+
const BAR: &'static str = env!("BAR");
5187+
fn main() {
5188+
println!("{}", FOO);
5189+
println!("{}", BAR);
5190+
}
5191+
"#,
5192+
)
5193+
.file(
5194+
"build.rs",
5195+
r#"fn main() {
5196+
println!("cargo::rustc-env=FOO=foo");
5197+
println!("cargo:rustc-env=BAR=bar");
5198+
println!("cargo:foo=foo");
5199+
println!("cargo::metadata=bar=bar");
5200+
}"#,
5201+
)
5202+
.build();
5203+
p.cargo("build -v").run();
5204+
p.cargo("run -v").with_stdout("foo\nbar\n").run();
5205+
}
5206+
5207+
#[cargo_test]
5208+
fn test_invalid_new_syntaxes() {
5209+
// `metadata` can not be used with the reserved keys.
5210+
let p = project()
5211+
.file("src/lib.rs", "")
5212+
.file(
5213+
"build.rs",
5214+
r#"
5215+
fn main() {
5216+
println!("cargo::metadata=rerun-if-changed=somedir");
5217+
}
5218+
"#,
5219+
)
5220+
.build();
5221+
5222+
p.cargo("build")
5223+
.with_status(101)
5224+
.with_stderr(
5225+
"\
5226+
[COMPILING] foo [..]
5227+
error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo::metadata=rerun-if-changed=somedir`
5228+
The reserved key cannot be used in the `cargo::metadata=` syntax. Please use `cargo::rerun-if-changed=VAlUE` instead.
5229+
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
5230+
for more information about build script outputs.
5231+
",
5232+
)
5233+
.run();
5234+
5235+
// `cargo::` can not be used with the non-reserved keys.
5236+
let p = project()
5237+
.file("src/lib.rs", "")
5238+
.file(
5239+
"build.rs",
5240+
r#"
5241+
fn main() {
5242+
println!("cargo::foo=bar");
5243+
}
5244+
"#,
5245+
)
5246+
.build();
5247+
5248+
p.cargo("build")
5249+
.with_status(101)
5250+
.with_stderr(
5251+
"\
5252+
[COMPILING] foo [..]
5253+
error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo::foo=bar`
5254+
Expected a line with `cargo::metadata=KEY=VALUE` but it did not have the `metadata=` part.
5255+
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
5256+
for more information about build script outputs.
5257+
",
5258+
)
5259+
.run();
5260+
}

0 commit comments

Comments
 (0)