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 export MALLOC_OPTIONS
=S
37 if [ "$(date -u -r 86400 +%F 2>/dev/null)" != 1970-01-02 ]; then
39 for p
in date gdate
; do
40 if [ "$($p -u -d @86400 +%F 2>/dev/null)" = 1970-01-02 ]; then
45 if [ -z "$DATECMD" ]; then
46 echo "Couldn't find gdate, is GNU coreutils installed?" >&2
53 while getopts r
:u flag
; do
61 command "$DATECMD" $u ${r+-d"@$r"} "$@"
67 git init
-q --object-format=${GOT_TEST_ALGO} "$1"
69 # Switch the default branch to match our test expectations if needed.
70 # Only need to change HEAD since 'git init' did not create any refs.
71 # Relying on implementation details of 'git init' is no problem for us.
72 # We want to be alerted when Git changes fundamental assumptions such
73 # as what an empty repository looks like and where the default branch
74 # is set. In such cases Got's own tooling might well need to change
75 # its behaviour, too, and our tests should fail.
76 # TODO: Update all tests to assume 'main' instead of 'master' and
77 # switch to main here, to match Got's own default.
78 echo "ref: refs/heads/master" > "$1/.git/HEAD"
84 if [ -n "$GOT_TEST_PACK" ]; then
86 if [ "$GOT_TEST_PACK" = "ref-delta" ]; then
90 gotadmin pack
-r "$repo" -a $arg > /dev
/null
91 gotadmin cleanup
-r "$repo" -a -q
99 git
-C $repo commit
--author="$GOT_AUTHOR" -q -a "$@"
100 maybe_pack_repo
$repo
107 git
-C $repo rm -q "$@"
114 git
-C $repo rm -q -r "$@"
120 git
-C $repo show
--no-patch --pretty='format:%H'
123 git_show_branch_head
()
127 git
-C $repo show
--no-patch --pretty='format:%H' $branch
131 git_show_author_time
()
135 git
-C $repo show
--no-patch --pretty='format:%at' $object
138 git_show_tagger_time
()
142 git
-C $repo cat-file tag
$tag |
grep ^tagger | \
143 sed -e "s/^tagger $GOT_AUTHOR//" | cut
-d' ' -f2
146 git_show_parent_commit
()
150 git
-C $repo show
--no-patch --pretty='format:%P' $commit
156 git
-C $repo show
--no-patch --pretty='format:%T'
161 expr "$2" : "\([0-9a-f]\{1,$1\}\)"
167 printf '%s' "${1:-index-out-of-bounds}"
175 git
-C $repo commit-tree
-m "$msg" "$tree"
183 git
-C $repo fsck
--strict \
184 > $testroot/fsck.stdout
2> $testroot/fsck.stderr
186 if [ $ret -ne 0 ]; then
188 cat $testroot/fsck.stderr
189 echo "git fsck failed; leaving test data in $testroot"
200 echo alpha
> $repo/alpha
201 echo beta
> $repo/beta
203 echo delta
> $repo/gamma
/delta
205 echo zeta
> $repo/epsilon
/zeta
208 make_single_file_repo
()
215 echo "this is file $file" > $repo/$file
217 git_commit
$repo -m "initialize $repo with file $file"
220 get_loose_object_path
()
224 local id0
=`trim_obj_id 2 $id`
225 local idrest
=`echo ${id#[0-9a-f][0-9a-f]}`
226 echo "$repo/.git/objects/$id0/$idrest"
235 got tree
-r $repo -i $tree_path |
grep "[0-9a-f] ${filename}$" | \
243 if [ -z "$testname" ]; then
244 echo "No test name provided" >&2
247 local testroot
=`mktemp -d \
248 "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXXXX"`
250 git_init
$testroot/repo
251 if [ -z "$no_tree" ]; then
252 make_test_tree
$testroot/repo
254 git_commit
$testroot/repo
-m "adding the test tree"
256 touch $testroot/repo
/.git
/git-daemon-export-ok
264 git_fsck
$testroot $testroot/repo
266 if [ $ret -ne 0 ]; then
275 while getopts qr
: flag
; do
277 q
) export GOT_TEST_QUIET
=1
279 r
) export GOT_TEST_ROOT
=${OPTARG%/}
281 ?
) echo "Supported options:"
282 echo " -q: quiet mode"
283 echo " -r PATH: use PATH as test data root directory"
288 shift $
(($OPTIND - 1))
289 regress_run_only
="$@"
297 if [ -n "$regress_run_only" ]; then
298 case "$regress_run_only" in
304 if [ "${GOT_TEST_ALGO}" = sha256
-a "$limits" = no-sha256
]; then
308 if [ -z "$GOT_TEST_QUIET" ]; then
318 if [ "$result" = "0" ]; then
319 test_cleanup
"$testroot" ||
return 1
320 if [ -z "$GOT_TEST_QUIET" ]; then
323 elif echo "$result" |
grep -q "^xfail"; then
324 # expected test failure; test reproduces an unfixed bug
326 test_cleanup
"$testroot" ||
return 1
328 echo "test failed; leaving test data in $testroot"