fish-shell/tests/checks/noshebang.fish
Fabian Homborg b3da0bd5a2 tests/noshebang: Add some longer sleeps
This still fails on launchpad. Last try, then I'm removing this - it's
not really expected that this particular bit would change a lot.
2021-05-30 17:19:04 +02:00

96 lines
2 KiB
Fish

# RUN: %fish -C'set -g fish (builtin realpath %fish)' %s
# Test for shebangless scripts - see 7802.
set testdir (mktemp -d)
cd $testdir
$fish -c 'true > file'
chmod a+x file
function runfile
# Run our file twice, printing status.
# Arguments are passed to exercise the re-execve code paths; they have no other effect.
true # clear status
set -g fish_use_posix_spawn 1
./file arg1 arg2 arg3
echo $status
true # clear status
set -g fish_use_posix_spawn 0
./file arg1 arg2 arg3 arg4 arg5
echo $status
end
# Empty executable files are 'true'.
sleep 0.2
runfile
#CHECK: 0
#CHECK: 0
# Files without NUL are 'true' as well.
# NOTE: We redirect in a new process because the file must be *closed*
# before it can be run. On some systems that doesn't happen quickly enough.
$fish -c "echo -e -n '#COMMENT\n#COMMENT' >file"
sleep 0.2
runfile
#CHECK: 0
#CHECK: 0
# Never implicitly pass files ending with .fish to /bin/sh.
touch file.fish
chmod a+x file.fish
sleep 0.3
set -g fish_use_posix_spawn 0
./file.fish
echo $status
set -g fish_use_posix_spawn 1
./file.fish
echo $status
rm file.fish
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}
# On to NUL bytes.
# The heuristic is that there must be a line containing a lowercase letter before the first NUL byte.
$fish -c "echo -n -e 'true\n\x00' >file"
sleep 0.3
runfile
#CHECK: 0
#CHECK: 0
# Doesn't meet our heuristic as there is no newline.
$fish -c "echo -n -e 'true\x00' >file"
sleep 0.3
runfile
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}
# Doesn't meet our heuristic as there is no lowercase before newline.
$fish -c "echo -n -e 'NOPE\n\x00' >file"
sleep 0.1
runfile
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}