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 function git_init
18 {
19 git init -q "$@"
20 }
22 function git_commit
23 {
24 local repo="$1"
25 shift
26 (cd $repo && git commit -q -a "$@")
27 }
29 function git_rm
30 {
31 local repo="$1"
32 shift
33 (cd $repo && git rm -q "$@")
34 }
36 function git_show_head
37 {
38 local repo="$1"
39 (cd $repo && git show --no-patch --pretty='format:%H')
40 }
42 function make_test_tree
43 {
44 repo="$1"
46 echo alpha > $repo/alpha
47 echo beta > $repo/beta
48 mkdir $repo/gamma
49 echo delta > $repo/gamma/delta
50 mkdir $repo/epsilon
51 echo zeta > $repo/epsilon/zeta
52 (cd $repo && git add .)
53 }
55 function test_init
56 {
57 local testname="$1"
58 local no_tree="$2"
59 if [ -z "$testname" ]; then
60 echo "No test name provided" >&2
61 return 1
62 fi
63 local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
64 mkdir $testroot/repo
65 git_init $testroot/repo
66 if [ -z "$no_tree" ]; then
67 make_test_tree $testroot/repo
68 git_commit $testroot/repo -m "adding the test tree"
69 fi
70 echo "$testroot"
71 }
73 function test_cleanup
74 {
75 local testroot="$1"
76 rm -rf "$testroot"
77 }
79 function run_test
80 {
81 testfunc="$1"
82 echo -n "$testfunc "
83 $testfunc
84 }
86 function test_done
87 {
88 local testroot="$1"
89 local result="$2"
90 if [ "$result" == "0" ]; then
91 test_cleanup "$testroot"
92 echo "ok"
93 else
94 echo "test failed; leaving test data in $testroot"
95 fi
96 }