Skip to content

Commit 79c8c64

Browse files
committed
test(script): Script names that conflict with artifacts
1 parent 2394ea6 commit 79c8c64

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/testsuite/script/cargo.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,73 @@ args: []
673673
.run();
674674
}
675675

676+
#[cargo_test(nightly, reason = "-Zscript is unstable")]
677+
fn test_name_is_deps_dir_implicit() {
678+
let script = ECHO_SCRIPT;
679+
let p = cargo_test_support::project()
680+
.file("deps.rs", script)
681+
.build();
682+
683+
p.cargo("-Zscript -v deps.rs")
684+
.masquerade_as_nightly_cargo(&["script"])
685+
.with_stdout_data(str![[r#"
686+
current_exe: [ROOT]/home/.cargo/target/[HASH]/debug/deps-[EXE]
687+
arg0: [..]
688+
args: []
689+
690+
"#]])
691+
.with_stderr_data(str![[r#"
692+
[WARNING] `package.edition` is unspecified, defaulting to `2024`
693+
[COMPILING] deps- v0.0.0 ([ROOT]/foo/deps.rs)
694+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
695+
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/deps-[EXE]`
696+
697+
"#]])
698+
.run();
699+
}
700+
701+
#[cargo_test(nightly, reason = "-Zscript is unstable")]
702+
fn test_name_is_deps_dir_explicit() {
703+
let script = r#"#!/usr/bin/env cargo
704+
---
705+
package.name = "deps"
706+
---
707+
708+
fn main() {
709+
let current_exe = std::env::current_exe().unwrap().to_str().unwrap().to_owned();
710+
let mut args = std::env::args_os();
711+
let arg0 = args.next().unwrap().to_str().unwrap().to_owned();
712+
let args = args.collect::<Vec<_>>();
713+
println!("current_exe: {current_exe}");
714+
println!("arg0: {arg0}");
715+
println!("args: {args:?}");
716+
}
717+
718+
#[test]
719+
fn test () {}
720+
"#;
721+
let p = cargo_test_support::project()
722+
.file("deps.rs", script)
723+
.build();
724+
725+
p.cargo("-Zscript -v deps.rs")
726+
.masquerade_as_nightly_cargo(&["script"])
727+
.with_stdout_data(str![[r#"
728+
current_exe: [ROOT]/home/.cargo/target/[HASH]/debug/deps-[EXE]
729+
arg0: [..]
730+
args: []
731+
732+
"#]])
733+
.with_stderr_data(str![[r#"
734+
[WARNING] `package.edition` is unspecified, defaulting to `2024`
735+
[COMPILING] deps v0.0.0 ([ROOT]/foo/deps.rs)
736+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
737+
[RUNNING] `[ROOT]/home/.cargo/target/[HASH]/debug/deps-[EXE]`
738+
739+
"#]])
740+
.run();
741+
}
742+
676743
#[cargo_test(nightly, reason = "-Zscript is unstable")]
677744
fn script_like_dir() {
678745
let p = cargo_test_support::project()

0 commit comments

Comments
 (0)