]>
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 | |
14 | >empty | |
15 | ||
321fd823 | 16 | test_expect_success 'start_command reports ENOENT (slash)' ' |
2b541bf8 JS |
17 | test-run-command start-command-ENOENT ./does-not-exist |
18 | ' | |
19 | ||
321fd823 JK |
20 | test_expect_success 'start_command reports ENOENT (no slash)' ' |
21 | test-run-command start-command-ENOENT does-not-exist | |
22 | ' | |
23 | ||
c0f19bf3 JN |
24 | test_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 |
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-run-command run-command should-not-run | |
38 | ' | |
39 | ||
c2d3119d BW |
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-run-command run-command ./hello >actual 2>err && | |
46 | ||
47 | test_cmp hello-script actual && | |
48 | test_cmp empty err | |
49 | ' | |
50 | ||
94028310 BW |
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-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-run-command run-command greet >actual 2>err && | |
77 | test_cmp bin2/greet actual && | |
78 | test_cmp empty err | |
79 | ' | |
80 | ||
c0f19bf3 JN |
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-run-command run-command ./hello.sh 2>err && | |
85 | ||
86 | grep "fatal: cannot exec.*hello.sh" err | |
87 | ' | |
88 | ||
eae69530 | 89 | test_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 |
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-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-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-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-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-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 | 155 | test_done |