Blame


1 f2900386 2022-10-31 thomas #!/bin/sh
2 f2900386 2022-10-31 thomas #
3 f2900386 2022-10-31 thomas # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 f2900386 2022-10-31 thomas #
5 f2900386 2022-10-31 thomas # Permission to use, copy, modify, and distribute this software for any
6 f2900386 2022-10-31 thomas # purpose with or without fee is hereby granted, provided that the above
7 f2900386 2022-10-31 thomas # copyright notice and this permission notice appear in all copies.
8 f2900386 2022-10-31 thomas #
9 f2900386 2022-10-31 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 f2900386 2022-10-31 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 f2900386 2022-10-31 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 f2900386 2022-10-31 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 f2900386 2022-10-31 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 f2900386 2022-10-31 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 f2900386 2022-10-31 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 f2900386 2022-10-31 thomas
17 f2900386 2022-10-31 thomas test_init()
18 f2900386 2022-10-31 thomas {
19 f2900386 2022-10-31 thomas local testname="$1"
20 f2900386 2022-10-31 thomas local no_tree="$2"
21 f2900386 2022-10-31 thomas if [ -z "$testname" ]; then
22 f2900386 2022-10-31 thomas echo "No test name provided" >&2
23 f2900386 2022-10-31 thomas return 1
24 f2900386 2022-10-31 thomas fi
25 f2900386 2022-10-31 thomas local testroot=`mktemp -d "$GOTD_TEST_ROOT/gotd-test-$testname-XXXXXXXX"`
26 f2900386 2022-10-31 thomas mkdir $testroot/repo
27 f2900386 2022-10-31 thomas git_init $testroot/repo
28 f2900386 2022-10-31 thomas if [ -z "$no_tree" ]; then
29 f2900386 2022-10-31 thomas make_test_tree $testroot/repo
30 f2900386 2022-10-31 thomas (cd $repo && git add .)
31 f2900386 2022-10-31 thomas git_commit $testroot/repo -m "adding the test tree"
32 f2900386 2022-10-31 thomas fi
33 f2900386 2022-10-31 thomas echo "$testroot"
34 f2900386 2022-10-31 thomas }
35 f2900386 2022-10-31 thomas
36 f2900386 2022-10-31 thomas test_done()
37 f2900386 2022-10-31 thomas {
38 f2900386 2022-10-31 thomas local testroot="$1"
39 f2900386 2022-10-31 thomas local result="$2"
40 f2900386 2022-10-31 thomas if [ "$result" = "0" ]; then
41 f2900386 2022-10-31 thomas test_cleanup "$testroot" || return 1
42 f2900386 2022-10-31 thomas if [ -z "$GOT_TEST_QUIET" ]; then
43 f2900386 2022-10-31 thomas echo "ok"
44 f2900386 2022-10-31 thomas fi
45 f2900386 2022-10-31 thomas elif echo "$result" | grep -q "^xfail"; then
46 f2900386 2022-10-31 thomas # expected test failure; test reproduces an unfixed bug
47 f2900386 2022-10-31 thomas echo "$result"
48 f2900386 2022-10-31 thomas test_cleanup "$testroot" || return 1
49 f2900386 2022-10-31 thomas else
50 f2900386 2022-10-31 thomas echo "test failed; leaving test data in $testroot"
51 f2900386 2022-10-31 thomas fi
52 f2900386 2022-10-31 thomas }