avoid needless use of STAILQ_FOREACH_SAFE, we are not removing elements here
[got-portable.git] / regress / gotwebd / common.sh
blobc118a771e44baf296871ddcfcbb3575f70c9fb82
1 #!/bin/sh
3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
4 # Copyright (c) 2024 Mark Jamsek <mark@jamsek.dev>
6 # Permission to use, copy, modify, and distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 . ${GOTWEBD_TEST_DATA_DIR}/../cmdline/common.sh
20 interpolate()
22 perl -p -e \
23 's/\$\{(\w+)\}/(exists $ENV{$1} ? $ENV{$1} : "UNDEFINED $1")/eg' \
24 < "$1"
27 test_cleanup()
29 local testroot="$1"
30 local repo="$2"
32 if [ -n "$repo" ]; then
33 git_fsck $testroot $repo
34 ret=$?
35 if [ $ret -ne 0 ]; then
36 return $ret
40 rm -rf "$testroot"
43 test_done()
45 local testroot="$1"
46 local repo="$2"
47 local result="$3"
49 if [ "$result" = "0" ]; then
50 test_cleanup "$testroot" "$repo" || return 1
51 if [ -z "$GOT_TEST_QUIET" ]; then
52 echo "ok"
54 elif echo "$result" | grep -q "^xfail"; then
55 # expected test failure; test reproduces an unfixed bug
56 echo "$result"
57 test_cleanup "$testroot" "$repo" || return 1
58 else
59 echo "test failed; leaving test data in $testroot"
63 test_init()
65 local testname="$1"
66 local no_repo="$2"
68 if [ -z "$testname" ]; then
69 echo "No test name provided" >&2
70 return 1
73 local testroot=$(mktemp -d \
74 "$GOTWEBD_TEST_ROOT/gotwebd-test-$testname-XXXXXXXXXX")
76 if [ -z "$no_repo" ]; then
77 mkdir $testroot/repo
78 git_init $testroot/repo
79 make_test_tree $testroot/repo
80 git -C $repo add .
81 git_commit $testroot/repo -m "adding the test tree"
84 echo "$testroot"
87 run_test()
89 testfunc="$1"
91 if [ -n "$regress_run_only" ]; then
92 case "$regress_run_only" in
93 *$testfunc*) ;;
94 *) return ;;
95 esac
98 if [ -z "$GOT_TEST_QUIET" ]; then
99 echo -n "$testfunc "
102 $testfunc