Blame


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