builtins to allow stdin to be closed

Prior to this fix, if stdin were explicitly closed, then builtins would
silently fail. For example:

    count <&-

would just fail with status 1. Remove this limitation and allow each
builtin to handle a closed stdin how it sees fit.
This commit is contained in:
ridiculousfish
2021-02-10 17:19:08 -08:00
parent f239329f33
commit 84d59accfc
9 changed files with 44 additions and 8 deletions

View File

@@ -50,7 +50,7 @@ test -f $tmpdir/file.txt && echo "File exists" || echo "File does not exist"
function foo
if set -q argv[1]
foo > $argv[1]
foo >$argv[1]
end
echo foo
end
@@ -89,6 +89,19 @@ begin
end 2>| cat >/dev/null
#CHECK: is_stdout
# Verify builtin behavior with closed stdin.
# count silently ignores closed stdin, others may print an error.
true <&-
echo $status
#CHECK: 0
test -t 0 <&-
echo $status
#CHECK: 1
read abc <&-
#CHECKERR: read: stdin is closed
# "Verify that pipes don't conflict with fd redirections"
# This code is very similar to eval. We go over a bunch of fads
# to make it likely that we will nominally conflict with a pipe