mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Add tests for multiple build scripts execution
This commit is contained in:
parent
8f80388a78
commit
e9df793c47
@ -409,6 +409,205 @@ path = "src/main.rs"
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn custom_build_script_first_index_script_failed() {
|
||||||
|
// In this, the script that is at first index in the build script array fails
|
||||||
|
let p = project()
|
||||||
|
.file(
|
||||||
|
"Cargo.toml",
|
||||||
|
r#"
|
||||||
|
cargo-features = ["multiple-build-scripts"]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
build = ["build1.rs", "build2.rs"]
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file("src/main.rs", "fn main() {}")
|
||||||
|
.file("build1.rs", "fn main() { std::process::exit(101); }")
|
||||||
|
.file("build2.rs", "fn main() {}")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
p.cargo("check -v")
|
||||||
|
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
||||||
|
.with_status(101)
|
||||||
|
.with_stderr_data(str![[r#"
|
||||||
|
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
||||||
|
[RUNNING] `rustc --crate-name build_script_build1 --edition=2024 build1.rs [..]--crate-type bin [..]`
|
||||||
|
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build1`
|
||||||
|
[ERROR] failed to run custom build command for `foo v0.1.0 ([ROOT]/foo)`
|
||||||
|
|
||||||
|
Caused by:
|
||||||
|
process didn't exit successfully: `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build1` ([EXIT_STATUS]: 101)
|
||||||
|
|
||||||
|
"#]])
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn custom_build_script_second_index_script_failed() {
|
||||||
|
// In this, the script that is at second index in the build script array fails
|
||||||
|
// This test was necessary because earlier, the program failed only if first script failed.
|
||||||
|
let p = project()
|
||||||
|
.file(
|
||||||
|
"Cargo.toml",
|
||||||
|
r#"
|
||||||
|
cargo-features = ["multiple-build-scripts"]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
build = ["build1.rs", "build2.rs"]
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file("src/main.rs", "fn main() {}")
|
||||||
|
.file("build1.rs", "fn main() {}")
|
||||||
|
.file("build2.rs", "fn main() { std::process::exit(101); }")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
p.cargo("check -v")
|
||||||
|
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
||||||
|
.with_status(0)
|
||||||
|
.with_stderr_data(str![[r#"
|
||||||
|
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
||||||
|
[RUNNING] `rustc --crate-name build_script_build1 --edition=2024 build1.rs [..]--crate-type bin [..]`
|
||||||
|
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build1`
|
||||||
|
[RUNNING] `rustc --crate-name foo --edition=2024 src/main.rs [..] --crate-type bin [..]`
|
||||||
|
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||||
|
|
||||||
|
"#]])
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn build_script_with_conflicting_environment_variables() {
|
||||||
|
// In this, multiple scripts set different values to same environment variables
|
||||||
|
let p = project()
|
||||||
|
.file(
|
||||||
|
"Cargo.toml",
|
||||||
|
r#"
|
||||||
|
cargo-features = ["multiple-build-scripts"]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
build = ["build1.rs", "build2.rs"]
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"src/main.rs",
|
||||||
|
r#"
|
||||||
|
const FOO: &'static str = env!("FOO");
|
||||||
|
fn main() {
|
||||||
|
println!("{}", FOO);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"build1.rs",
|
||||||
|
r#"fn main() { println!("cargo::rustc-env=FOO=bar1"); }"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"build2.rs",
|
||||||
|
r#"fn main() { println!("cargo::rustc-env=FOO=bar2"); }"#,
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
p.cargo("run -v")
|
||||||
|
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
||||||
|
.with_status(0)
|
||||||
|
.with_stdout_data(str![[r#"
|
||||||
|
bar1
|
||||||
|
|
||||||
|
"#]])
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn build_script_with_conflicting_out_dirs() {
|
||||||
|
// In this, multiple scripts create file with same name in their respective OUT_DIR.
|
||||||
|
|
||||||
|
let p = project()
|
||||||
|
.file(
|
||||||
|
"Cargo.toml",
|
||||||
|
r#"
|
||||||
|
cargo-features = ["multiple-build-scripts"]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
build = ["build1.rs", "build2.rs"]
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
// OUT_DIR is set to the lexicographically largest build script's OUT_DIR by default
|
||||||
|
.file(
|
||||||
|
"src/main.rs",
|
||||||
|
r#"
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/foo.rs"));
|
||||||
|
fn main() {
|
||||||
|
println!("{}", message());
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"build1.rs",
|
||||||
|
r#"
|
||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||||
|
let dest_path = Path::new(&out_dir).join("foo.rs");
|
||||||
|
fs::write(
|
||||||
|
&dest_path,
|
||||||
|
"pub fn message() -> &'static str {
|
||||||
|
\"Hello, from Build Script 1!\"
|
||||||
|
}
|
||||||
|
"
|
||||||
|
).unwrap();
|
||||||
|
}"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"build2.rs",
|
||||||
|
r#"
|
||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||||
|
let dest_path = Path::new(&out_dir).join("foo.rs");
|
||||||
|
fs::write(
|
||||||
|
&dest_path,
|
||||||
|
"pub fn message() -> &'static str {
|
||||||
|
\"Hello, from Build Script 2!\"
|
||||||
|
}
|
||||||
|
"
|
||||||
|
).unwrap();
|
||||||
|
}"#,
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
p.cargo("run -v")
|
||||||
|
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
||||||
|
.with_status(0)
|
||||||
|
.with_stdout_data(str![[r#"
|
||||||
|
Hello, from Build Script 1!
|
||||||
|
|
||||||
|
"#]])
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn rerun_untracks_other_files() {
|
fn rerun_untracks_other_files() {
|
||||||
let p = project()
|
let p = project()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user