]>
Commit | Line | Data |
---|---|---|
2b541bf8 JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2009 Ilari Liusvaara | |
4 | # | |
5 | ||
6 | test_description='Test run command' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
c0f19bf3 JN |
10 | cat >hello-script <<-EOF |
11 | #!$SHELL_PATH | |
12 | cat hello-script | |
13 | EOF | |
c0f19bf3 | 14 | |
321fd823 | 15 | test_expect_success 'start_command reports ENOENT (slash)' ' |
e5a329a2 JH |
16 | test-tool run-command start-command-ENOENT ./does-not-exist 2>err && |
17 | test_i18ngrep "\./does-not-exist" err | |
2b541bf8 JS |
18 | ' |
19 | ||
321fd823 | 20 | test_expect_success 'start_command reports ENOENT (no slash)' ' |
e5a329a2 JH |
21 | test-tool run-command start-command-ENOENT does-not-exist 2>err && |
22 | test_i18ngrep "does-not-exist" err | |
321fd823 JK |
23 | ' |
24 | ||
c0f19bf3 JN |
25 | test_expect_success 'run_command can run a command' ' |
26 | cat hello-script >hello.sh && | |
27 | chmod +x hello.sh && | |
ae6a51f5 | 28 | test-tool run-command run-command ./hello.sh >actual 2>err && |
c0f19bf3 JN |
29 | |
30 | test_cmp hello-script actual && | |
1c5e94f4 | 31 | test_must_be_empty err |
c0f19bf3 JN |
32 | ' |
33 | ||
89ba9a79 JH |
34 | |
35 | test_lazy_prereq RUNS_COMMANDS_FROM_PWD ' | |
36 | write_script runs-commands-from-pwd <<-\EOF && | |
37 | true | |
38 | EOF | |
39 | runs-commands-from-pwd >/dev/null 2>&1 | |
40 | ' | |
41 | ||
42 | test_expect_success !RUNS_COMMANDS_FROM_PWD 'run_command is restricted to PATH' ' | |
321fd823 JK |
43 | write_script should-not-run <<-\EOF && |
44 | echo yikes | |
45 | EOF | |
e5a329a2 JH |
46 | test_must_fail test-tool run-command run-command should-not-run 2>err && |
47 | test_i18ngrep "should-not-run" err | |
321fd823 JK |
48 | ' |
49 | ||
c2d3119d BW |
50 | test_expect_success !MINGW 'run_command can run a script without a #! line' ' |
51 | cat >hello <<-\EOF && | |
52 | cat hello-script | |
53 | EOF | |
54 | chmod +x hello && | |
ae6a51f5 | 55 | test-tool run-command run-command ./hello >actual 2>err && |
c2d3119d BW |
56 | |
57 | test_cmp hello-script actual && | |
1c5e94f4 | 58 | test_must_be_empty err |
c2d3119d BW |
59 | ' |
60 | ||
94028310 BW |
61 | test_expect_success 'run_command does not try to execute a directory' ' |
62 | test_when_finished "rm -rf bin1 bin2" && | |
63 | mkdir -p bin1/greet bin2 && | |
64 | write_script bin2/greet <<-\EOF && | |
65 | cat bin2/greet | |
66 | EOF | |
67 | ||
68 | PATH=$PWD/bin1:$PWD/bin2:$PATH \ | |
ae6a51f5 | 69 | test-tool run-command run-command greet >actual 2>err && |
94028310 | 70 | test_cmp bin2/greet actual && |
1c5e94f4 | 71 | test_must_be_empty err |
94028310 BW |
72 | ' |
73 | ||
74 | test_expect_success POSIXPERM 'run_command passes over non-executable file' ' | |
75 | test_when_finished "rm -rf bin1 bin2" && | |
76 | mkdir -p bin1 bin2 && | |
77 | write_script bin1/greet <<-\EOF && | |
78 | cat bin1/greet | |
79 | EOF | |
80 | chmod -x bin1/greet && | |
81 | write_script bin2/greet <<-\EOF && | |
82 | cat bin2/greet | |
83 | EOF | |
84 | ||
85 | PATH=$PWD/bin1:$PWD/bin2:$PATH \ | |
ae6a51f5 | 86 | test-tool run-command run-command greet >actual 2>err && |
94028310 | 87 | test_cmp bin2/greet actual && |
1c5e94f4 | 88 | test_must_be_empty err |
94028310 BW |
89 | ' |
90 | ||
c0f19bf3 JN |
91 | test_expect_success POSIXPERM 'run_command reports EACCES' ' |
92 | cat hello-script >hello.sh && | |
93 | chmod -x hello.sh && | |
ae6a51f5 | 94 | test_must_fail test-tool run-command run-command ./hello.sh 2>err && |
c0f19bf3 JN |
95 | |
96 | grep "fatal: cannot exec.*hello.sh" err | |
97 | ' | |
98 | ||
eae69530 | 99 | test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' ' |
38f865c2 JK |
100 | mkdir local-command && |
101 | test_when_finished "chmod u+rwx local-command && rm -fr local-command" && | |
102 | git config alias.nitfol "!echo frotz" && | |
103 | chmod a-rx local-command && | |
104 | ( | |
105 | PATH=./local-command:$PATH && | |
106 | git nitfol >actual | |
107 | ) && | |
108 | echo frotz >expect && | |
109 | test_cmp expect actual | |
110 | ' | |
111 | ||
c553c72e SB |
112 | cat >expect <<-EOF |
113 | preloaded output of a child | |
114 | Hello | |
115 | World | |
116 | preloaded output of a child | |
117 | Hello | |
118 | World | |
119 | preloaded output of a child | |
120 | Hello | |
121 | World | |
122 | preloaded output of a child | |
123 | Hello | |
124 | World | |
125 | EOF | |
126 | ||
127 | test_expect_success 'run_command runs in parallel with more jobs available than tasks' ' | |
ae6a51f5 | 128 | test-tool run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
129 | test_cmp expect actual |
130 | ' | |
131 | ||
132 | test_expect_success 'run_command runs in parallel with as many jobs as tasks' ' | |
ae6a51f5 | 133 | test-tool run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
134 | test_cmp expect actual |
135 | ' | |
136 | ||
137 | test_expect_success 'run_command runs in parallel with more tasks than jobs available' ' | |
ae6a51f5 | 138 | test-tool run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
139 | test_cmp expect actual |
140 | ' | |
141 | ||
142 | cat >expect <<-EOF | |
143 | preloaded output of a child | |
144 | asking for a quick stop | |
145 | preloaded output of a child | |
146 | asking for a quick stop | |
147 | preloaded output of a child | |
148 | asking for a quick stop | |
149 | EOF | |
150 | ||
151 | test_expect_success 'run_command is asked to abort gracefully' ' | |
ae6a51f5 | 152 | test-tool run-command run-command-abort 3 false 2>actual && |
c553c72e SB |
153 | test_cmp expect actual |
154 | ' | |
155 | ||
156 | cat >expect <<-EOF | |
157 | no further jobs available | |
158 | EOF | |
159 | ||
160 | test_expect_success 'run_command outputs ' ' | |
ae6a51f5 | 161 | test-tool run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
162 | test_cmp expect actual |
163 | ' | |
164 | ||
c61a975d NTND |
165 | test_trace () { |
166 | expect="$1" | |
167 | shift | |
ae6a51f5 | 168 | GIT_TRACE=1 test-tool run-command "$@" run-command true 2>&1 >/dev/null | \ |
06718d4a JS |
169 | sed -e 's/.* run_command: //' -e '/trace: .*/d' \ |
170 | -e '/RUNTIME_PREFIX requested/d' >actual && | |
c61a975d NTND |
171 | echo "$expect true" >expect && |
172 | test_cmp expect actual | |
173 | } | |
174 | ||
175 | test_expect_success 'GIT_TRACE with environment variables' ' | |
176 | test_trace "abc=1 def=2" env abc=1 env def=2 && | |
177 | test_trace "abc=2" env abc env abc=1 env abc=2 && | |
178 | test_trace "abc=2" env abc env abc=2 && | |
179 | ( | |
180 | abc=1 && export abc && | |
181 | test_trace "def=1" env abc=1 env def=1 | |
182 | ) && | |
183 | ( | |
184 | abc=1 && export abc && | |
185 | test_trace "def=1" env abc env abc=1 env def=1 | |
186 | ) && | |
187 | test_trace "def=1" env non-exist env def=1 && | |
188 | test_trace "abc=2" env abc=1 env abc env abc=2 && | |
189 | ( | |
190 | abc=1 def=2 && export abc def && | |
191 | test_trace "unset abc def;" env abc env def | |
192 | ) && | |
193 | ( | |
194 | abc=1 def=2 && export abc def && | |
195 | test_trace "unset def; abc=3" env abc env def env abc=3 | |
196 | ) && | |
197 | ( | |
198 | abc=1 && export abc && | |
199 | test_trace "unset abc;" env abc=2 env abc | |
200 | ) | |
201 | ' | |
202 | ||
9e9da23c JS |
203 | test_expect_success MINGW 'verify curlies are quoted properly' ' |
204 | : force the rev-parse through the MSYS2 Bash && | |
205 | git -c alias.r="!git rev-parse" r -- a{b}c >actual && | |
206 | cat >expect <<-\EOF && | |
207 | -- | |
208 | a{b}c | |
209 | EOF | |
210 | test_cmp expect actual | |
211 | ' | |
212 | ||
71f4960b AM |
213 | test_expect_success MINGW 'can spawn .bat with argv[0] containing spaces' ' |
214 | bat="$TRASH_DIRECTORY/bat with spaces in name.bat" && | |
215 | ||
216 | # Every .bat invocation will log its arguments to file "out" | |
217 | rm -f out && | |
218 | echo "echo %* >>out" >"$bat" && | |
219 | ||
220 | # Ask git to invoke .bat; clone will fail due to fake SSH helper | |
221 | test_must_fail env GIT_SSH="$bat" git clone myhost:src ssh-clone && | |
222 | ||
223 | # Spawning .bat can fail if there are two quoted cmd.exe arguments. | |
224 | # .bat itself is first (due to spaces in name), so just one more is | |
225 | # needed to verify. GIT_SSH will invoke .bat multiple times: | |
226 | # 1) -G myhost | |
227 | # 2) myhost "git-upload-pack src" | |
228 | # First invocation will always succeed. Test the second one. | |
229 | grep "git-upload-pack" out | |
eb7c7863 JS |
230 | ' |
231 | ||
2b541bf8 | 232 | test_done |