-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_shell.sh
More file actions
50 lines (44 loc) · 1.5 KB
/
test_shell.sh
File metadata and controls
50 lines (44 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
# SPDX-FileCopyrightText: 2026 Alexandre Gomes Gaigalas <alganet@gmail.com>
#
# SPDX-License-Identifier: ISC
set -euf
ROOT_DIR="$(cd "$(/bin/dirname "$0")" && /bin/pwd)"
TEST_LIST="$(/bin/find "${ROOT_DIR}/tests" -name '*vars.env' | /bin/sort)"
TEST_COUNT="$(echo "$TEST_LIST" | /bin/wc -l)"
TEST_SHELL="${TEST_SHELL:-${SHELL:-/bin/sh}}"
test_shell () {
RUN_COUNT=0
PASS_COUNT=0
SKIP_COUNT=0
echo "1..${TEST_COUNT}"
while read -r TEST_ENV
do
RUN_COUNT=$((RUN_COUNT + 1))
. "${TEST_ENV}"
cd "$ROOT_DIR"
case "$TEST_SHELL" in
# yash has some weird behavior that makes builtins unavailable if
# they don't exist in the PATH, so we need to set it for true, test, printf
# etc even though the internal builtin version is used anyway. Annoying.
*yash*)
/bin/env -i PATH=/bin $TEST_SHELL "$TEST_FILE" > "${TEST_OUTPUT}" 2>&1 || true
;;
*)
/bin/env -i PATH= $TEST_SHELL "$TEST_FILE" > "${TEST_OUTPUT}" 2>&1 || true
;;
esac
if /bin/diff -u "${TEST_EXPECTED}" "${TEST_OUTPUT}"
then
printf 'ok'
PASS_COUNT=$((PASS_COUNT + 1))
else
printf 'not ok'
fi
echo \ $RUN_COUNT - $TEST_FILE \| $TEST_DOC_FILE:$TEST_DOC_EXAMPLE_LINE \| $TEST_NAME
done
if ! test $(($PASS_COUNT + SKIP_COUNT)) -eq "$TEST_COUNT"
then exit 1
fi
}
echo "$TEST_LIST" | test_shell