Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 name=$(getent passwd $USER | cut -d: -f5)
18 export GOT_AUTHOR="$name <$(whoami)@$(hostname)>"
20 export MALLOC_OPTIONS=S
22 function git_init
23 {
24 git init -q "$@"
25 }
27 function git_commit
28 {
29 local repo="$1"
30 shift
31 (cd $repo && git commit -q -a "$@")
32 }
34 function git_rm
35 {
36 local repo="$1"
37 shift
38 (cd $repo && git rm -q "$@")
39 }
41 function git_show_head
42 {
43 local repo="$1"
44 (cd $repo && git show --no-patch --pretty='format:%H')
45 }
47 function git_show_tree
48 {
49 local repo="$1"
50 (cd $repo && git show --no-patch --pretty='format:%T')
51 }
53 function git_commit_tree
54 {
55 local repo="$1"
56 local msg="$2"
57 local tree="$3"
58 (cd $repo && git commit-tree -m "$msg" "$tree")
59 }
61 function make_test_tree
62 {
63 repo="$1"
65 echo alpha > $repo/alpha
66 echo beta > $repo/beta
67 mkdir $repo/gamma
68 echo delta > $repo/gamma/delta
69 mkdir $repo/epsilon
70 echo zeta > $repo/epsilon/zeta
71 (cd $repo && git add .)
72 }
74 function test_init
75 {
76 local testname="$1"
77 local no_tree="$2"
78 if [ -z "$testname" ]; then
79 echo "No test name provided" >&2
80 return 1
81 fi
82 local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
83 mkdir $testroot/repo
84 git_init $testroot/repo
85 if [ -z "$no_tree" ]; then
86 make_test_tree $testroot/repo
87 git_commit $testroot/repo -m "adding the test tree"
88 fi
89 echo "$testroot"
90 }
92 function test_cleanup
93 {
94 local testroot="$1"
95 rm -rf "$testroot"
96 }
98 function run_test
99 {
100 testfunc="$1"
101 echo -n "$testfunc "
102 $testfunc
105 function test_done
107 local testroot="$1"
108 local result="$2"
109 if [ "$result" == "0" ]; then
110 test_cleanup "$testroot"
111 echo "ok"
112 elif echo "$result" | grep -q "^xfail"; then
113 # expected test failure; test reproduces an unfixed bug
114 test_cleanup "$testroot"
115 echo "$result"
116 else
117 echo "test failed; leaving test data in $testroot"
118 fi