Skip to content

Commit

Permalink
Add some new syntax tests
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Jun 4, 2023
1 parent 04ac517 commit 83ae1a8
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5164,3 +5164,122 @@ fn custom_build_closes_stdin() {
.build();
p.cargo("build").run();
}

#[cargo_test]
fn test_both_two_semicolons_and_one_semicolon_syntax() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
build = "build.rs"
"#,
)
.file(
"src/main.rs",
r#"
const FOO: &'static str = env!("FOO");
const BAR: &'static str = env!("BAR");
fn main() {
println!("{}", FOO);
println!("{}", BAR);
}
"#,
)
.file(
"build.rs",
r#"fn main() {
println!("cargo::rustc-env=FOO=foo");
println!("cargo:rustc-env=BAR=bar");
println!("cargo:foo=foo");
println!("cargo::metadata=bar=bar");
}"#,
)
.build();
p.cargo("build -v").run();
p.cargo("run -v").with_stdout("foo\nbar\n").run();
}

#[cargo_test]
fn test_invalid_new_syntaxes() {
// `cargo:` can not be used with `metadata` prefix.
let p = project()
.file("src/lib.rs", "")
.file(
"build.rs",
r#"
fn main() {
println!("cargo:metadata=rerun-if-changed=somedir");
}
"#,
)
.build();

p.cargo("build")
.with_status(101)
.with_stderr(
"\
[COMPILING] foo [..]
error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo:metadata=rerun-if-changed=somedir`
Expected a line with `cargo::KEY=VALUE`, but found `cargo:metadata=KEY=VALUE`.
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs.
",
)
.run();

// `metadata` can not be used with the reserved keys.
let p = project()
.file("src/lib.rs", "")
.file(
"build.rs",
r#"
fn main() {
println!("cargo::metadata=rerun-if-changed=somedir");
}
"#,
)
.build();

p.cargo("build")
.with_status(101)
.with_stderr(
"\
[COMPILING] foo [..]
error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo::metadata=rerun-if-changed=somedir`
The reserved key `rerun-if-changed` cannot be used in a `cargo::metadata` line. Please use `cargo::rerun-if-changed=VAlUE` instead.
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs.
",
)
.run();

// `cargo::` can not be used with the non-reserved keys.
let p = project()
.file("src/lib.rs", "")
.file(
"build.rs",
r#"
fn main() {
println!("cargo::foo=bar");
}
"#,
)
.build();

p.cargo("build")
.with_status(101)
.with_stderr(
"\
[COMPILING] foo [..]
error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo::foo=bar`
Expected a line with `cargo::metadata=KEY=VALUE` but it did not have the `metadata=` part.
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
for more information about build script outputs.
",
)
.run();
}

0 comments on commit 83ae1a8

Please sign in to comment.