mirror of
https://github.com/baketnk/frame-yap.git
synced 2026-10-06 08:00:05 +02:00
41 lines
1.5 KiB
Bash
41 lines
1.5 KiB
Bash
#!/bin/sh
|
|
# Offline, hardware-free contract test using a restricted PATH of fake host tools.
|
|
set -eu
|
|
script=$1
|
|
tmp=$(/bin/mktemp -d)
|
|
trap '/bin/rm -rf "$tmp"' EXIT HUP INT TERM
|
|
/bin/mkdir "$tmp/bin"
|
|
for dep in curl tar sha256sum mktemp mkdir mv; do
|
|
printf '#!/bin/sh\nexit 0\n' > "$tmp/bin/$dep"
|
|
/bin/chmod +x "$tmp/bin/$dep"
|
|
done
|
|
printf '#!/bin/sh\ncase "$1" in -s) printf "%%s\\n" "${MOCK_OS:-Linux}" ;; -m) printf "%%s\\n" "${MOCK_ARCH:-aarch64}" ;; esac\n' > "$tmp/bin/uname"
|
|
printf '#!/bin/sh\nprintf "%%s\\n" "${MOCK_LIBC:-glibc 2.39}"\n' > "$tmp/bin/getconf"
|
|
printf '#!/bin/sh\nprintf "%%s\\n" "${MOCK_PYTHON:-Python 3.12.3}"\n' > "$tmp/bin/python3"
|
|
/bin/chmod +x "$tmp/bin/uname" "$tmp/bin/getconf" "$tmp/bin/python3"
|
|
|
|
check() {
|
|
expected=$1
|
|
needle=$2
|
|
shift 2
|
|
status=0
|
|
output=$(PATH="$tmp/bin" "$@" /bin/sh "$script" 2>&1) || status=$?
|
|
if [ "$status" -ne "$expected" ]; then
|
|
printf 'Expected exit %s, got %s: %s\n' "$expected" "$status" "$output" >&2
|
|
exit 1
|
|
fi
|
|
case "$output" in
|
|
*"$needle"*) ;;
|
|
*) printf 'Missing expected text %s: %s\n' "$needle" "$output" >&2; exit 1 ;;
|
|
esac
|
|
}
|
|
|
|
check 0 'Git: missing (not required' /usr/bin/env
|
|
check 0 'uv: missing (not required' /usr/bin/env
|
|
check 0 'Preflight passed' /usr/bin/env
|
|
check 0 'older than 3.12' /usr/bin/env MOCK_PYTHON='Python 3.11.9'
|
|
check 1 'Linux AArch64 only' /usr/bin/env MOCK_ARCH=x86_64
|
|
check 1 'require glibc' /usr/bin/env MOCK_LIBC=musl
|
|
/bin/rm "$tmp/bin/curl"
|
|
check 1 'curl MISSING' /usr/bin/env
|