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 [ "$(date -u -r 86400 +%F 2>/dev/null)" = 1970-01-02 ] || date()
46 [ "$PLATFORM" != "linux" ] && {
47 command -v "gdate" >/dev/null 2>&1 && {
50 echo "Couldn't find gdate is GNU coreutils installed?"
55 while getopts r:u flag; do
63 command "$DATECMD" $u ${r+-d"@$r"} "$@"
70 # On non-linux systems, the sed command can happily accept "-i ''" as
71 # a valid command to not save backup files for in-place edits.
72 # However, on linux, "-i ''" would be treated as "-i" with a blank
73 # argument, and hence, no file to edit in-place, which is an error.
75 # Therefore, scan the argument list and remove "-i ''", replacing it
78 [ "$PLATFORM" = "linux" ] && {
86 [ "$seen" = "1" -a -z "$w" ] && {
90 command "$SEDCMD" -i "$@"
95 command "$SEDCMD" "$@"
103 # Switch the default branch to match our test expectations if needed.
104 # Only need to change HEAD since 'git init' did not create any refs.
105 # Relying on implementation details of 'git init' is no problem for us.
106 # We want to be alerted when Git changes fundamental assumptions such
107 # as what an empty repository looks like and where the default branch
108 # is set. In such cases Got's own tooling might well need to change
109 # its behaviour, too, and our tests should fail.
110 # TODO: Update all tests to assume 'main' instead of 'master' and
111 # switch to main here, to match Got's own default.
112 echo "ref: refs/heads/master" > "$1/.git/HEAD"
118 if [ -n "$GOT_TEST_PACK" ]; then
120 if [ "$GOT_TEST_PACK" = "ref-delta" ]; then
124 (cd $repo && gotadmin pack -a $arg > /dev/null)
125 (cd $repo && gotadmin cleanup -a -q)
133 (cd $repo && git commit --author="$GOT_AUTHOR" -q -a "$@")
134 maybe_pack_repo $repo
141 (cd $repo && git rm -q "$@")
147 (cd $repo && git show --no-patch --pretty='format:%H')
150 git_show_branch_head()
154 (cd $repo && git show --no-patch --pretty='format:%H' $branch)
158 git_show_author_time()
162 (cd $repo && git show --no-patch --pretty='format:%at' $object)
165 git_show_tagger_time()
169 (cd $repo && git cat-file tag $tag | grep ^tagger | \
170 sed -e "s/^tagger $GOT_AUTHOR//" | cut -d' ' -f2)
173 git_show_parent_commit()
177 (cd $repo && git show --no-patch --pretty='format:%P' $commit)
183 (cd $repo && git show --no-patch --pretty='format:%T')
192 while [ "$trimcount" -gt 0 ]; do
194 trimcount=$((trimcount - 1))
205 (cd $repo && git commit-tree -m "$msg" "$tree")
213 (cd $repo && git fsck --strict \
214 > $testroot/fsck.stdout 2> $testroot/fsck.stderr)
216 if [ $ret -ne 0 ]; then
218 cat $testroot/fsck.stderr
219 echo "git fsck failed; leaving test data in $testroot"
230 echo alpha > $repo/alpha
231 echo beta > $repo/beta
233 echo delta > $repo/gamma/delta
235 echo zeta > $repo/epsilon/zeta
238 make_single_file_repo()
245 echo "this is file $file" > $repo/$file
246 (cd $repo && git add .)
247 git_commit $repo -m "intialize $repo with file $file"
250 get_loose_object_path()
254 local id0=`trim_obj_id 38 $id`
255 local idrest=`echo ${id#[0-9a-f][0-9a-f]}`
256 echo "$repo/.git/objects/$id0/$idrest"
265 got tree -r $repo -i $tree_path | grep "[0-9a-f] ${filename}$" | \
273 if [ -z "$testname" ]; then
274 echo "No test name provided" >&2
277 local testroot=`mktemp -d "$GOT_TEST_ROOT/got-test-$testname-XXXXXXXX"`
279 git_init $testroot/repo
280 if [ -z "$no_tree" ]; then
281 make_test_tree $testroot/repo
282 (cd $repo && git add .)
283 git_commit $testroot/repo -m "adding the test tree"
285 touch $testroot/repo/.git/git-daemon-export-ok
293 git_fsck $testroot $testroot/repo
295 if [ $ret -ne 0 ]; then
304 while getopts qr: flag; do
306 q) export GOT_TEST_QUIET=1
308 r) export GOT_TEST_ROOT=${OPTARG%/}
310 ?) echo "Supported options:"
311 echo " -q: quiet mode"
312 echo " -r PATH: use PATH as test data root directory"
317 shift $(($OPTIND - 1))
318 regress_run_only="$@"
325 if [ -n "$regress_run_only" ]; then
326 case "$regress_run_only" in
332 if [ -z "$GOT_TEST_QUIET" ]; then
342 if [ "$result" = "0" ]; then
343 test_cleanup "$testroot" || return 1
344 if [ -z "$GOT_TEST_QUIET" ]; then
347 elif echo "$result" | grep -q "^xfail"; then
348 # expected test failure; test reproduces an unfixed bug
350 test_cleanup "$testroot" || return 1
352 echo "test failed; leaving test data in $testroot"