Skip to content

Commit 8c0b609

Browse files
committed
WIP
1 parent 387da88 commit 8c0b609

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

gix-command/tests/command.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use gix_testtools::Result;
22
use std::path::Path;
33

4+
#[cfg(windows)]
5+
const SH: &str = "sh";
6+
#[cfg(not(windows))]
7+
const SH: &str = "/bin/sh";
8+
49
#[test]
510
fn extract_interpreter() -> gix_testtools::Result {
611
let root = gix_testtools::scripted_fixture_read_only("win_path_lookup.sh")?;
@@ -222,10 +227,7 @@ mod context {
222227
}
223228

224229
mod prepare {
225-
#[cfg(windows)]
226-
const SH: &str = "sh";
227-
#[cfg(not(windows))]
228-
const SH: &str = "/bin/sh";
230+
use crate::SH;
229231

230232
fn quoted(input: &[&str]) -> String {
231233
input.iter().map(|s| format!("\"{s}\"")).collect::<Vec<_>>().join(" ")
@@ -512,6 +514,7 @@ mod spawn {
512514
}
513515

514516
mod with_shell {
517+
use crate::SH;
515518
use gix_testtools::bstr::ByteSlice;
516519

517520
#[test]
@@ -558,6 +561,31 @@ mod spawn {
558561
assert_eq!(out.stdout.as_bstr(), "arg");
559562
Ok(())
560563
}
564+
565+
#[test]
566+
fn command_name() -> crate::Result {
567+
let prep = gix_command::prepare(r#"printf '%s' "$0""#)
568+
.command_may_be_shell_script_disallow_manual_argument_splitting();
569+
assert!(prep.use_shell);
570+
assert!(!prep.allow_manual_arg_splitting);
571+
let out = prep.spawn()?.wait_with_output()?;
572+
assert!(out.status.success());
573+
assert_eq!(out.stdout.as_bstr(), SH);
574+
Ok(())
575+
}
576+
577+
#[test]
578+
fn command_name_with_args() -> crate::Result {
579+
let prep = gix_command::prepare(r#"printf '%s\n' "$0""#) // Rely on ` "$@"` being appended.
580+
.command_may_be_shell_script_disallow_manual_argument_splitting()
581+
.args(["foo", "bar baz", "quux"]);
582+
assert!(prep.use_shell);
583+
assert!(!prep.allow_manual_arg_splitting);
584+
let out = prep.spawn()?.wait_with_output()?;
585+
assert!(out.status.success());
586+
assert_eq!(out.stdout.as_bstr(), format!("{SH}\nfoo\nbar baz\nquux\n"));
587+
Ok(())
588+
}
561589
}
562590

563591
mod script {

0 commit comments

Comments
 (0)