3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
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.
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 export GIT_AUTHOR_NAME="Flan Hacker"
18 export GIT_AUTHOR_EMAIL="flan_hacker@openbsd.org"
19 export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
20 export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
21 export GOT_AUTHOR="$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
22 export GOT_AUTHOR_8="flan_hac"
23 export GOT_AUTHOR_11="flan_hacker"
24 export GOT_LOG_DEFAULT_LIMIT=0
25 export GOT_TEST_ROOT="/tmp"
27 export MALLOC_OPTIONS=S
37 if [ -n "$GOT_TEST_PACK" ]; then
38 (cd $repo && git repack -a -q)
46 (cd $repo && git commit --author="$GOT_AUTHOR" -q -a "$@")
54 (cd $repo && git rm -q "$@")
60 (cd $repo && git show --no-patch --pretty='format:%H')
63 git_show_branch_head()
67 (cd $repo && git show --no-patch --pretty='format:%H' $branch)
71 git_show_author_time()
75 (cd $repo && git show --no-patch --pretty='format:%at' $object)
78 git_show_tagger_time()
82 (cd $repo && git cat-file tag $tag | grep ^tagger | \
83 sed -e "s/^tagger $GOT_AUTHOR//" | cut -d' ' -f2)
86 git_show_parent_commit()
90 (cd $repo && git show --no-patch --pretty='format:%P' $commit)
96 (cd $repo && git show --no-patch --pretty='format:%T')
105 while [ "$trimcount" -gt 0 ]; do
107 trimcount=$((trimcount - 1))
118 (cd $repo && git commit-tree -m "$msg" "$tree")
119 maybe_pack_repo $repo
127 (cd $repo && git fsck --strict \
128 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
130 if [ "$ret" != "0" ]; then
132 cat $testroot/fsck.stderr
133 echo "git fsck failed; leaving test data in $testroot"
144 echo alpha > $repo/alpha
145 echo beta > $repo/beta
147 echo delta > $repo/gamma/delta
149 echo zeta > $repo/epsilon/zeta
152 make_single_file_repo()
159 echo "this is file $file" > $repo/$file
160 (cd $repo && git add .)
161 git_commit $repo -m "intialize $repo with file $file"
164 get_loose_object_path()
168 local id0=`trim_obj_id 38 $id`
169 local idrest=`echo ${id#[0-9a-f][0-9a-f]}`
170 echo "$repo/.git/objects/$id0/$idrest"
179 got tree -r $repo -i $tree_path | grep "[0-9a-f] ${filename}$" | \
187 if [ -z "$testname" ]; then
188 echo "No test name provided" >&2
191 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
193 git_init $testroot/repo
194 if [ -z "$no_tree" ]; then
195 make_test_tree $testroot/repo
196 (cd $repo && git add .)
197 git_commit $testroot/repo -m "adding the test tree"
199 touch $testroot/repo/.git/git-daemon-export-ok
207 git_fsck $testroot $testroot/repo
209 if [ "$ret" != "0" ]; then
218 while getopts qr: flag; do
220 q) export GOT_TEST_QUIET=1
222 r) export GOT_TEST_ROOT=$OPTARG
224 ?) echo "Supported options:"
225 echo " -q: quiet mode"
226 echo " -r PATH: use PATH as test data root directory"
236 if [ -z "$GOT_TEST_QUIET" ]; then
246 if [ "$result" = "0" ]; then
247 test_cleanup "$testroot" || return 1
248 if [ -z "$GOT_TEST_QUIET" ]; then
251 elif echo "$result" | grep -q "^xfail"; then
252 # expected test failure; test reproduces an unfixed bug
254 test_cleanup "$testroot" || return 1
256 echo "test failed; leaving test data in $testroot"