3 # Copyright (c) 2009 Ilari Liusvaara
6 test_description
='Test run command'
10 cat >hello-script
<<-EOF
16 test_expect_success
'start_command reports ENOENT (slash)' '
17 test-tool run-command start-command-ENOENT ./does-not-exist
20 test_expect_success
'start_command reports ENOENT (no slash)' '
21 test-tool run-command start-command-ENOENT does-not-exist
24 test_expect_success
'run_command can run a command' '
25 cat hello-script >hello.sh &&
27 test-tool run-command run-command ./hello.sh >actual 2>err &&
29 test_cmp hello-script actual &&
33 test_expect_success
'run_command is restricted to PATH' '
34 write_script should-not-run <<-\EOF &&
37 test_must_fail test-tool run-command run-command should-not-run
40 test_expect_success
!MINGW
'run_command can run a script without a #! line' '
45 test-tool run-command run-command ./hello >actual 2>err &&
47 test_cmp hello-script actual &&
51 test_expect_success
'run_command does not try to execute a directory' '
52 test_when_finished "rm -rf bin1 bin2" &&
53 mkdir -p bin1/greet bin2 &&
54 write_script bin2/greet <<-\EOF &&
58 PATH=$PWD/bin1:$PWD/bin2:$PATH \
59 test-tool run-command run-command greet >actual 2>err &&
60 test_cmp bin2/greet actual &&
64 test_expect_success POSIXPERM
'run_command passes over non-executable file' '
65 test_when_finished "rm -rf bin1 bin2" &&
67 write_script bin1/greet <<-\EOF &&
70 chmod -x bin1/greet &&
71 write_script bin2/greet <<-\EOF &&
75 PATH=$PWD/bin1:$PWD/bin2:$PATH \
76 test-tool run-command run-command greet >actual 2>err &&
77 test_cmp bin2/greet actual &&
81 test_expect_success POSIXPERM
'run_command reports EACCES' '
82 cat hello-script >hello.sh &&
84 test_must_fail test-tool run-command run-command ./hello.sh 2>err &&
86 grep "fatal: cannot exec.*hello.sh" err
89 test_expect_success POSIXPERM
,SANITY
'unreadable directory in PATH' '
90 mkdir local-command &&
91 test_when_finished "chmod u+rwx local-command && rm -fr local-command" &&
92 git config alias.nitfol "!echo frotz" &&
93 chmod a-rx local-command &&
95 PATH=./local-command:$PATH &&
99 test_cmp expect actual
103 preloaded output of a child
106 preloaded output of a child
109 preloaded output of a child
112 preloaded output of a child
117 test_expect_success
'run_command runs in parallel with more jobs available than tasks' '
118 test-tool run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
119 test_cmp expect actual
122 test_expect_success
'run_command runs in parallel with as many jobs as tasks' '
123 test-tool run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
124 test_cmp expect actual
127 test_expect_success
'run_command runs in parallel with more tasks than jobs available' '
128 test-tool run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
129 test_cmp expect actual
133 preloaded output of a child
134 asking for a quick stop
135 preloaded output of a child
136 asking for a quick stop
137 preloaded output of a child
138 asking for a quick stop
141 test_expect_success
'run_command is asked to abort gracefully' '
142 test-tool run-command run-command-abort 3 false 2>actual &&
143 test_cmp expect actual
147 no further jobs available
150 test_expect_success
'run_command outputs ' '
151 test-tool run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
152 test_cmp expect actual
158 GIT_TRACE
=1 test-tool run-command
"$@" run-command true
2>&1 >/dev
/null | \
159 sed -e 's/.* run_command: //' -e '/trace: .*/d' >actual
&&
160 echo "$expect true" >expect
&&
161 test_cmp expect actual
164 test_expect_success
'GIT_TRACE with environment variables' '
165 test_trace "abc=1 def=2" env abc=1 env def=2 &&
166 test_trace "abc=2" env abc env abc=1 env abc=2 &&
167 test_trace "abc=2" env abc env abc=2 &&
169 abc=1 && export abc &&
170 test_trace "def=1" env abc=1 env def=1
173 abc=1 && export abc &&
174 test_trace "def=1" env abc env abc=1 env def=1
176 test_trace "def=1" env non-exist env def=1 &&
177 test_trace "abc=2" env abc=1 env abc env abc=2 &&
179 abc=1 def=2 && export abc def &&
180 test_trace "unset abc def;" env abc env def
183 abc=1 def=2 && export abc def &&
184 test_trace "unset def; abc=3" env abc env def env abc=3
187 abc=1 && export abc &&
188 test_trace "unset abc;" env abc=2 env abc