Skip to content

Commit c0f19bf

Browse files
jrngitster
authored andcommitted
tests: check error message from run_command
In git versions starting at v1.7.5-rc0~29^2 until v1.7.5-rc3~2 (Revert "run-command: prettify -D_FORTIFY_SOURCE workaround", 2011-04-18) fixed it, the run_command facility would write a truncated error message when the command is present but cannot be executed for some other reason. For example, if I add a 'hello' command to git: $ echo 'echo hello' >git-hello $ chmod +x git-hello $ PATH=.:$PATH git hello hello and make it non-executable, this is what I normally get: $ chmod -x git-hello $ git hello fatal: cannot exec 'git-hello': Permission denied But with the problematic versions, we get disturbing output: $ PATH=.:$PATH git hello fatal: $ Add some tests to make sure it doesn't happen again. The hello-script used in these tests uses cat instead of echo because on Windows the bash spawned by git converts LF to CRLF in text written by echo while the bash running tests does not, causing the test to fail if "echo" is used. Thanks to Hannes for noticing. Signed-off-by: Jonathan Nieder <[email protected]> Improved-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 60e199c commit c0f19bf

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

t/t0061-run-command.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,31 @@ test_description='Test run command'
77

88
. ./test-lib.sh
99

10+
cat >hello-script <<-EOF
11+
#!$SHELL_PATH
12+
cat hello-script
13+
EOF
14+
>empty
15+
1016
test_expect_success 'start_command reports ENOENT' '
1117
test-run-command start-command-ENOENT ./does-not-exist
1218
'
1319

20+
test_expect_success 'run_command can run a command' '
21+
cat hello-script >hello.sh &&
22+
chmod +x hello.sh &&
23+
test-run-command run-command ./hello.sh >actual 2>err &&
24+
25+
test_cmp hello-script actual &&
26+
test_cmp empty err
27+
'
28+
29+
test_expect_success POSIXPERM 'run_command reports EACCES' '
30+
cat hello-script >hello.sh &&
31+
chmod -x hello.sh &&
32+
test_must_fail test-run-command run-command ./hello.sh 2>err &&
33+
34+
grep "fatal: cannot exec.*hello.sh" err
35+
'
36+
1437
test_done

test-run-command.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ int main(int argc, char **argv)
2929
fprintf(stderr, "FAIL %s\n", argv[1]);
3030
return 1;
3131
}
32+
if (!strcmp(argv[1], "run-command"))
33+
exit(run_command(&proc));
3234

3335
fprintf(stderr, "check usage\n");
3436
return 1;

0 commit comments

Comments
 (0)