]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0061-run-command.sh
run-command: mark path lookup errors with ENOENT
[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
14>empty
15
321fd823 16test_expect_success 'start_command reports ENOENT (slash)' '
2b541bf8
JS
17 test-run-command start-command-ENOENT ./does-not-exist
18'
19
321fd823
JK
20test_expect_success 'start_command reports ENOENT (no slash)' '
21 test-run-command start-command-ENOENT does-not-exist
22'
23
c0f19bf3
JN
24test_expect_success 'run_command can run a command' '
25 cat hello-script >hello.sh &&
26 chmod +x hello.sh &&
27 test-run-command run-command ./hello.sh >actual 2>err &&
28
29 test_cmp hello-script actual &&
30 test_cmp empty err
31'
32
321fd823
JK
33test_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-run-command run-command should-not-run
38'
39
c2d3119d
BW
40test_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-run-command run-command ./hello >actual 2>err &&
46
47 test_cmp hello-script actual &&
48 test_cmp empty err
49'
50
94028310
BW
51test_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-run-command run-command greet >actual 2>err &&
60 test_cmp bin2/greet actual &&
61 test_cmp empty err
62'
63
64test_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-run-command run-command greet >actual 2>err &&
77 test_cmp bin2/greet actual &&
78 test_cmp empty err
79'
80
c0f19bf3
JN
81test_expect_success POSIXPERM 'run_command reports EACCES' '
82 cat hello-script >hello.sh &&
83 chmod -x hello.sh &&
84 test_must_fail test-run-command run-command ./hello.sh 2>err &&
85
86 grep "fatal: cannot exec.*hello.sh" err
87'
88
eae69530 89test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' '
38f865c2
JK
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
c553c72e
SB
102cat >expect <<-EOF
103preloaded output of a child
104Hello
105World
106preloaded output of a child
107Hello
108World
109preloaded output of a child
110Hello
111World
112preloaded output of a child
113Hello
114World
115EOF
116
117test_expect_success 'run_command runs in parallel with more jobs available than tasks' '
118 test-run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
119 test_cmp expect actual
120'
121
122test_expect_success 'run_command runs in parallel with as many jobs as tasks' '
123 test-run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
124 test_cmp expect actual
125'
126
127test_expect_success 'run_command runs in parallel with more tasks than jobs available' '
128 test-run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
129 test_cmp expect actual
130'
131
132cat >expect <<-EOF
133preloaded output of a child
134asking for a quick stop
135preloaded output of a child
136asking for a quick stop
137preloaded output of a child
138asking for a quick stop
139EOF
140
141test_expect_success 'run_command is asked to abort gracefully' '
142 test-run-command run-command-abort 3 false 2>actual &&
143 test_cmp expect actual
144'
145
146cat >expect <<-EOF
147no further jobs available
148EOF
149
150test_expect_success 'run_command outputs ' '
151 test-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
2b541bf8 155test_done