3 # Copyright (c) 2009 Ilari Liusvaara
6 test_description='Test run command'
10 cat >hello-script <<-EOF
15 test_expect_success 'start_command reports ENOENT (slash)' '
16 test-tool run-command start-command-ENOENT ./does-not-exist 2>err &&
17 test_i18ngrep "\./does-not-exist" err
20 test_expect_success 'start_command reports ENOENT (no slash)' '
21 test-tool run-command start-command-ENOENT does-not-exist 2>err &&
22 test_i18ngrep "does-not-exist" err
25 test_expect_success 'run_command can run a command' '
26 cat hello-script >hello.sh &&
28 test-tool run-command run-command ./hello.sh >actual 2>err &&
30 test_cmp hello-script actual &&
31 test_must_be_empty err
35 test_lazy_prereq RUNS_COMMANDS_FROM_PWD '
36 write_script runs-commands-from-pwd <<-\EOF &&
39 runs-commands-from-pwd >/dev/null 2>&1
42 test_expect_success !RUNS_COMMANDS_FROM_PWD 'run_command is restricted to PATH' '
43 write_script should-not-run <<-\EOF &&
46 test_must_fail test-tool run-command run-command should-not-run 2>err &&
47 test_i18ngrep "should-not-run" err
50 test_expect_success !MINGW 'run_command can run a script without a #! line' '
55 test-tool run-command run-command ./hello >actual 2>err &&
57 test_cmp hello-script actual &&
58 test_must_be_empty err
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 &&
68 PATH=$PWD/bin1:$PWD/bin2:$PATH \
69 test-tool run-command run-command greet >actual 2>err &&
70 test_cmp bin2/greet actual &&
71 test_must_be_empty err
74 test_expect_success POSIXPERM 'run_command passes over non-executable file' '
75 test_when_finished "rm -rf bin1 bin2" &&
77 write_script bin1/greet <<-\EOF &&
80 chmod -x bin1/greet &&
81 write_script bin2/greet <<-\EOF &&
85 PATH=$PWD/bin1:$PWD/bin2:$PATH \
86 test-tool run-command run-command greet >actual 2>err &&
87 test_cmp bin2/greet actual &&
88 test_must_be_empty err
91 test_expect_success POSIXPERM 'run_command reports EACCES' '
92 cat hello-script >hello.sh &&
94 test_must_fail test-tool run-command run-command ./hello.sh 2>err &&
96 grep "fatal: cannot exec.*hello.sh" err
99 test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' '
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 &&
105 PATH=./local-command:$PATH &&
108 echo frotz >expect &&
109 test_cmp expect actual
113 preloaded output of a child
116 preloaded output of a child
119 preloaded output of a child
122 preloaded output of a child
127 test_expect_success 'run_command runs in parallel with more jobs available than tasks' '
128 test-tool run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
129 test_cmp expect actual
132 test_expect_success 'run_command runs in parallel with as many jobs as tasks' '
133 test-tool run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
134 test_cmp expect actual
137 test_expect_success 'run_command runs in parallel with more tasks than jobs available' '
138 test-tool run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
139 test_cmp expect actual
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
151 test_expect_success 'run_command is asked to abort gracefully' '
152 test-tool run-command run-command-abort 3 false 2>actual &&
153 test_cmp expect actual
157 no further jobs available
160 test_expect_success 'run_command outputs ' '
161 test-tool run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
162 test_cmp expect actual
168 GIT_TRACE=1 test-tool run-command "$@" run-command true 2>&1 >/dev/null | \
169 sed -e 's/.* run_command: //' -e '/trace: .*/d' \
170 -e '/RUNTIME_PREFIX requested/d' >actual &&
171 echo "$expect true" >expect &&
172 test_cmp expect actual
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 &&
180 abc=1 && export abc &&
181 test_trace "def=1" env abc=1 env def=1
184 abc=1 && export abc &&
185 test_trace "def=1" env abc env abc=1 env def=1
187 test_trace "def=1" env non-exist env def=1 &&
188 test_trace "abc=2" env abc=1 env abc env abc=2 &&
190 abc=1 def=2 && export abc def &&
191 test_trace "unset abc def;" env abc env def
194 abc=1 def=2 && export abc def &&
195 test_trace "unset def; abc=3" env abc env def env abc=3
198 abc=1 && export abc &&
199 test_trace "unset abc;" env abc=2 env abc
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 &&
210 test_cmp expect actual
213 test_expect_success MINGW 'can spawn .bat with argv[0] containing spaces' '
214 bat="$TRASH_DIRECTORY/bat with spaces in name.bat" &&
216 # Every .bat invocation will log its arguments to file "out"
218 echo "echo %* >>out" >"$bat" &&
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 &&
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:
227 # 2) myhost "git-upload-pack src"
228 # First invocation will always succeed. Test the second one.
229 grep "git-upload-pack" out