Skip to content

Commit 5597407

Browse files
committed
Add tests for msrv check
Signed-off-by: hi-rustin <[email protected]>
1 parent 5906455 commit 5597407

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/testsuite/build_script.rs

+74
Original file line numberDiff line numberDiff line change
@@ -5318,3 +5318,77 @@ for more information about build script outputs.
53185318
)
53195319
.run();
53205320
}
5321+
5322+
#[cargo_test]
5323+
fn test_new_syntax_with_old_msrv() {
5324+
let p = project()
5325+
.file(
5326+
"Cargo.toml",
5327+
r#"
5328+
[package]
5329+
name = "foo"
5330+
version = "0.5.0"
5331+
authors = []
5332+
build = "build.rs"
5333+
rust-version = "1.60.0"
5334+
"#,
5335+
)
5336+
.file("src/lib.rs", "")
5337+
.file(
5338+
"build.rs",
5339+
r#"
5340+
fn main() {
5341+
println!("cargo::metadata=foo=bar");
5342+
}
5343+
"#,
5344+
)
5345+
.build();
5346+
5347+
p.cargo("build")
5348+
.with_status(101)
5349+
.with_stderr_contains(
5350+
"\
5351+
[COMPILING] foo [..]
5352+
error: the `cargo::` syntax for build script output instructions was added in Rust 1.77.0, \
5353+
but the minimum supported Rust version of `foo v0.5.0 ([ROOT]/foo)` is 1.60.0.
5354+
See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
5355+
for more information about build script outputs.
5356+
",
5357+
)
5358+
.run();
5359+
}
5360+
5361+
#[cargo_test]
5362+
fn test_old_syntax_with_old_msrv() {
5363+
let p = project()
5364+
.file(
5365+
"Cargo.toml",
5366+
r#"
5367+
[package]
5368+
name = "foo"
5369+
version = "0.0.1"
5370+
authors = []
5371+
build = "build.rs"
5372+
rust-version = "1.60.0"
5373+
"#,
5374+
)
5375+
.file(
5376+
"src/main.rs",
5377+
r#"
5378+
const FOO: &'static str = env!("FOO");
5379+
fn main() {
5380+
println!("{}", FOO);
5381+
}
5382+
"#,
5383+
)
5384+
.file(
5385+
"build.rs",
5386+
r#"fn main() {
5387+
println!("cargo:rustc-env=FOO=foo");
5388+
println!("cargo:foo=foo");
5389+
}"#,
5390+
)
5391+
.build();
5392+
p.cargo("build -v").run();
5393+
p.cargo("run -v").with_stdout("foo\n").run();
5394+
}

0 commit comments

Comments
 (0)