3030
3131scriptpath=$( dirname " $( readlink -f " $0 " ) " )
3232rev=$( git rev-parse HEAD)
33+ gnu_version=" 3.12"
34+ gnu_tarball_blake2b=5b4593b39da71578d7f975603abe9359be215b9ac76548a6ab0d6e3838bb103c7ffcddf7fa01abcd5c6289db9a2f16b43aa3d5e846a9aa4b8db866763c2660de
3335
3436# Report an infrastructure error: the test suite could not be run at all
3537die () {
@@ -53,50 +55,23 @@ tempdir=$(mktemp -d)
5355trap ' rm -rf "$tempdir"' EXIT
5456cd " $tempdir " || die " Cannot enter temporary directory $tempdir "
5557
56- # Check out the upstream test suite. git.savannah.gnu.org is regularly
57- # unavailable or slow, so retry a few times before giving up.
58- gitserver=" https://git.savannah.gnu.org"
59- testsuite=" $gitserver /git/diffutils.git"
60- attempts=3
61- for (( attempt = 1 ; attempt <= attempts; attempt++ ))
62- do
63- echo " Fetching upstream test suite from $testsuite (attempt $attempt /$attempts )"
64- rm -rf diffutils
65- git clone -n --depth=1 --filter=tree:0 " $testsuite " && break
66- (( attempt < attempts )) && sleep $(( attempt * 10 ))
67- done
68- [[ -d diffutils ]] || die " Failed to fetch the upstream test suite from $testsuite "
69- cd diffutils || die " Failed to fetch the upstream test suite from $testsuite "
70- git sparse-checkout set --no-cone tests & > /dev/null || die " Cannot sparse-checkout the upstream tests"
71- git checkout & > /dev/null || die " Cannot check out the upstream tests"
72- upstreamrev=$( git rev-parse HEAD)
73- [[ -d tests ]] || die " The upstream checkout contains no tests directory"
58+ # Check out the upstream test suite
59+ echo " Fetching upstream test suite"
60+ curl -fsSL --retry 5 https://ftpmirror.gnu.org/diffutils/diffutils-${gnu-version} .tar.xz -o gnu-diffutils.tar.xz || die " Failed to fetch test suite"
61+ echo ${gnu_tarball_blake2b} gnu-diffutils.tar.xz \
62+ | b2sum --check || die " Failed to verify checksum of tarball of GNU diffutils"
63+ mkdir -p diffutils
64+ tar xJf gnu-diffutils.tar.xz --strip-components=1 -C diffutils || die " Failed to extract test suite"
65+
66+ cd diffutils || die " Test suite src is broken"
7467
7568# Ensure that calling `diff` invokes the built `diffutils` binary instead of
7669# the upstream `diff` binary that is most likely installed on the system
77- mkdir src
78- cd src || die " Cannot create the directory holding the diff and cmp symlinks"
70+ cd src || die " Missing the directory holding the diff and cmp symlinks"
7971ln -s " $binary " diff
8072ln -s " $binary " cmp
8173cd ../tests || die " Cannot enter the upstream tests directory"
8274
83- # Fetch tests/init.sh from the gnulib repository (needed since
84- # https://git.savannah.gnu.org/cgit/diffutils.git/commit/tests?id=1d2456f539)
85- # The savannah gitweb interface is often rate-limited or unavailable, so fall
86- # back to the official gnulib mirror on GitHub
87- initsh_urls=(
88- " $gitserver /gitweb/?p=gnulib.git;a=blob_plain;f=tests/init.sh;hb=HEAD"
89- " https://raw.githubusercontent.com/coreutils/gnulib/master/tests/init.sh"
90- )
91- for url in " ${initsh_urls[@]} "
92- do
93- echo " Fetching tests/init.sh from $url "
94- curl -sSL --fail --retry 3 --retry-delay 5 --retry-all-errors \
95- --connect-timeout 30 --max-time 300 " $url " -o init.sh && [[ -s init.sh ]] && break
96- rm -f init.sh
97- done
98- [[ -s init.sh ]] || die " Failed to fetch tests/init.sh from the gnulib repository"
99-
10075if [[ -n " $TESTS " ]]
10176then
10277 tests=" $TESTS "
@@ -111,15 +86,13 @@ echo "Running $total tests"
11186export LC_ALL=C
11287export KEEP=yes
11388timestamp=$( date -Iseconds)
114- urlroot=" $gitserver /cgit/diffutils.git/tree/tests/"
11589passed=0
11690failed=0
11791skipped=0
11892normal=" $( tput sgr0) "
11993for test in $tests
12094do
12195 result=" FAIL"
122- url=" $urlroot$test ?id=$upstreamrev "
12396 # Run only the tests that invoke `diff` or `cmp`,
12497 # because other binaries aren't implemented yet
12598 if ! grep -E -s -q " (diff3|sdiff)" " $test "
130103 result=" SKIP"
131104 else
132105 json+=" {\" test\" :\" $test \" ,\" result\" :\" $result \" ,"
133- json+=" \" url \" :\" $url \" ,"
106+ json+=" \" gnu_version \" :\" $gnu_version \" ,"
134107 json+=" \" stdout\" :\" $( base64 -w0 < stdout.txt) \" ,"
135108 json+=" \" stderr\" :\" $( base64 -w0 < stderr.txt) \" ,"
136109 json+=" \" files\" :{"
156129 if [[ $result = " SKIP" ]]
157130 then
158131 (( skipped++ ))
159- json+=" {\" test\" :\" $test \" ,\" url\" :\" $url \" ,\" result\" :\" $result \" },"
160132 color=3 # yellow
161133 fi
162134 printf " %-40s $( tput setaf $color ) $result $( tput sgr0) \n" " $test "
@@ -171,7 +143,6 @@ echo ""
171143json=" \" tests\" :[${json% ,} ]"
172144metadata=" \" timestamp\" :\" $timestamp \" ,"
173145metadata+=" \" revision\" :\" $rev \" ,"
174- metadata+=" \" upstream-revision\" :\" $upstreamrev \" ,"
175146if [[ -n " $GITHUB_ACTIONS " ]]
176147then
177148 metadata+=" \" branch\" :\" $GITHUB_REF \" ,"
0 commit comments