1
1
use gix_credentials:: { helper, program:: Kind , Program } ;
2
+ use once_cell:: sync:: Lazy ;
2
3
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
+ } ) ;
5
9
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
+ } ) ;
10
15
11
16
#[ test]
12
17
fn empty ( ) {
@@ -47,11 +52,12 @@ fn name_with_args() {
47
52
fn name_with_special_args ( ) {
48
53
let input = "name --arg --bar=~/folder/in/home" ;
49
54
let prog = Program :: from_custom_definition ( input) ;
55
+ let sh = * SH ;
50
56
let git = * GIT ;
51
57
assert ! ( matches!( & prog. kind, Kind :: ExternalName { name_and_args} if name_and_args == input) ) ;
52
58
assert_eq ! (
53
59
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""# )
55
61
) ;
56
62
}
57
63
@@ -73,12 +79,13 @@ fn path_with_args_that_definitely_need_shell() {
73
79
let input = "/abs/name --arg --bar=\" a b\" " ;
74
80
let prog = Program :: from_custom_definition ( input) ;
75
81
assert ! ( matches!( & prog. kind, Kind :: ExternalPath { path_and_args} if path_and_args == input) ) ;
82
+ let sh = * SH ;
76
83
assert_eq ! (
77
84
format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
78
85
if cfg!( windows) {
79
86
r#""/abs/name" "--arg" "--bar=a b" "store""# . to_owned( )
80
87
} 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""# )
82
89
}
83
90
) ;
84
91
}
@@ -100,12 +107,13 @@ fn path_with_simple_args() {
100
107
let input = "/abs/name a b" ;
101
108
let prog = Program :: from_custom_definition ( input) ;
102
109
assert ! ( matches!( & prog. kind, Kind :: ExternalPath { path_and_args} if path_and_args == input) ) ;
110
+ let sh = * SH ;
103
111
assert_eq ! (
104
112
format!( "{:?}" , prog. to_command( & helper:: Action :: Store ( "egal" . into( ) ) ) ) ,
105
113
if cfg!( windows) {
106
114
r#""/abs/name" "a" "b" "store""# . to_owned( )
107
115
} else {
108
- format!( r#""{SH }" "-c" "/abs/name a b \"$@\"" "--" "store""# )
116
+ format!( r#""{sh }" "-c" "/abs/name a b \"$@\"" "--" "store""# )
109
117
} ,
110
118
"a shell is used as there are arguments, and it's generally more flexible, but on windows we split ourselves"
111
119
) ;
0 commit comments