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' '
16 test-tool run-command start-command-ENOENT ./does-not-exist
19 test_expect_success 'run_command can run a command' '
20 cat hello-script >hello.sh &&
22 test-tool run-command run-command ./hello.sh >actual 2>err &&
24 test_cmp hello-script actual &&
25 test_must_be_empty err
28 test_expect_success !MINGW 'run_command can run a script without a #! line' '
33 test-tool run-command run-command ./hello >actual 2>err &&
35 test_cmp hello-script actual &&
36 test_must_be_empty err
39 test_expect_success 'run_command does not try to execute a directory' '
40 test_when_finished "rm -rf bin1 bin2" &&
41 mkdir -p bin1/greet bin2 &&
42 write_script bin2/greet <<-\EOF &&
46 PATH=$PWD/bin1:$PWD/bin2:$PATH \
47 test-tool run-command run-command greet >actual 2>err &&
48 test_cmp bin2/greet actual &&
49 test_must_be_empty err
52 test_expect_success POSIXPERM 'run_command passes over non-executable file' '
53 test_when_finished "rm -rf bin1 bin2" &&
55 write_script bin1/greet <<-\EOF &&
58 chmod -x bin1/greet &&
59 write_script bin2/greet <<-\EOF &&
63 PATH=$PWD/bin1:$PWD/bin2:$PATH \
64 test-tool run-command run-command greet >actual 2>err &&
65 test_cmp bin2/greet actual &&
66 test_must_be_empty err
69 test_expect_success POSIXPERM 'run_command reports EACCES' '
70 cat hello-script >hello.sh &&
72 test_must_fail test-tool run-command run-command ./hello.sh 2>err &&
74 grep "fatal: cannot exec.*hello.sh" err
77 test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' '
78 mkdir local-command &&
79 test_when_finished "chmod u+rwx local-command && rm -fr local-command" &&
80 git config alias.nitfol "!echo frotz" &&
81 chmod a-rx local-command &&
83 PATH=./local-command:$PATH &&
87 test_cmp expect actual
91 preloaded output of a child
94 preloaded output of a child
97 preloaded output of a child
100 preloaded output of a child
105 test_expect_success 'run_command runs in parallel with more jobs available than tasks' '
106 test-tool run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
107 test_cmp expect actual
110 test_expect_success 'run_command runs in parallel with as many jobs as tasks' '
111 test-tool run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
112 test_cmp expect actual
115 test_expect_success 'run_command runs in parallel with more tasks than jobs available' '
116 test-tool run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
117 test_cmp expect actual
121 preloaded output of a child
122 asking for a quick stop
123 preloaded output of a child
124 asking for a quick stop
125 preloaded output of a child
126 asking for a quick stop
129 test_expect_success 'run_command is asked to abort gracefully' '
130 test-tool run-command run-command-abort 3 false 2>actual &&
131 test_cmp expect actual
135 no further jobs available
138 test_expect_success 'run_command outputs ' '
139 test-tool run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
140 test_cmp expect actual
146 GIT_TRACE=1 test-tool run-command "$@" run-command true 2>&1 >/dev/null | \
147 sed -e 's/.* run_command: //' -e '/trace: .*/d' >actual &&
148 echo "$expect true" >expect &&
149 test_cmp expect actual
152 test_expect_success 'GIT_TRACE with environment variables' '
153 test_trace "abc=1 def=2" env abc=1 env def=2 &&
154 test_trace "abc=2" env abc env abc=1 env abc=2 &&
155 test_trace "abc=2" env abc env abc=2 &&
157 abc=1 && export abc &&
158 test_trace "def=1" env abc=1 env def=1
161 abc=1 && export abc &&
162 test_trace "def=1" env abc env abc=1 env def=1
164 test_trace "def=1" env non-exist env def=1 &&
165 test_trace "abc=2" env abc=1 env abc env abc=2 &&
167 abc=1 def=2 && export abc def &&
168 test_trace "unset abc def;" env abc env def
171 abc=1 def=2 && export abc def &&
172 test_trace "unset def; abc=3" env abc env def env abc=3
175 abc=1 && export abc &&
176 test_trace "unset abc;" env abc=2 env abc