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`
33 export MALLOC_OPTIONS
=S
35 # Check to see if PLATFORM has a value. PLATFORM is populated when running
36 # via `./configure && make` but this isn't guaranteed if an individual test is
37 # run directly, such as `regress/cmdline/tag.sh`. In such cases, PLATFORM
38 # will be empty, but we still want to use it. Since we test for non-linux
39 # values, only set PLATFORM if we're running on Linu so that the correct
41 [ -z "$PLATFORM" -a "$(uname)" = "Linux" ] && PLATFORM
="linux"
43 if [ "$(date -u -r 86400 +%F 2>/dev/null)" != 1970-01-02 ]; then
45 for p
in date gdate
; do
46 if [ "$($p -u -d @86400 +%F 2>/dev/null)" = 1970-01-02 ]; then
51 if [ -z "$DATECMD" ]; then
52 echo "Couldn't find gdate, is GNU coreutils installed?" >&2
59 while getopts r
:u flag
; do
67 command "$DATECMD" $u ${r+-d"@$r"} "$@"
75 # On non-linux systems, the sed command can happily accept "-i ''" as
76 # a valid command to not save backup files for in-place edits.
77 # However, on linux, "-i ''" would be treated as "-i" with a blank
78 # argument, and hence, no file to edit in-place, which is an error.
80 # Therefore, scan the argument list and remove "-i ''", replacing it
83 [ "$PLATFORM" = "linux" ] && {
91 [ "$seen" = "1" -a -z "$w" ] && {
95 command "$SEDCMD" -i "$@"
100 command "$SEDCMD" "$@"
108 # Switch the default branch to match our test expectations if needed.
109 # Only need to change HEAD since 'git init' did not create any refs.
110 # Relying on implementation details of 'git init' is no problem for us.
111 # We want to be alerted when Git changes fundamental assumptions such
112 # as what an empty repository looks like and where the default branch
113 # is set. In such cases Got's own tooling might well need to change
114 # its behaviour, too, and our tests should fail.
115 # TODO: Update all tests to assume 'main' instead of 'master' and
116 # switch to main here, to match Got's own default.
117 echo "ref: refs/heads/master" > "$1/.git/HEAD"
123 if [ -n "$GOT_TEST_PACK" ]; then
125 if [ "$GOT_TEST_PACK" = "ref-delta" ]; then
129 (cd $repo && gotadmin pack
-a $arg > /dev
/null
)
130 (cd $repo && gotadmin cleanup
-a -q)
138 (cd $repo && git commit
--author="$GOT_AUTHOR" -q -a "$@")
139 maybe_pack_repo
$repo
146 (cd $repo && git
rm -q "$@")
152 (cd $repo && git show
--no-patch --pretty='format:%H')
155 git_show_branch_head
()
159 (cd $repo && git show
--no-patch --pretty='format:%H' $branch)
163 git_show_author_time
()
167 (cd $repo && git show
--no-patch --pretty='format:%at' $object)
170 git_show_tagger_time
()
174 (cd $repo && git cat-file tag
$tag |
grep ^tagger | \
175 sed -e "s/^tagger $GOT_AUTHOR//" | cut
-d' ' -f2)
178 git_show_parent_commit
()
182 (cd $repo && git show
--no-patch --pretty='format:%P' $commit)
188 (cd $repo && git show
--no-patch --pretty='format:%T')
197 while [ "$trimcount" -gt 0 ]; do
199 trimcount
=$
((trimcount
- 1))
210 (cd $repo && git commit-tree
-m "$msg" "$tree")
218 (cd $repo && git fsck
--strict \
219 > $testroot/fsck.stdout
2> $testroot/fsck.stderr
)
221 if [ $ret -ne 0 ]; then
223 cat $testroot/fsck.stderr
224 echo "git fsck failed; leaving test data in $testroot"
235 echo alpha
> $repo/alpha
236 echo beta
> $repo/beta
238 echo delta
> $repo/gamma
/delta
240 echo zeta
> $repo/epsilon
/zeta
243 make_single_file_repo
()
250 echo "this is file $file" > $repo/$file
251 (cd $repo && git add .
)
252 git_commit
$repo -m "intialize $repo with file $file"
255 get_loose_object_path
()
259 local id0
=`trim_obj_id 38 $id`
260 local idrest
=`echo ${id#[0-9a-f][0-9a-f]}`
261 echo "$repo/.git/objects/$id0/$idrest"
270 got tree
-r $repo -i $tree_path |
grep "[0-9a-f] ${filename}$" | \
278 if [ -z "$testname" ]; then
279 echo "No test name provided" >&2
282 local testroot
=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
284 git_init
$testroot/repo
285 if [ -z "$no_tree" ]; then
286 make_test_tree
$testroot/repo
287 (cd $repo && git add .
)
288 git_commit
$testroot/repo
-m "adding the test tree"
290 touch $testroot/repo
/.git
/git-daemon-export-ok
298 git_fsck
$testroot $testroot/repo
300 if [ $ret -ne 0 ]; then
309 while getopts qr
: flag
; do
311 q
) export GOT_TEST_QUIET
=1
313 r
) export GOT_TEST_ROOT
=${OPTARG%/}
315 ?
) echo "Supported options:"
316 echo " -q: quiet mode"
317 echo " -r PATH: use PATH as test data root directory"
322 shift $
(($OPTIND - 1))
323 regress_run_only
="$@"
330 if [ -n "$regress_run_only" ]; then
331 case "$regress_run_only" in
337 if [ -z "$GOT_TEST_QUIET" ]; then
347 if [ "$result" = "0" ]; then
348 test_cleanup
"$testroot" ||
return 1
349 if [ -z "$GOT_TEST_QUIET" ]; then
352 elif echo "$result" |
grep -q "^xfail"; then
353 # expected test failure; test reproduces an unfixed bug
355 test_cleanup
"$testroot" ||
return 1
357 echo "test failed; leaving test data in $testroot"