Files
sausage/userland/brush/source/brush-shell/tests/cases/compat/builtins/builtin.yaml
T
2026-11-11 22:04:16 +00:00

134 lines
3.8 KiB
YAML

name: "Builtins: builtin"
cases:
- name: "builtin with no builtin"
stdin: builtin
- name: "builtin with unknown builtin"
ignore_stderr: true
stdin: builtin not-a-builtin args
- name: "valid builtin"
stdin: builtin echo "Hello world"
- name: "valid builtin with hyphen args"
stdin: builtin echo -e "Hello\nWorld"
- name: "builtin passing through results"
stdin: |
builtin false; echo "builtin false => $?"
builtin true; echo "builtin true => $?"
- name: "builtin with non-decl builtin"
stdin: |
builtin echo variable=value
- name: "builtin expands assignment-looking argument for ordinary builtin"
stdin: |
value=world
builtin echo argument=$value
- name: "builtin expands assignment-looking argument for simple builtin"
stdin: |
value=world
builtin true argument=$value
echo "[$_]"
- name: "builtin expands assignment-looking builtin name"
stdin: |
value=world
builtin missing=$value 2>/dev/null
printf 'status=%s last=<%s>\n' "$?" "$_"
- name: "builtin with decl builtin"
stdin: |
builtin declare variable=value
declare -p variable
- name: "builtin forwards expanded declaration assignments"
stdin: |
value=world
builtin declare declared=$value
builtin export exported=$value
declare -p declared exported
- name: "builtin with disabled builtin"
ignore_stderr: true
incompatible_os:
- opensuse-tumbleweed
stdin: |
cd .
echo $?
enable -n cd
builtin cd .
echo $?
enable cd
builtin cd .
echo $?
- name: "Function shadowing builtin receives its arguments"
stdin: |
builtin() { echo "shadow builtin: [$*] count=$#"; }
builtin echo hi
unset -f builtin
- name: "builtin forwards a value with no field separators intact"
stdin: |
value=world
builtin declare declared=$value
builtin export exported=$value
declare -p declared exported
- name: "builtin does not preserve assignment splitting semantics"
# brush treats `builtin` as a declaration wrapper, so an assignment argument passed through it
# keeps assignment semantics (no field splitting). Bash applies ordinary word expansion here,
# splitting the value and leaving a separate bare-name operand.
known_failure: true
ignore_stderr: true
stdin: |
v="x y"
builtin declare c=$v
declare -p c y
- name: "builtin splits assignment-shaped words for ordinary builtins"
known_failure: true # TODO(builtin): brush's builtin is a declaration utility, so a=$x isn't split
stdin: |
x="1 2"
builtin printf '[%s]' a=$x
echo
- name: "builtin --help prints help on stdout"
known_failure: true # TODO(builtin): --help is looked up as a builtin's name
stdin: |
builtin --help >/dev/null 2>&1; echo "rc=$?"
[[ -n $(builtin --help 2>/dev/null) ]] && echo "help on stdout"
- name: "builtin rejects options"
known_failure: true # TODO(builtin): options are looked up as builtin names
ignore_stderr: true
stdin: |
builtin -z true; echo "rc=$?"
builtin -- true; echo "rc=$?"
- name: "builtin drops a special builtin's fatal errors in POSIX mode"
ignore_stderr: true
stdin: |
set -o posix
builtin export --bogus
echo "still running: $?"
- name: "builtin expands a ~ after the = of a declaration it passes on"
home_dir: .
stdin: |
test_root=~
builtin export y=~/z
echo "${y//${test_root}/ROOT}"
builtin declare d=~/w
echo "${d//${test_root}/ROOT}"
- name: "builtin passes --help on to the builtin it runs"
stdin: |
builtin cd --help >/dev/null 2>&1; echo "rc=$?"
[[ "$(builtin cd --help; echo .)" == "$(help cd; echo .)" ]] && echo "same as help cd"