Skip to content

Commit eabea47

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

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

tests/testsuite/build_script.rs

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

0 commit comments

Comments
 (0)