Browse Source

/dev/stdin...

main
pvincent 2 days ago
parent
commit
30658cc495
  1. 29
      bin/miaou-bash
  2. 2
      test/miaou-bash.test.bash
  3. 3
      test/stub/scenario.bash

29
bin/miaou-bash

@ -623,9 +623,16 @@ function usage {
}
function parse_options {
[[ $# == 0 ]] && >&2 echo 'ERROR: script expected!' && builtin exit 2
if [[ $# == 1 ]]; then
HEREDOC=false
if [[ $# == 0 ]]; then
if [[ -t 0 ]]; then
>&2 echo 'ERROR: script expected!'
builtin exit 2
else
HEREDOC=true
return
fi
elif [[ $# == 1 ]]; then
case "$1" in
--help) usage && builtin exit ;;
--version) cat "${MIAOU_BASH_DIR:-/opt/miaou-bash}/.semver_git_tag" && builtin exit ;;
@ -646,10 +653,12 @@ function parse_options {
fi
[[ $1 =~ ^- ]] && >&2 echo "ERROR: too many args $#, either single option or SCRIPT + args accepted!" && builtin exit 2
SCRIPT="$1"
[[ ! -v SCRIPT ]] && >&2 echo 'ERROR: script expected!' && builtin exit 2
[[ ! -f "$SCRIPT" ]] && >&2 echo "ERROR: script '$SCRIPT' not found!" && builtin exit 2
true
if [[ ! -f "$SCRIPT" ]]; then
>&2 echo "ERROR: script '$SCRIPT' not found!"
builtin exit 3
fi
}
function read {
@ -670,7 +679,8 @@ trap 'on_exit $?' EXIT
trap 'on_pipe' PIPE
trap 'on_return' RETURN
BASH_ARGV0="$SCRIPT" && shift
[[ -v SCRIPT ]] && BASH_ARGV0="${SCRIPT}" && shift
if is_true "$CHILD_PROCESS"; then
# any nested children
exec 4>/dev/tty 2>"$MIAOU_BASH_ERROR"
@ -688,5 +698,10 @@ else
miaou_debug "<main file=$BASH_ARGV0 pid=${BASHPID}/>"
fi
if [[ "$HEREDOC" == true ]]; then
# shellcheck source=/dev/stdin
source /dev/stdin
else
# shellcheck source=/dev/null
source "$SCRIPT"
fi

2
test/miaou-bash.test.bash

@ -139,7 +139,7 @@ time {
fail_stderr_count unbound_variable 1
fail_stderr_count child_error 4
fail_miaou_count command_error_multiline 6
fail_miaou_count command_error_multiline 7
}
failed=${#failures[@]}
success=$((test_count - failed))

3
test/stub/scenario.bash

@ -13,8 +13,9 @@ function do_subshell_false {
}
function do_command_error_multiline {
miaou-bash <<EOF
source /dev/stdin <<EOF
echo ok
echo yop
false
echo SHOULD NOT APPEAR
EOF

Loading…
Cancel
Save