Skip to content

Commit c0d23d2

Browse files
committed
Add test for multiple OUT_DIR
1 parent a6c58d4 commit c0d23d2

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/testsuite/build_scripts_multiple.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,79 @@ fn bar() {
764764
"#]])
765765
.run();
766766
}
767+
768+
#[cargo_test]
769+
fn multiple_out_dirs() {
770+
// In this, we try to access the OUT_DIR of multiple build scripts.
771+
772+
let p = project()
773+
.file(
774+
"Cargo.toml",
775+
r#"
776+
cargo-features = ["multiple-build-scripts"]
777+
778+
[package]
779+
name = "foo"
780+
version = "0.1.0"
781+
edition = "2024"
782+
build = ["build1.rs", "build2.rs"]
783+
"#,
784+
)
785+
.file(
786+
"src/main.rs",
787+
r#"
788+
include!(concat!(env!("OUT_DIR"), "/foo.rs"));
789+
fn main() {
790+
println!("{}", message());
791+
}
792+
"#,
793+
)
794+
.file(
795+
"build1.rs",
796+
r#"
797+
use std::env;
798+
use std::fs;
799+
use std::path::Path;
800+
801+
fn main() {
802+
let out_dir = env::var_os("OUT_DIR").unwrap();
803+
let dest_path = Path::new(&out_dir).join("foo.rs");
804+
fs::write(
805+
&dest_path,
806+
"pub fn message() -> &'static str {
807+
\"Hello, from Build Script 1!\"
808+
}
809+
"
810+
).unwrap();
811+
}"#,
812+
)
813+
.file(
814+
"build2.rs",
815+
r#"
816+
use std::env;
817+
use std::fs;
818+
use std::path::Path;
819+
820+
fn main() {
821+
let out_dir = env::var_os("OUT_DIR").unwrap();
822+
let dest_path = Path::new(&out_dir).join("foo.rs");
823+
fs::write(
824+
&dest_path,
825+
"pub fn message() -> &'static str {
826+
\"Hello, from Build Script 2!\"
827+
}
828+
"
829+
).unwrap();
830+
}"#,
831+
)
832+
.build();
833+
834+
p.cargo("run -v")
835+
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
836+
.with_status(0)
837+
.with_stdout_data(str![[r#"
838+
Hello, from Build Script 2!
839+
840+
"#]])
841+
.run();
842+
}

0 commit comments

Comments
 (0)