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 if [ "$(date -u -r 86400 +%F 2>/dev/null)" != 1970-01-02 ]; then
37 for p in date gdate; do
38 if [ "$($p -u -d @86400 +%F 2>/dev/null)" = 1970-01-02 ]; then
43 if [ -z "$DATECMD" ]; then
44 echo "Couldn't find gdate, is GNU coreutils installed?" >&2
51 while getopts r:u flag; do
59 command "$DATECMD" $u ${r+-d"@$r"} "$@"
67 # Switch the default branch to match our test expectations if needed.
68 # Only need to change HEAD since 'git init' did not create any refs.
69 # Relying on implementation details of 'git init' is no problem for us.
70 # We want to be alerted when Git changes fundamental assumptions such
71 # as what an empty repository looks like and where the default branch
72 # is set. In such cases Got's own tooling might well need to change
73 # its behaviour, too, and our tests should fail.
74 # TODO: Update all tests to assume 'main' instead of 'master' and
75 # switch to main here, to match Got's own default.
76 echo "ref: refs/heads/master" > "$1/.git/HEAD"
82 if [ -n "$GOT_TEST_PACK" ]; then
84 if [ "$GOT_TEST_PACK" = "ref-delta" ]; then
88 (cd $repo && gotadmin pack -a $arg > /dev/null)
89 (cd $repo && gotadmin cleanup -a -q)
97 (cd $repo && git commit --author="$GOT_AUTHOR" -q -a "$@")
105 (cd $repo && git rm -q "$@")
111 (cd $repo && git show --no-patch --pretty='format:%H')
114 git_show_branch_head()
118 (cd $repo && git show --no-patch --pretty='format:%H' $branch)
122 git_show_author_time()
126 (cd $repo && git show --no-patch --pretty='format:%at' $object)
129 git_show_tagger_time()
133 (cd $repo && git cat-file tag $tag | grep ^tagger | \
134 sed -e "s/^tagger $GOT_AUTHOR//" | cut -d' ' -f2)
137 git_show_parent_commit()
141 (cd $repo && git show --no-patch --pretty='format:%P' $commit)
147 (cd $repo && git show --no-patch --pretty='format:%T')
156 while [ "$trimcount" -gt 0 ]; do
158 trimcount=$((trimcount - 1))
169 (cd $repo && git commit-tree -m "$msg" "$tree")
177 (cd $repo && git fsck --strict \
178 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
180 if [ $ret -ne 0 ]; then
182 cat $testroot/fsck.stderr
183 echo "git fsck failed; leaving test data in $testroot"
194 echo alpha > $repo/alpha
195 echo beta > $repo/beta
197 echo delta > $repo/gamma/delta
199 echo zeta > $repo/epsilon/zeta
202 make_single_file_repo()
209 echo "this is file $file" > $repo/$file
210 (cd $repo && git add .)
211 git_commit $repo -m "intialize $repo with file $file"
214 get_loose_object_path()
218 local id0=`trim_obj_id 38 $id`
219 local idrest=`echo ${id#[0-9a-f][0-9a-f]}`
220 echo "$repo/.git/objects/$id0/$idrest"
229 got tree -r $repo -i $tree_path | grep "[0-9a-f] ${filename}$" | \
237 if [ -z "$testname" ]; then
238 echo "No test name provided" >&2
241 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
243 git_init $testroot/repo
244 if [ -z "$no_tree" ]; then
245 make_test_tree $testroot/repo
246 (cd $repo && git add .)
247 git_commit $testroot/repo -m "adding the test tree"
249 touch $testroot/repo/.git/git-daemon-export-ok
257 git_fsck $testroot $testroot/repo
259 if [ $ret -ne 0 ]; then
268 while getopts qr: flag; do
270 q) export GOT_TEST_QUIET=1
272 r) export GOT_TEST_ROOT=${OPTARG%/}
274 ?) echo "Supported options:"
275 echo " -q: quiet mode"
276 echo " -r PATH: use PATH as test data root directory"
281 shift $(($OPTIND - 1))
282 regress_run_only="$@"
289 if [ -n "$regress_run_only" ]; then
290 case "$regress_run_only" in
296 if [ -z "$GOT_TEST_QUIET" ]; then
306 if [ "$result" = "0" ]; then
307 test_cleanup "$testroot" || return 1
308 if [ -z "$GOT_TEST_QUIET" ]; then
311 elif echo "$result" | grep -q "^xfail"; then
312 # expected test failure; test reproduces an unfixed bug
314 test_cleanup "$testroot" || return 1
316 echo "test failed; leaving test data in $testroot"