3 # Copyright (c) 2009 Ilari Liusvaara
6 test_description='Test run command'
10 cat >hello-script <<-EOF
15 test_expect_success MINGW 'subprocess inherits only std handles' '
16 test-tool run-command inherited-handle
19 test_expect_success 'start_command reports ENOENT (slash)' '
20 test-tool run-command start-command-ENOENT ./does-not-exist 2>err &&
21 test_i18ngrep "\./does-not-exist" err
24 test_expect_success 'start_command reports ENOENT (no slash)' '
25 test-tool run-command start-command-ENOENT does-not-exist 2>err &&
26 test_i18ngrep "does-not-exist" err
29 test_expect_success 'run_command can run a command' '
30 cat hello-script >hello.sh &&
32 test-tool run-command run-command ./hello.sh >actual 2>err &&
34 test_cmp hello-script actual &&
35 test_must_be_empty err
39 test_lazy_prereq RUNS_COMMANDS_FROM_PWD '
40 write_script runs-commands-from-pwd <<-\EOF &&
43 runs-commands-from-pwd >/dev/null 2>&1
46 test_expect_success !RUNS_COMMANDS_FROM_PWD 'run_command is restricted to PATH' '
47 write_script should-not-run <<-\EOF &&
50 test_must_fail test-tool run-command run-command should-not-run 2>err &&
51 test_i18ngrep "should-not-run" err
54 test_expect_success !MINGW 'run_command can run a script without a #! line' '
59 test-tool run-command run-command ./hello >actual 2>err &&
61 test_cmp hello-script actual &&
62 test_must_be_empty err
65 test_expect_success 'run_command does not try to execute a directory' '
66 test_when_finished "rm -rf bin1 bin2" &&
67 mkdir -p bin1/greet bin2 &&
68 write_script bin2/greet <<-\EOF &&
72 PATH=$PWD/bin1:$PWD/bin2:$PATH \
73 test-tool run-command run-command greet >actual 2>err &&
74 test_cmp bin2/greet actual &&
75 test_must_be_empty err
78 test_expect_success POSIXPERM 'run_command passes over non-executable file' '
79 test_when_finished "rm -rf bin1 bin2" &&
81 write_script bin1/greet <<-\EOF &&
84 chmod -x bin1/greet &&
85 write_script bin2/greet <<-\EOF &&
89 PATH=$PWD/bin1:$PWD/bin2:$PATH \
90 test-tool run-command run-command greet >actual 2>err &&
91 test_cmp bin2/greet actual &&
92 test_must_be_empty err
95 test_expect_success POSIXPERM 'run_command reports EACCES' '
96 cat hello-script >hello.sh &&
98 test_must_fail test-tool run-command run-command ./hello.sh 2>err &&
100 grep "fatal: cannot exec.*hello.sh" err
103 test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' '
104 mkdir local-command &&
105 test_when_finished "chmod u+rwx local-command && rm -fr local-command" &&
106 git config alias.nitfol "!echo frotz" &&
107 chmod a-rx local-command &&
109 PATH=./local-command:$PATH &&
112 echo frotz >expect &&
113 test_cmp expect actual
117 preloaded output of a child
120 preloaded output of a child
123 preloaded output of a child
126 preloaded output of a child
131 test_expect_success 'run_command runs in parallel with more jobs available than tasks' '
132 test-tool run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
133 test_cmp expect actual
136 test_expect_success 'run_command runs in parallel with as many jobs as tasks' '
137 test-tool run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
138 test_cmp expect actual
141 test_expect_success 'run_command runs in parallel with more tasks than jobs available' '
142 test-tool run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
143 test_cmp expect actual
146 test_expect_success 'run_command can divert output' '
147 test_when_finished rm sideband &&
148 test-tool run-command run-command-sideband 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
149 test_must_be_empty actual &&
150 test_cmp expect sideband
154 preloaded output of a child
158 preloaded output of a child
162 preloaded output of a child
166 preloaded output of a child
172 test_expect_success 'run_command listens to stdin' '
173 write_script stdin-script <<-\EOF &&
174 echo "listening for stdin:"
179 test-tool run-command run-command-stdin 2 ./stdin-script 2>actual &&
180 test_cmp expect actual
184 preloaded output of a child
185 asking for a quick stop
186 preloaded output of a child
187 asking for a quick stop
188 preloaded output of a child
189 asking for a quick stop
192 test_expect_success 'run_command is asked to abort gracefully' '
193 test-tool run-command run-command-abort 3 false 2>actual &&
194 test_cmp expect actual
198 no further jobs available
201 test_expect_success 'run_command outputs ' '
202 test-tool run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
203 test_cmp expect actual
209 GIT_TRACE=1 test-tool run-command "$@" run-command true 2>&1 >/dev/null | \
210 sed -e 's/.* run_command: //' -e '/trace: .*/d' \
211 -e '/RUNTIME_PREFIX requested/d' >actual &&
212 echo "$expect true" >expect &&
213 test_cmp expect actual
216 test_expect_success 'GIT_TRACE with environment variables' '
217 test_trace "abc=1 def=2" env abc=1 env def=2 &&
218 test_trace "abc=2" env abc env abc=1 env abc=2 &&
219 test_trace "abc=2" env abc env abc=2 &&
221 abc=1 && export abc &&
222 test_trace "def=1" env abc=1 env def=1
225 abc=1 && export abc &&
226 test_trace "def=1" env abc env abc=1 env def=1
228 test_trace "def=1" env non-exist env def=1 &&
229 test_trace "abc=2" env abc=1 env abc env abc=2 &&
231 abc=1 def=2 && export abc def &&
232 test_trace "unset abc def;" env abc env def
235 abc=1 def=2 && export abc def &&
236 test_trace "unset def; abc=3" env abc env def env abc=3
239 abc=1 && export abc &&
240 test_trace "unset abc;" env abc=2 env abc
244 test_expect_success MINGW 'verify curlies are quoted properly' '
245 : force the rev-parse through the MSYS2 Bash &&
246 git -c alias.r="!git rev-parse" r -- a{b}c >actual &&
247 cat >expect <<-\EOF &&
251 test_cmp expect actual
254 test_expect_success MINGW 'can spawn .bat with argv[0] containing spaces' '
255 bat="$TRASH_DIRECTORY/bat with spaces in name.bat" &&
257 # Every .bat invocation will log its arguments to file "out"
259 echo "echo %* >>out" >"$bat" &&
261 # Ask git to invoke .bat; clone will fail due to fake SSH helper
262 test_must_fail env GIT_SSH="$bat" git clone myhost:src ssh-clone &&
264 # Spawning .bat can fail if there are two quoted cmd.exe arguments.
265 # .bat itself is first (due to spaces in name), so just one more is
266 # needed to verify. GIT_SSH will invoke .bat multiple times:
268 # 2) myhost "git-upload-pack src"
269 # First invocation will always succeed. Test the second one.
270 grep "git-upload-pack" out