consmirror.c: the BSD notice is replaced (Makronix's own file). Files with changes of other sessions pending are left for their commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
71 lines
2.4 KiB
Bash
71 lines
2.4 KiB
Bash
#!/bin/sh
|
|
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
#
|
|
# Test of the env port. src/tests/usr.bin/env does not exist, so there is no
|
|
# NetBSD test to translate; the cases are the ones env(1) documents --
|
|
# name=value additions, -i, -0, -u, --, running a utility with the modified
|
|
# environment, and its exit status.
|
|
#
|
|
# Usage: test.sh ENV DATADIR
|
|
# ENV the command that runs the port (a path, or "qemu-aarch64 -L
|
|
# <sysroot> <path>"; tools/userland-test.sh passes it)
|
|
# DATADIR unused (src/tests/usr.bin/env does not exist)
|
|
# Prints one line per case and exits non-zero if one failed.
|
|
|
|
[ $# -eq 2 ] || { echo "usage: $0 ENV DATADIR" >&2; exit 2; }
|
|
env=$1 d=$2
|
|
fails=0
|
|
t=${TMPDIR:-/tmp}/env-test.$$
|
|
mkdir -p "$t" || exit 1
|
|
trap 'rm -rf "$t"' EXIT
|
|
LC_ALL=C
|
|
export LC_ALL
|
|
|
|
ok() { echo "PASS $1"; }
|
|
no() { echo "FAIL $1"; fails=$((fails + 1)); }
|
|
same() { # NAME EXPECTED-FILE: compare $t/out with it
|
|
if cmp -s "$2" "$t/out"; then ok "$1"; else no "$1"; fi
|
|
}
|
|
|
|
# env(1) -i: "completely ignore the environment it inherits"; each
|
|
# name=value is "added to the environment"; with no utility the pairs are
|
|
# printed "separated by a new line".
|
|
$env -i A=1 B=two > "$t/out" 2> "$t/err"
|
|
printf 'A=1\nB=two\n' > "$t/exp"
|
|
same clear-and-set "$t/exp"
|
|
|
|
# env(1) -0: "name/value pairs are separated by a nul character".
|
|
$env -i -0 A=1 > "$t/out" 2> "$t/err"
|
|
printf 'A=1\000' > "$t/exp"
|
|
same nul-separated "$t/exp"
|
|
|
|
# env(1): "executes utility ... after modifying the environment".
|
|
$env -i FOO=bar /bin/sh -c 'printf "%s\n" "$FOO"' > "$t/out" 2> "$t/err"
|
|
printf 'bar\n' > "$t/exp"
|
|
same utility-environment "$t/exp"
|
|
|
|
# env(1) EXIT STATUS: "the exit status of env is the exit status of the
|
|
# utility".
|
|
$env -i /bin/sh -c 'exit 7' > "$t/out" 2> "$t/err"
|
|
if [ $? -eq 7 ]; then ok utility-exit-status; else no utility-exit-status; fi
|
|
|
|
# env(1) -u: "removal of the name environment variable if it is in the
|
|
# environment"; ${A-unset} expands to "unset" only if A is gone.
|
|
A=inherited $env -u A /bin/sh -c 'printf "%s\n" "${A-unset}"' \
|
|
> "$t/out" 2> "$t/err"
|
|
printf 'unset\n' > "$t/exp"
|
|
same unset-name "$t/exp"
|
|
|
|
# env(1) EXIT STATUS: 127, "utility could not be found", with a message on
|
|
# standard error.
|
|
$env -i /nonexistent/program > "$t/out" 2> "$t/err"
|
|
st=$?
|
|
if [ "$st" -eq 127 ] && [ -s "$t/err" ]; then
|
|
ok utility-not-found
|
|
else
|
|
no utility-not-found
|
|
fi
|
|
|
|
echo "env: $fails failed"
|
|
[ "$fails" -eq 0 ]
|