11use gix_credentials:: { helper, program:: Kind , Program } ;
2+ use once_cell:: sync:: Lazy ;
23
3- static GIT : once_cell:: sync:: Lazy < & ' static str > =
4- once_cell:: sync:: Lazy :: new ( || gix_path:: env:: exe_invocation ( ) . to_str ( ) . expect ( "not illformed" ) ) ;
4+ static GIT : once_cell:: sync:: Lazy < & ' static str > = once_cell:: sync:: Lazy :: new ( || {
5+ gix_path:: env:: exe_invocation ( )
6+ . to_str ( )
7+ . expect ( "some `from_custom_definition` tests must be run where 'git' path is valid Unicode" )
8+ } ) ;
59
6- #[ cfg( windows) ]
7- const SH : & str = "sh" ;
8- #[ cfg( not( windows) ) ]
9- const SH : & str = "/bin/sh" ;
10+ static SH : Lazy < & ' static str > = Lazy :: new ( || {
11+ gix_path:: env:: shell ( )
12+ . to_str ( )
13+ . expect ( "some `from_custom_definition` tests must be run where 'sh' path is valid Unicode" )
14+ } ) ;
1015
1116#[ test]
1217fn empty ( ) {
@@ -47,11 +52,12 @@ fn name_with_args() {
4752fn name_with_special_args ( ) {
4853 let input = "name --arg --bar=~/folder/in/home" ;
4954 let prog = Program :: from_custom_definition ( input) ;
55+ let sh = * SH ;
5056 let git = * GIT ;
5157 assert ! ( matches!( & prog. kind, Kind :: ExternalName { name_and_args} if name_and_args == input) ) ;
5258 assert_eq ! (
5359 format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
54- format!( r#""{SH }" "-c" "{git} credential-name --arg --bar=~/folder/in/home \"$@\"" "--" "store""# )
60+ format!( r#""{sh }" "-c" "{git} credential-name --arg --bar=~/folder/in/home \"$@\"" "--" "store""# )
5561 ) ;
5662}
5763
@@ -73,12 +79,13 @@ fn path_with_args_that_definitely_need_shell() {
7379 let input = "/abs/name --arg --bar=\" a b\" " ;
7480 let prog = Program :: from_custom_definition ( input) ;
7581 assert ! ( matches!( & prog. kind, Kind :: ExternalPath { path_and_args} if path_and_args == input) ) ;
82+ let sh = * SH ;
7683 assert_eq ! (
7784 format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
7885 if cfg!( windows) {
7986 r#""/abs/name" "--arg" "--bar=a b" "store""# . to_owned( )
8087 } else {
81- format!( r#""{SH }" "-c" "/abs/name --arg --bar=\"a b\" \"$@\"" "--" "store""# )
88+ format!( r#""{sh }" "-c" "/abs/name --arg --bar=\"a b\" \"$@\"" "--" "store""# )
8289 }
8390 ) ;
8491}
@@ -100,12 +107,13 @@ fn path_with_simple_args() {
100107 let input = "/abs/name a b" ;
101108 let prog = Program :: from_custom_definition ( input) ;
102109 assert ! ( matches!( & prog. kind, Kind :: ExternalPath { path_and_args} if path_and_args == input) ) ;
110+ let sh = * SH ;
103111 assert_eq ! (
104112 format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
105113 if cfg!( windows) {
106114 r#""/abs/name" "a" "b" "store""# . to_owned( )
107115 } else {
108- format!( r#""{SH }" "-c" "/abs/name a b \"$@\"" "--" "store""# )
116+ format!( r#""{sh }" "-c" "/abs/name a b \"$@\"" "--" "store""# )
109117 } ,
110118 "a shell is used as there are arguments, and it's generally more flexible, but on windows we split ourselves"
111119 ) ;
0 commit comments