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 ea2819be 2023-05-29 op local testroot=`mktemp -d \
26 ea2819be 2023-05-29 op "$GOTD_TEST_ROOT/gotd-test-$testname-XXXXXXXXXX"`
27 6ae16afd 2022-10-31 stsp mkdir $testroot/repo
28 6ae16afd 2022-10-31 stsp git_init $testroot/repo
29 6ae16afd 2022-10-31 stsp if [ -z "$no_tree" ]; then
30 6ae16afd 2022-10-31 stsp make_test_tree $testroot/repo
31 6ae16afd 2022-10-31 stsp (cd $repo && git add .)
32 6ae16afd 2022-10-31 stsp git_commit $testroot/repo -m "adding the test tree"
33 6ae16afd 2022-10-31 stsp fi
34 6ae16afd 2022-10-31 stsp echo "$testroot"
35 6ae16afd 2022-10-31 stsp }
36 6ae16afd 2022-10-31 stsp
37 6ae16afd 2022-10-31 stsp test_done()
38 6ae16afd 2022-10-31 stsp {
39 6ae16afd 2022-10-31 stsp local testroot="$1"
40 6ae16afd 2022-10-31 stsp local result="$2"
41 6ae16afd 2022-10-31 stsp if [ "$result" = "0" ]; then
42 6ae16afd 2022-10-31 stsp test_cleanup "$testroot" || return 1
43 6ae16afd 2022-10-31 stsp if [ -z "$GOT_TEST_QUIET" ]; then
44 6ae16afd 2022-10-31 stsp echo "ok"
45 6ae16afd 2022-10-31 stsp fi
46 6ae16afd 2022-10-31 stsp elif echo "$result" | grep -q "^xfail"; then
47 6ae16afd 2022-10-31 stsp # expected test failure; test reproduces an unfixed bug
48 6ae16afd 2022-10-31 stsp echo "$result"
49 6ae16afd 2022-10-31 stsp test_cleanup "$testroot" || return 1
50 6ae16afd 2022-10-31 stsp else
51 6ae16afd 2022-10-31 stsp echo "test failed; leaving test data in $testroot"
52 6ae16afd 2022-10-31 stsp fi
53 6ae16afd 2022-10-31 stsp }