]>
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 | |
2b541bf8 | 15 | test_expect_success 'start_command reports ENOENT' ' |
ae6a51f5 | 16 | test-tool run-command start-command-ENOENT ./does-not-exist |
2b541bf8 JS |
17 | ' |
18 | ||
c0f19bf3 JN |
19 | test_expect_success 'run_command can run a command' ' |
20 | cat hello-script >hello.sh && | |
21 | chmod +x hello.sh && | |
ae6a51f5 | 22 | test-tool run-command run-command ./hello.sh >actual 2>err && |
c0f19bf3 JN |
23 | |
24 | test_cmp hello-script actual && | |
1c5e94f4 | 25 | test_must_be_empty err |
c0f19bf3 JN |
26 | ' |
27 | ||
c2d3119d BW |
28 | test_expect_success !MINGW 'run_command can run a script without a #! line' ' |
29 | cat >hello <<-\EOF && | |
30 | cat hello-script | |
31 | EOF | |
32 | chmod +x hello && | |
ae6a51f5 | 33 | test-tool run-command run-command ./hello >actual 2>err && |
c2d3119d BW |
34 | |
35 | test_cmp hello-script actual && | |
1c5e94f4 | 36 | test_must_be_empty err |
c2d3119d BW |
37 | ' |
38 | ||
94028310 BW |
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 && | |
43 | cat bin2/greet | |
44 | EOF | |
45 | ||
46 | PATH=$PWD/bin1:$PWD/bin2:$PATH \ | |
ae6a51f5 | 47 | test-tool run-command run-command greet >actual 2>err && |
94028310 | 48 | test_cmp bin2/greet actual && |
1c5e94f4 | 49 | test_must_be_empty err |
94028310 BW |
50 | ' |
51 | ||
52 | test_expect_success POSIXPERM 'run_command passes over non-executable file' ' | |
53 | test_when_finished "rm -rf bin1 bin2" && | |
54 | mkdir -p bin1 bin2 && | |
55 | write_script bin1/greet <<-\EOF && | |
56 | cat bin1/greet | |
57 | EOF | |
58 | chmod -x bin1/greet && | |
59 | write_script bin2/greet <<-\EOF && | |
60 | cat bin2/greet | |
61 | EOF | |
62 | ||
63 | PATH=$PWD/bin1:$PWD/bin2:$PATH \ | |
ae6a51f5 | 64 | test-tool run-command run-command greet >actual 2>err && |
94028310 | 65 | test_cmp bin2/greet actual && |
1c5e94f4 | 66 | test_must_be_empty err |
94028310 BW |
67 | ' |
68 | ||
c0f19bf3 JN |
69 | test_expect_success POSIXPERM 'run_command reports EACCES' ' |
70 | cat hello-script >hello.sh && | |
71 | chmod -x hello.sh && | |
ae6a51f5 | 72 | test_must_fail test-tool run-command run-command ./hello.sh 2>err && |
c0f19bf3 JN |
73 | |
74 | grep "fatal: cannot exec.*hello.sh" err | |
75 | ' | |
76 | ||
eae69530 | 77 | test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' ' |
38f865c2 JK |
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 && | |
82 | ( | |
83 | PATH=./local-command:$PATH && | |
84 | git nitfol >actual | |
85 | ) && | |
86 | echo frotz >expect && | |
87 | test_cmp expect actual | |
88 | ' | |
89 | ||
c553c72e SB |
90 | cat >expect <<-EOF |
91 | preloaded output of a child | |
92 | Hello | |
93 | World | |
94 | preloaded output of a child | |
95 | Hello | |
96 | World | |
97 | preloaded output of a child | |
98 | Hello | |
99 | World | |
100 | preloaded output of a child | |
101 | Hello | |
102 | World | |
103 | EOF | |
104 | ||
105 | test_expect_success 'run_command runs in parallel with more jobs available than tasks' ' | |
ae6a51f5 | 106 | test-tool run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
107 | test_cmp expect actual |
108 | ' | |
109 | ||
110 | test_expect_success 'run_command runs in parallel with as many jobs as tasks' ' | |
ae6a51f5 | 111 | test-tool run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
112 | test_cmp expect actual |
113 | ' | |
114 | ||
115 | test_expect_success 'run_command runs in parallel with more tasks than jobs available' ' | |
ae6a51f5 | 116 | test-tool run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
117 | test_cmp expect actual |
118 | ' | |
119 | ||
120 | cat >expect <<-EOF | |
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 | |
127 | EOF | |
128 | ||
129 | test_expect_success 'run_command is asked to abort gracefully' ' | |
ae6a51f5 | 130 | test-tool run-command run-command-abort 3 false 2>actual && |
c553c72e SB |
131 | test_cmp expect actual |
132 | ' | |
133 | ||
134 | cat >expect <<-EOF | |
135 | no further jobs available | |
136 | EOF | |
137 | ||
138 | test_expect_success 'run_command outputs ' ' | |
ae6a51f5 | 139 | test-tool run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && |
c553c72e SB |
140 | test_cmp expect actual |
141 | ' | |
142 | ||
c61a975d NTND |
143 | test_trace () { |
144 | expect="$1" | |
145 | shift | |
ae6a51f5 | 146 | GIT_TRACE=1 test-tool run-command "$@" run-command true 2>&1 >/dev/null | \ |
226c0ddd | 147 | sed -e 's/.* run_command: //' -e '/trace: .*/d' >actual && |
c61a975d NTND |
148 | echo "$expect true" >expect && |
149 | test_cmp expect actual | |
150 | } | |
151 | ||
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 && | |
156 | ( | |
157 | abc=1 && export abc && | |
158 | test_trace "def=1" env abc=1 env def=1 | |
159 | ) && | |
160 | ( | |
161 | abc=1 && export abc && | |
162 | test_trace "def=1" env abc env abc=1 env def=1 | |
163 | ) && | |
164 | test_trace "def=1" env non-exist env def=1 && | |
165 | test_trace "abc=2" env abc=1 env abc env abc=2 && | |
166 | ( | |
167 | abc=1 def=2 && export abc def && | |
168 | test_trace "unset abc def;" env abc env def | |
169 | ) && | |
170 | ( | |
171 | abc=1 def=2 && export abc def && | |
172 | test_trace "unset def; abc=3" env abc env def env abc=3 | |
173 | ) && | |
174 | ( | |
175 | abc=1 && export abc && | |
176 | test_trace "unset abc;" env abc=2 env abc | |
177 | ) | |
178 | ' | |
179 | ||
2b541bf8 | 180 | test_done |