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 if [ -z "$testname" ]; then
59 echo "No test name provided" >&2
60 return 1
61 fi
62 local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
63 mkdir $testroot/repo
64 git_init $testroot/repo
65 make_test_tree $testroot/repo
66 git_commit $testroot/repo -m "adding the test tree"
67 echo "$testroot"
68 }
70 function test_cleanup
71 {
72 local testroot="$1"
73 rm -rf "$testroot"
74 }
76 function run_test
77 {
78 testfunc="$1"
79 echo -n "$testfunc "
80 $testfunc
81 }
83 function test_done
84 {
85 local testroot="$1"
86 local result="$2"
87 if [ "$result" == "0" ]; then
88 test_cleanup "$testroot"
89 echo "ok"
90 else
91 echo "test failed; leaving test data in $testroot"
92 fi
93 }