3 # Copyright (c) 2009 Ilari Liusvaara
6 test_description='Test run command'
10 cat >hello-script <<-EOF
16 test_expect_success 'start_command reports ENOENT' '
17 test-run-command start-command-ENOENT ./does-not-exist
20 test_expect_success 'run_command can run a command' '
21 cat hello-script >hello.sh &&
23 test-run-command run-command ./hello.sh >actual 2>err &&
25 test_cmp hello-script actual &&
29 test_expect_success !MINGW 'run_command can run a script without a #! line' '
34 test-run-command run-command ./hello >actual 2>err &&
36 test_cmp hello-script actual &&
40 test_expect_success 'run_command does not try to execute a directory' '
41 test_when_finished "rm -rf bin1 bin2" &&
42 mkdir -p bin1/greet bin2 &&
43 write_script bin2/greet <<-\EOF &&
47 PATH=$PWD/bin1:$PWD/bin2:$PATH \
48 test-run-command run-command greet >actual 2>err &&
49 test_cmp bin2/greet actual &&
53 test_expect_success POSIXPERM 'run_command passes over non-executable file' '
54 test_when_finished "rm -rf bin1 bin2" &&
56 write_script bin1/greet <<-\EOF &&
59 chmod -x bin1/greet &&
60 write_script bin2/greet <<-\EOF &&
64 PATH=$PWD/bin1:$PWD/bin2:$PATH \
65 test-run-command run-command greet >actual 2>err &&
66 test_cmp bin2/greet actual &&
70 test_expect_success POSIXPERM 'run_command reports EACCES' '
71 cat hello-script >hello.sh &&
73 test_must_fail test-run-command run-command ./hello.sh 2>err &&
75 grep "fatal: cannot exec.*hello.sh" err
78 test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' '
79 mkdir local-command &&
80 test_when_finished "chmod u+rwx local-command && rm -fr local-command" &&
81 git config alias.nitfol "!echo frotz" &&
82 chmod a-rx local-command &&
84 PATH=./local-command:$PATH &&
88 test_cmp expect actual
92 preloaded output of a child
95 preloaded output of a child
98 preloaded output of a child
101 preloaded output of a child
106 test_expect_success 'run_command runs in parallel with more jobs available than tasks' '
107 test-run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
108 test_cmp expect actual
111 test_expect_success 'run_command runs in parallel with as many jobs as tasks' '
112 test-run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
113 test_cmp expect actual
116 test_expect_success 'run_command runs in parallel with more tasks than jobs available' '
117 test-run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
118 test_cmp expect actual
122 preloaded output of a child
123 asking for a quick stop
124 preloaded output of a child
125 asking for a quick stop
126 preloaded output of a child
127 asking for a quick stop
130 test_expect_success 'run_command is asked to abort gracefully' '
131 test-run-command run-command-abort 3 false 2>actual &&
132 test_cmp expect actual
136 no further jobs available
139 test_expect_success 'run_command outputs ' '
140 test-run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
141 test_cmp expect actual