]> git.ipfire.org Git - thirdparty/git.git/blob - t/t0061-run-command.sh
t0061: adjust to test-tool transition
[thirdparty/git.git] / t / t0061-run-command.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2009 Ilari Liusvaara
4 #
5
6 test_description='Test run command'
7
8 . ./test-lib.sh
9
10 cat >hello-script <<-EOF
11 #!$SHELL_PATH
12 cat hello-script
13 EOF
14 >empty
15
16 test_expect_success 'start_command reports ENOENT (slash)' '
17 test-tool run-command start-command-ENOENT ./does-not-exist
18 '
19
20 test_expect_success 'start_command reports ENOENT (no slash)' '
21 test-tool run-command start-command-ENOENT does-not-exist
22 '
23
24 test_expect_success 'run_command can run a command' '
25 cat hello-script >hello.sh &&
26 chmod +x hello.sh &&
27 test-tool run-command run-command ./hello.sh >actual 2>err &&
28
29 test_cmp hello-script actual &&
30 test_cmp empty err
31 '
32
33 test_expect_success 'run_command is restricted to PATH' '
34 write_script should-not-run <<-\EOF &&
35 echo yikes
36 EOF
37 test_must_fail test-tool run-command run-command should-not-run
38 '
39
40 test_expect_success !MINGW 'run_command can run a script without a #! line' '
41 cat >hello <<-\EOF &&
42 cat hello-script
43 EOF
44 chmod +x hello &&
45 test-tool run-command run-command ./hello >actual 2>err &&
46
47 test_cmp hello-script actual &&
48 test_cmp empty err
49 '
50
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 &&
55 cat bin2/greet
56 EOF
57
58 PATH=$PWD/bin1:$PWD/bin2:$PATH \
59 test-tool run-command run-command greet >actual 2>err &&
60 test_cmp bin2/greet actual &&
61 test_cmp empty err
62 '
63
64 test_expect_success POSIXPERM 'run_command passes over non-executable file' '
65 test_when_finished "rm -rf bin1 bin2" &&
66 mkdir -p bin1 bin2 &&
67 write_script bin1/greet <<-\EOF &&
68 cat bin1/greet
69 EOF
70 chmod -x bin1/greet &&
71 write_script bin2/greet <<-\EOF &&
72 cat bin2/greet
73 EOF
74
75 PATH=$PWD/bin1:$PWD/bin2:$PATH \
76 test-tool run-command run-command greet >actual 2>err &&
77 test_cmp bin2/greet actual &&
78 test_cmp empty err
79 '
80
81 test_expect_success POSIXPERM 'run_command reports EACCES' '
82 cat hello-script >hello.sh &&
83 chmod -x hello.sh &&
84 test_must_fail test-tool run-command run-command ./hello.sh 2>err &&
85
86 grep "fatal: cannot exec.*hello.sh" err
87 '
88
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 &&
94 (
95 PATH=./local-command:$PATH &&
96 git nitfol >actual
97 ) &&
98 echo frotz >expect &&
99 test_cmp expect actual
100 '
101
102 cat >expect <<-EOF
103 preloaded output of a child
104 Hello
105 World
106 preloaded output of a child
107 Hello
108 World
109 preloaded output of a child
110 Hello
111 World
112 preloaded output of a child
113 Hello
114 World
115 EOF
116
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
120 '
121
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
125 '
126
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
130 '
131
132 cat >expect <<-EOF
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
139 EOF
140
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
144 '
145
146 cat >expect <<-EOF
147 no further jobs available
148 EOF
149
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
153 '
154
155 test_trace () {
156 expect="$1"
157 shift
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
162 }
163
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 &&
168 (
169 abc=1 && export abc &&
170 test_trace "def=1" env abc=1 env def=1
171 ) &&
172 (
173 abc=1 && export abc &&
174 test_trace "def=1" env abc env abc=1 env def=1
175 ) &&
176 test_trace "def=1" env non-exist env def=1 &&
177 test_trace "abc=2" env abc=1 env abc env abc=2 &&
178 (
179 abc=1 def=2 && export abc def &&
180 test_trace "unset abc def;" env abc env def
181 ) &&
182 (
183 abc=1 def=2 && export abc def &&
184 test_trace "unset def; abc=3" env abc env def env abc=3
185 ) &&
186 (
187 abc=1 && export abc &&
188 test_trace "unset abc;" env abc=2 env abc
189 )
190 '
191
192 test_done