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
34 test_expect_success
'run_command is restricted to PATH' '
35 write_script should-not-run <<-\EOF &&
38 test_must_fail test-tool run-command run-command should-not-run 2>err &&
39 test_i18ngrep "should-not-run" err
42 test_expect_success
!MINGW
'run_command can run a script without a #! line' '
47 test-tool run-command run-command ./hello >actual 2>err &&
49 test_cmp hello-script actual &&
50 test_must_be_empty err
53 test_expect_success
'run_command does not try to execute a directory' '
54 test_when_finished "rm -rf bin1 bin2" &&
55 mkdir -p bin1/greet bin2 &&
56 write_script bin2/greet <<-\EOF &&
60 PATH=$PWD/bin1:$PWD/bin2:$PATH \
61 test-tool run-command run-command greet >actual 2>err &&
62 test_cmp bin2/greet actual &&
63 test_must_be_empty err
66 test_expect_success POSIXPERM
'run_command passes over non-executable file' '
67 test_when_finished "rm -rf bin1 bin2" &&
69 write_script bin1/greet <<-\EOF &&
72 chmod -x bin1/greet &&
73 write_script bin2/greet <<-\EOF &&
77 PATH=$PWD/bin1:$PWD/bin2:$PATH \
78 test-tool run-command run-command greet >actual 2>err &&
79 test_cmp bin2/greet actual &&
80 test_must_be_empty err
83 test_expect_success POSIXPERM
'run_command reports EACCES' '
84 cat hello-script >hello.sh &&
86 test_must_fail test-tool run-command run-command ./hello.sh 2>err &&
88 grep "fatal: cannot exec.*hello.sh" err
91 test_expect_success POSIXPERM
,SANITY
'unreadable directory in PATH' '
92 mkdir local-command &&
93 test_when_finished "chmod u+rwx local-command && rm -fr local-command" &&
94 git config alias.nitfol "!echo frotz" &&
95 chmod a-rx local-command &&
97 PATH=./local-command:$PATH &&
100 echo frotz >expect &&
101 test_cmp expect actual
105 preloaded output of a child
108 preloaded output of a child
111 preloaded output of a child
114 preloaded output of a child
119 test_expect_success
'run_command runs in parallel with more jobs available than tasks' '
120 test-tool run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
121 test_cmp expect actual
124 test_expect_success
'run_command runs in parallel with as many jobs as tasks' '
125 test-tool run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
126 test_cmp expect actual
129 test_expect_success
'run_command runs in parallel with more tasks than jobs available' '
130 test-tool run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
131 test_cmp expect actual
135 preloaded output of a child
136 asking for a quick stop
137 preloaded output of a child
138 asking for a quick stop
139 preloaded output of a child
140 asking for a quick stop
143 test_expect_success
'run_command is asked to abort gracefully' '
144 test-tool run-command run-command-abort 3 false 2>actual &&
145 test_cmp expect actual
149 no further jobs available
152 test_expect_success
'run_command outputs ' '
153 test-tool run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
154 test_cmp expect actual
160 GIT_TRACE
=1 test-tool run-command
"$@" run-command true
2>&1 >/dev
/null | \
161 sed -e 's/.* run_command: //' -e '/trace: .*/d' >actual
&&
162 echo "$expect true" >expect
&&
163 test_cmp expect actual
166 test_expect_success
'GIT_TRACE with environment variables' '
167 test_trace "abc=1 def=2" env abc=1 env def=2 &&
168 test_trace "abc=2" env abc env abc=1 env abc=2 &&
169 test_trace "abc=2" env abc env abc=2 &&
171 abc=1 && export abc &&
172 test_trace "def=1" env abc=1 env def=1
175 abc=1 && export abc &&
176 test_trace "def=1" env abc env abc=1 env def=1
178 test_trace "def=1" env non-exist env def=1 &&
179 test_trace "abc=2" env abc=1 env abc env abc=2 &&
181 abc=1 def=2 && export abc def &&
182 test_trace "unset abc def;" env abc env def
185 abc=1 def=2 && export abc def &&
186 test_trace "unset def; abc=3" env abc env def env abc=3
189 abc=1 && export abc &&
190 test_trace "unset abc;" env abc=2 env abc