]>
Commit | Line | Data |
---|---|---|
2b541bf8 JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2009 Ilari Liusvaara | |
4 | # | |
5 | ||
6 | test_description='Test run command' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
c0f19bf3 JN |
10 | cat >hello-script <<-EOF |
11 | #!$SHELL_PATH | |
12 | cat hello-script | |
13 | EOF | |
c0f19bf3 | 14 | |
321fd823 | 15 | test_expect_success 'start_command reports ENOENT (slash)' ' |
e5a329a2 JH |
16 | test-tool run-command start-command-ENOENT ./does-not-exist 2>err && |
17 | test_i18ngrep "\./does-not-exist" err | |
2b541bf8 JS |
18 | ' |
19 | ||
321fd823 | 20 | test_expect_success 'start_command reports ENOENT (no slash)' ' |
e5a329a2 JH |
21 | test-tool run-command start-command-ENOENT does-not-exist 2>err && |
22 | test_i18ngrep "does-not-exist" err | |
321fd823 JK |
23 | ' |
24 | ||
c0f19bf3 JN |
25 | test_expect_success 'run_command can run a command' ' |
26 | cat hello-script >hello.sh && | |
27 | chmod +x hello.sh && | |
ae6a51f5 | 28 | test-tool run-command run-command ./hello.sh >actual 2>err && |
c0f19bf3 JN |
29 | |
30 | test_cmp hello-script actual && | |
1c5e94f4 | 31 | test_must_be_empty err |
c0f19bf3 JN |
32 | ' |
33 | ||
321fd823 JK |
34 | test_expect_success 'run_command is restricted to PATH' ' |
35 | write_script should-not-run <<-\EOF && | |
36 | echo yikes | |
37 | EOF | |
e5a329a2 JH |
38 | test_must_fail test-tool run-command run-command should-not-run 2>err && |
39 | test_i18ngrep "should-not-run" err | |
321fd823 JK |
40 | ' |
41 | ||
c2d3119d BW |
42 | test_expect_success !MINGW 'run_command can run a script without a #! line' ' |
43 | cat >hello <<-\EOF && | |
44 | cat hello-script | |
45 | EOF | |
46 | chmod +x hello && | |
ae6a51f5 | 47 | test-tool run-command run-command ./hello >actual 2>err && |
c2d3119d BW |
48 | |
49 | test_cmp hello-script actual && | |
1c5e94f4 | 50 | test_must_be_empty err |
c2d3119d BW |
51 | ' |
52 | ||
94028310 BW |
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 && | |
57 | cat bin2/greet | |
58 | EOF | |
59 | ||
60 | PATH=$PWD/bin1:$PWD/bin2:$PATH \ | |
ae6a51f5 | 61 | test-tool run-command run-command greet >actual 2>err && |
94028310 | 62 | test_cmp bin2/greet actual && |
1c5e94f4 | 63 | test_must_be_empty err |
94028310 BW |
64 | ' |
65 | ||
66 | test_expect_success POSIXPERM 'run_command passes over non-executable file' ' | |
67 | test_when_finished "rm -rf bin1 bin2" && | |
68 | mkdir -p bin1 bin2 && | |
69 | write_script bin1/greet <<-\EOF && | |
70 | cat bin1/greet | |
71 | EOF | |
72 | chmod -x bin1/greet && | |
73 | write_script bin2/greet <<-\EOF && | |
74 | cat bin2/greet | |
75 | EOF | |
76 | ||
77 | PATH=$PWD/bin1:$PWD/bin2:$PATH \ | |
ae6a51f5 | 78 | test-tool run-command run-command greet >actual 2>err && |
94028310 | 79 | test_cmp bin2/greet actual && |
1c5e94f4 | 80 | test_must_be_empty err |
94028310 BW |
81 | ' |
82 | ||
c0f19bf3 JN |
83 | test_expect_success POSIXPERM 'run_command reports EACCES' ' |
84 | cat hello-script >hello.sh && | |
85 | chmod -x hello.sh && | |
ae6a51f5 | 86 | test_must_fail test-tool run-command run-command ./hello.sh 2>err && |
c0f19bf3 JN |
87 | |
88 | grep "fatal: cannot exec.*hello.sh" err | |
89 | ' | |
90 | ||
eae69530 | 91 | test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' ' |
38f865c2 JK |
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 && | |
96 | ( | |
97 | PATH=./local-command:$PATH && | |
98 | git nitfol >actual | |
99 | ) && | |
100 | echo frotz >expect && | |
101 | test_cmp expect actual | |
102 | ' | |
103 | ||
c553c72e SB |
104 | cat >expect <<-EOF |
105 | preloaded output of a child | |
106 | Hello | |
107 | World | |
108 | preloaded output of a child | |
109 | Hello | |
110 | World | |
111 | preloaded output of a child | |
112 | Hello | |
113 | World | |
114 | preloaded output of a child | |
115 | Hello | |
116 | World | |
117 | EOF | |
118 | ||
119 | test_expect_success 'run_command runs in parallel with more jobs available than tasks' ' | |
ae6a51f5 | 120 | test-tool run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
121 | test_cmp expect actual |
122 | ' | |
123 | ||
124 | test_expect_success 'run_command runs in parallel with as many jobs as tasks' ' | |
ae6a51f5 | 125 | test-tool run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
126 | test_cmp expect actual |
127 | ' | |
128 | ||
129 | test_expect_success 'run_command runs in parallel with more tasks than jobs available' ' | |
ae6a51f5 | 130 | test-tool run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
131 | test_cmp expect actual |
132 | ' | |
133 | ||
134 | cat >expect <<-EOF | |
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 | |
141 | EOF | |
142 | ||
143 | test_expect_success 'run_command is asked to abort gracefully' ' | |
ae6a51f5 | 144 | test-tool run-command run-command-abort 3 false 2>actual && |
c553c72e SB |
145 | test_cmp expect actual |
146 | ' | |
147 | ||
148 | cat >expect <<-EOF | |
149 | no further jobs available | |
150 | EOF | |
151 | ||
152 | test_expect_success 'run_command outputs ' ' | |
ae6a51f5 | 153 | test-tool run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
154 | test_cmp expect actual |
155 | ' | |
156 | ||
c61a975d NTND |
157 | test_trace () { |
158 | expect="$1" | |
159 | shift | |
ae6a51f5 | 160 | GIT_TRACE=1 test-tool run-command "$@" run-command true 2>&1 >/dev/null | \ |
226c0ddd | 161 | sed -e 's/.* run_command: //' -e '/trace: .*/d' >actual && |
c61a975d NTND |
162 | echo "$expect true" >expect && |
163 | test_cmp expect actual | |
164 | } | |
165 | ||
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 && | |
170 | ( | |
171 | abc=1 && export abc && | |
172 | test_trace "def=1" env abc=1 env def=1 | |
173 | ) && | |
174 | ( | |
175 | abc=1 && export abc && | |
176 | test_trace "def=1" env abc env abc=1 env def=1 | |
177 | ) && | |
178 | test_trace "def=1" env non-exist env def=1 && | |
179 | test_trace "abc=2" env abc=1 env abc env abc=2 && | |
180 | ( | |
181 | abc=1 def=2 && export abc def && | |
182 | test_trace "unset abc def;" env abc env def | |
183 | ) && | |
184 | ( | |
185 | abc=1 def=2 && export abc def && | |
186 | test_trace "unset def; abc=3" env abc env def env abc=3 | |
187 | ) && | |
188 | ( | |
189 | abc=1 && export abc && | |
190 | test_trace "unset abc;" env abc=2 env abc | |
191 | ) | |
192 | ' | |
193 | ||
2b541bf8 | 194 | test_done |