]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0061-run-command.sh
t0000: use hash translation table
[thirdparty/git.git] / t / t0061-run-command.sh
CommitLineData
2b541bf8
JS
1#!/bin/sh
2#
3# Copyright (c) 2009 Ilari Liusvaara
4#
5
6test_description='Test run command'
7
8. ./test-lib.sh
9
c0f19bf3
JN
10cat >hello-script <<-EOF
11 #!$SHELL_PATH
12 cat hello-script
13EOF
c0f19bf3 14
2b541bf8 15test_expect_success 'start_command reports ENOENT' '
ae6a51f5 16 test-tool run-command start-command-ENOENT ./does-not-exist
2b541bf8
JS
17'
18
c0f19bf3
JN
19test_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
28test_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
39test_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
52test_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
69test_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 77test_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
90cat >expect <<-EOF
91preloaded output of a child
92Hello
93World
94preloaded output of a child
95Hello
96World
97preloaded output of a child
98Hello
99World
100preloaded output of a child
101Hello
102World
103EOF
104
105test_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
110test_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
115test_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
120cat >expect <<-EOF
121preloaded output of a child
122asking for a quick stop
123preloaded output of a child
124asking for a quick stop
125preloaded output of a child
126asking for a quick stop
127EOF
128
129test_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
134cat >expect <<-EOF
135no further jobs available
136EOF
137
138test_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
143test_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
152test_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 180test_done