|
1 | 1 | use gix_testtools::Result;
|
2 | 2 | use std::path::Path;
|
3 | 3 |
|
| 4 | +#[cfg(windows)] |
| 5 | +const SH: &str = "sh"; |
| 6 | +#[cfg(not(windows))] |
| 7 | +const SH: &str = "/bin/sh"; |
| 8 | + |
4 | 9 | #[test]
|
5 | 10 | fn extract_interpreter() -> gix_testtools::Result {
|
6 | 11 | let root = gix_testtools::scripted_fixture_read_only("win_path_lookup.sh")?;
|
@@ -222,10 +227,7 @@ mod context {
|
222 | 227 | }
|
223 | 228 |
|
224 | 229 | mod prepare {
|
225 |
| - #[cfg(windows)] |
226 |
| - const SH: &str = "sh"; |
227 |
| - #[cfg(not(windows))] |
228 |
| - const SH: &str = "/bin/sh"; |
| 230 | + use crate::SH; |
229 | 231 |
|
230 | 232 | fn quoted(input: &[&str]) -> String {
|
231 | 233 | input.iter().map(|s| format!("\"{s}\"")).collect::<Vec<_>>().join(" ")
|
@@ -512,6 +514,7 @@ mod spawn {
|
512 | 514 | }
|
513 | 515 |
|
514 | 516 | mod with_shell {
|
| 517 | + use crate::SH; |
515 | 518 | use gix_testtools::bstr::ByteSlice;
|
516 | 519 |
|
517 | 520 | #[test]
|
@@ -558,6 +561,31 @@ mod spawn {
|
558 | 561 | assert_eq!(out.stdout.as_bstr(), "arg");
|
559 | 562 | Ok(())
|
560 | 563 | }
|
| 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 | + } |
561 | 589 | }
|
562 | 590 |
|
563 | 591 | mod script {
|
|
0 commit comments