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.
19 export GIT_AUTHOR_NAME
="Flan Hacker"
20 export GIT_AUTHOR_EMAIL
="flan_hacker@openbsd.org"
21 export GIT_COMMITTER_NAME
="$GIT_AUTHOR_NAME"
22 export GIT_COMMITTER_EMAIL
="$GIT_AUTHOR_EMAIL"
23 export GOT_AUTHOR
="$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
24 export GOT_AUTHOR_8
="flan_hac"
25 export GOT_AUTHOR_11
="flan_hacker"
26 export GOT_LOG_DEFAULT_LIMIT
=0
27 export GOT_TEST_ROOT
="/tmp"
28 export GOT_IGNORE_GITCONFIG
=1
29 export GOT_VERSION_STR
=`got --version | cut -d ' ' -f2`
30 export GOT_TEST_HTTP_PORT
=${GOT_TEST_HTTP_PORT:-8080}
31 export GOT_TEST_ALGO
="${GOT_TEST_ALGO:-sha1}"
35 if [ -n "$MEM_CHECK" ] && [ "$MEM_CHECK" -gt 0 ] && [ "$MEM_CHECK" -lt 5 ]; then
36 export MALLOC_OPTIONS
="$MEM_CHECK"S
38 export MALLOC_OPTIONS
=S
41 if [ "$(date -u -r 86400 +%F 2>/dev/null)" != 1970-01-02 ]; then
43 for p
in date gdate
; do
44 if [ "$($p -u -d @86400 +%F 2>/dev/null)" = 1970-01-02 ]; then
49 if [ -z "$DATECMD" ]; then
50 echo "Couldn't find gdate, is GNU coreutils installed?" >&2
57 while getopts r
:u flag
; do
65 command "$DATECMD" $u ${r+-d"@$r"} "$@"
71 git init
-q --object-format=${GOT_TEST_ALGO} "$1"
73 # Switch the default branch to match our test expectations if needed.
74 # Only need to change HEAD since 'git init' did not create any refs.
75 # Relying on implementation details of 'git init' is no problem for us.
76 # We want to be alerted when Git changes fundamental assumptions such
77 # as what an empty repository looks like and where the default branch
78 # is set. In such cases Got's own tooling might well need to change
79 # its behaviour, too, and our tests should fail.
80 # TODO: Update all tests to assume 'main' instead of 'master' and
81 # switch to main here, to match Got's own default.
82 echo "ref: refs/heads/master" > "$1/.git/HEAD"
88 if [ -n "$GOT_TEST_PACK" ]; then
90 if [ "$GOT_TEST_PACK" = "ref-delta" ]; then
94 gotadmin pack
-r "$repo" -a $arg > /dev
/null
95 gotadmin cleanup
-r "$repo" -a -q
103 git
-C $repo commit
--author="$GOT_AUTHOR" -q -a "$@"
104 maybe_pack_repo
$repo
111 git
-C $repo rm -q "$@"
118 git
-C $repo rm -q -r "$@"
124 git
-C $repo show
--no-patch --pretty='format:%H'
127 git_show_branch_head
()
131 git
-C $repo show
--no-patch --pretty='format:%H' $branch
135 git_show_author_time
()
139 git
-C $repo show
--no-patch --pretty='format:%at' $object
142 git_show_tagger_time
()
146 git
-C $repo cat-file tag
$tag |
grep ^tagger | \
147 sed -e "s/^tagger $GOT_AUTHOR//" | cut
-d' ' -f2
150 git_show_parent_commit
()
154 git
-C $repo show
--no-patch --pretty='format:%P' $commit
160 git
-C $repo show
--no-patch --pretty='format:%T'
165 expr "$2" : "\([0-9a-f]\{1,$1\}\)"
171 printf '%s' "${1:-index-out-of-bounds}"
179 git
-C $repo commit-tree
-m "$msg" "$tree"
187 git
-C $repo fsck
--strict \
188 > $testroot/fsck.stdout
2> $testroot/fsck.stderr
190 if [ $ret -ne 0 ]; then
192 cat $testroot/fsck.stderr
193 echo "git fsck failed; leaving test data in $testroot"
204 echo alpha
> $repo/alpha
205 echo beta
> $repo/beta
207 echo delta
> $repo/gamma
/delta
209 echo zeta
> $repo/epsilon
/zeta
212 make_single_file_repo
()
219 echo "this is file $file" > $repo/$file
221 git_commit
$repo -m "initialize $repo with file $file"
224 get_loose_object_path
()
228 local id0
=`trim_obj_id 2 $id`
229 local idrest
=`echo ${id#[0-9a-f][0-9a-f]}`
230 echo "$repo/.git/objects/$id0/$idrest"
239 got tree
-r $repo -i $tree_path |
grep "[0-9a-f] ${filename}$" | \
247 if [ -z "$testname" ]; then
248 echo "No test name provided" >&2
251 local testroot
=`mktemp -d \
252 "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
254 git_init
$testroot/repo
255 if [ -z "$no_tree" ]; then
256 make_test_tree
$testroot/repo
258 git_commit
$testroot/repo
-m "adding the test tree"
260 touch $testroot/repo
/.git
/git-daemon-export-ok
268 git_fsck
$testroot $testroot/repo
270 if [ $ret -ne 0 ]; then
279 while getopts qr
: flag
; do
281 q
) export GOT_TEST_QUIET
=1
283 r
) export GOT_TEST_ROOT
=${OPTARG%/}
285 ?
) echo "Supported options:"
286 echo " -q: quiet mode"
287 echo " -r PATH: use PATH as test data root directory"
292 shift $
(($OPTIND - 1))
293 regress_run_only
="$@"
301 if [ -n "$regress_run_only" ]; then
302 case "$regress_run_only" in
308 if [ "${GOT_TEST_ALGO}" = sha256
-a "$limits" = no-sha256
]; then
312 if [ -z "$GOT_TEST_QUIET" ]; then
322 if [ "$result" = "0" ]; then
323 test_cleanup
"$testroot" ||
return 1
324 if [ -z "$GOT_TEST_QUIET" ]; then
327 elif echo "$result" |
grep -q "^xfail"; then
328 # expected test failure; test reproduces an unfixed bug
330 test_cleanup
"$testroot" ||
return 1
332 echo "test failed; leaving test data in $testroot"
341 kdump
-u malloc
-f $testroot/ktrace.out
> $testroot/leak-report
342 if egrep -q "( got 0x|/bin/got-)" $testroot/leak-report
; then
343 cat $testroot/leak-report
347 test_done
"$testroot" "$result"
355 echo "Testroot not passed"
359 if [ ! -d "$testroot" ]; then
360 echo "Directory does not exist"
364 echo "ktrace -d -tu -i -f $testroot/ktrace.out"