mingw: replace MSVCRT's fstat() with a Win32-based implementation
[git/raj.git] / t / t0061-run-command.sh
blob3e131c5325e363fa6188456e3f5f3f47f762801e
1 #!/bin/sh
3 # Copyright (c) 2009 Ilari Liusvaara
6 test_description='Test run command'
8 . ./test-lib.sh
10 cat >hello-script <<-EOF
11 #!$SHELL_PATH
12 cat hello-script
13 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 &&
21 chmod +x 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' '
29 cat >hello <<-\EOF &&
30 cat hello-script
31 EOF
32 chmod +x hello &&
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 &&
43 cat bin2/greet
44 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" &&
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
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 &&
71 chmod -x 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 &&
84 git nitfol >actual
85 ) &&
86 echo frotz >expect &&
87 test_cmp expect actual
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
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
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
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
134 cat >expect <<-EOF
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
143 test_trace () {
144 expect="$1"
145 shift
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
159 ) &&
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 &&
167 abc=1 def=2 && export abc def &&
168 test_trace "unset abc def;" env abc env def
169 ) &&
171 abc=1 def=2 && export abc def &&
172 test_trace "unset def; abc=3" env abc env def env abc=3
173 ) &&
175 abc=1 && export abc &&
176 test_trace "unset abc;" env abc=2 env abc
180 test_done