diff options
Diffstat (limited to '')
-rwxr-xr-x | test/test_uscan | 530 | ||||
-rwxr-xr-x | test/test_uscan_ftp | 489 | ||||
-rwxr-xr-x | test/test_uscan_git | 207 | ||||
-rwxr-xr-x | test/test_uscan_group | 206 | ||||
-rwxr-xr-x | test/test_uscan_mangle | 1178 | ||||
-rwxr-xr-x | test/test_uscan_online | 50 | ||||
-rwxr-xr-x | test/test_uscan_svn | 196 |
7 files changed, 2856 insertions, 0 deletions
diff --git a/test/test_uscan b/test/test_uscan new file mode 100755 index 0000000..ebf2899 --- /dev/null +++ b/test/test_uscan @@ -0,0 +1,530 @@ +#!/bin/bash + +# Copyright (C) 2013, Rafael Laboissiere <rafael@laboissiere.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# On Debian systems, the complete text of the GNU General Public License +# version 3 can be found in the /usr/share/common-licenses/GPL-3 file. + +set -u + +TESTTYPE=base +test_dir=$(readlink -f "${0%/*}") +. "$test_dir/lib_test_uscan" + +SUFFIX="1" +if which dpkg-vendor >/dev/null 2>&1; then + VENDER="$(dpkg-vendor --query Vendor 2>/dev/null|tr 'A-Z' 'a-z')" + case "$VENDER" in + debian) SUFFIX="1" ;; + *) SUFFIX="0${VENDER}1" ;; + esac +fi + +if test "${1:-}" = --installed; then + COMMAND="uscan --no-conf --compression=xz" + shift +else + top_srcdir=$(readlink -f "${0%/*}/..") + make -C "$top_srcdir/scripts" uscan mk-origtargz uupdate debchange + PATH="$top_srcdir/scripts:$PATH" + export PATH + PERL5LIB="$top_srcdir/lib" + export PERL5LIB + COMMAND="uscan --no-conf --compression=xz" +fi + +COMMANDDEHS="$COMMAND --dehs" + +# comment out for debug +#COMMAND="$COMMAND --debug" + +tearDown(){ + killHttpServer + echo +} + +trap tearDown EXIT + +containsName(){ + echo "$1" | grep -qF "$2" + echo $? +} + +. "$test_dir/shunit2-helper-functions.sh" + +# The following tests do the following: (1) create a minimal Debian package +# directory, containing minimal files debian/{changelog,watch,copyright}, +# (2) create a minimal repository, containing a tarball (built on the fly), +# (3) start an HTTP server that works offline, using the SimpleHTTPServer +# module of Python, and (4) run uscan inside that minimal universe. + + +# The following function tests the --repack feature +helperTestRepack() { + from_ext="$1" + to_comp="$2" + file_output="$3" + + PKG=foo + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR") + + mkdir -p "$TEMP_PKG_DIR"/$PKG/debian/source + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/repo/port) + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/watch +version=3 +http://localhost:$PORT/$PKG-(\d).$from_ext +END + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/changelog +$PKG (0-1) unstable; urgency=low + + * Initial release + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + + echo -n '3.0 (quilt)' > "$TEMP_PKG_DIR"/$PKG/debian/source/format + mkdir -p "$TEMP_PKG_DIR"/repo/foo + touch "$TEMP_PKG_DIR"/repo/foo/content + + ( cd "$TEMP_PKG_DIR"/repo ; + tar -caf $PKG-1.$from_ext $PKG/* ) + + OUTPUT=$( cd "$TEMP_PKG_DIR"/$PKG ; $COMMANDDEHS --repack --compression=$to_comp ) + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + + TARBALL=${PKG}_1.orig.tar.$to_comp + if [ "$from_ext" != "tar.$to_comp" ] + then + assertFalse 'unrepacked tarball still present' "[ -f "$TEMP_PKG_DIR"/${PKG}_1.orig.$from_ext ]" + fi + assertTrue 'pristine tarball is not created' "[ -f "$TEMP_PKG_DIR"/$TARBALL ]" + assertNotNull "pristine tarball is not $to_comp-compressed" \ + "$( file -L "$TEMP_PKG_DIR"/$TARBALL | grep "$file_output" )" + CONTENTS="$(tar atf "$TEMP_PKG_DIR"/$TARBALL)" + assertTrue 'file contents missing' \ + $(containsName "$CONTENTS" content) + assertTrue "malfored target in dehs output: $OUTPUT" \ + $(containsName "$OUTPUT" "<target>$TARBALL</target>") + +} + +testRepackGZ_XZ() { helperTestRepack "tar.gz" "xz" "XZ compressed data" ; } +testRepackGZ_BZ2() { helperTestRepack "tar.gz" "bz2" "bzip2 compressed data" ; } +testRepackBZ2_GZ() { helperTestRepack "tar.bz2" "gz" "gzip compressed data" ; } +testRepackGZ_GZ() { helperTestRepack "tar.gz" "gz" "gzip compressed data" ; } +testRepackXZ_XZ() { helperTestRepack "tar.xz" "xz" "XZ compressed data" ; } +testRepackTGZ_XZ() { helperTestRepack "tgz" "xz" "XZ compressed data" ; } + +# The following function tests the --repack feature, with a zip file +testRepackZip_XZ() { + to_comp=xz + file_output="XZ compressed data" + + PKG=foo + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR") + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/repo/port) + + mkdir -p "$TEMP_PKG_DIR"/$PKG/debian/source + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/watch +version=3 +http://localhost:$PORT/$PKG-(\d).zip +END + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/changelog +$PKG (0-1) unstable; urgency=low + + * Initial release + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + echo -n '3.0 (quilt)' > "$TEMP_PKG_DIR"/$PKG/debian/source/format + + mkdir -p "$TEMP_PKG_DIR"/repo/foo + touch "$TEMP_PKG_DIR"/repo/foo/content + + ( cd "$TEMP_PKG_DIR"/repo ; + zip -q -r $PKG-1.zip * ) + + OUTPUT=$( (cd "$TEMP_PKG_DIR"/$PKG ; $COMMANDDEHS --repack --compression=$to_comp) ) + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + + TARBALL=${PKG}_1.orig.tar.$to_comp + assertTrue 'unrepacked zipfile present' "[ -f "$TEMP_PKG_DIR"/${PKG}-1.zip ]" + assertTrue 'pristine tarball is not created' "[ -f "$TEMP_PKG_DIR"/$TARBALL ]" + assertNotNull "pristine tarball is not $to_comp-compressed" \ + "$( file -L "$TEMP_PKG_DIR"/$TARBALL | grep "$file_output" )" + CONTENTS="$(tar atf "$TEMP_PKG_DIR"/$TARBALL)" + assertTrue 'file contents missing' \ + $(containsName "$CONTENTS" content) + assertTrue "malfored target in dehs output: $OUTPUT" \ + $(containsName "$OUTPUT" "<target>$TARBALL</target>") + +} + + + +# The following function tests the Files-Excluded feature of uscan, which +# allows the selective exclusion of files from the upstream tarball before +# repacking it. + +helperCreateRepo () { + mkdir -p $PKG/debian + + cat <<END > $PKG/debian/watch +version=3 +${OPTS:-}http://localhost:$PORT/$PKG-(\d).tar.gz debian ${SCRIPT:-} +END + + cat <<END > $PKG/debian/changelog +$PKG (0+dfsg1-$SUFFIX) unstable; urgency=low + + * Initial release + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + + cat <<'END' > $PKG/debian/copyright +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Files-Excluded: exclude-this + exclude-dir + .* + */js/jquery.js + ;?echo?baz;?# +END + if [ -n "${SRCFORMAT:-}" ]; then + mkdir -p $PKG/debian/source + echo "$SRCFORMAT" > $PKG/debian/source/format + fi + + mkdir -p repo + touch repo/include-this + touch repo/exclude-this + touch repo/.hidden + mkdir -p "repo/; echo baz; #/" + mkdir -p repo/exclude-dir + touch repo/exclude-dir/file + mkdir -p repo/exclude-dir/subdir + touch repo/exclude-dir/subdir/file2 + mkdir -p repo/docs/html/js/ + touch repo/docs/html/js/jquery.js + +} + +helperTestContent() { + assertTrue 'file that must be present is excluded in the tarball' \ + $(containsName "$CONTENTS" include-this) + assertFalse 'file that must be excluded is present in the tarball' \ + $(containsName "$CONTENTS" exclude-this) + assertFalse "dir that must be excluded is present in the tarball" \ + $(containsName "$CONTENTS" exclude-dir) + assertFalse "subdir that must be excluded is present in the tarball" \ + $(containsName "$CONTENTS" subdir) + assertFalse "non-root-file that must be excluded is present in the tarball" \ + $(containsName "$CONTENTS" jquery.js) + assertFalse "hidden file that must be excluded is present in the zip file" \ + $(containsName "$CONTENTS" .hidden) + assertFalse "path with whitespace that must be excluded is present" \ + $(containsName "$CONTENTS" "; echo baz; #/") +} + +testFileExclusion() { + + PKG=foo + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR") + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/repo/port) + + ( + cd "$TEMP_PKG_DIR" + OPTS="opts=repacksuffix=+dfsg1,dversionmangle=s/@DEB_EXT@// " + SCRIPT="uupdate" + SRCFORMAT="3.0 (quilt)" + helperCreateRepo + cd repo + tar cfz $PKG-1.tar.gz * .hidden ) + + (cd "$TEMP_PKG_DIR"/$PKG ; $COMMAND) + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + + TARBALL=${PKG}_1+dfsg1.orig.tar.xz + assertTrue 'downloaded tarfile not present' "[ -f "$TEMP_PKG_DIR"/${PKG}-1.tar.gz ]" + assertTrue 'pristine tarball is not created' "[ -f "$TEMP_PKG_DIR"/$TARBALL ]" + assertFalse 'pristine tarball is a symlink (nothing repacked?)' "[ -L "$TEMP_PKG_DIR"/$TARBALL ]" + assertNotNull 'pristine tarball is not XZ-compressed' \ + "$( file "$TEMP_PKG_DIR"/$TARBALL | grep -i 'XZ compressed data' )" + CONTENTS="$(tar atf "$TEMP_PKG_DIR"/$TARBALL)" + + helperTestContent + + # check uupdate + assertTrue 'pristine tarball is not extracted' "[ -f "$TEMP_PKG_DIR"/${PKG}-1+dfsg1/debian/changelog ]" + DVERSION=`dpkg-parsechangelog -l"$TEMP_PKG_DIR"/${PKG}-1+dfsg1/debian/changelog -SVersion` + assertEquals "uscan: Version should be 1+dfsg1-$SUFFIX but $DVERSION" "$DVERSION" "1+dfsg1-$SUFFIX" + +} + +# the same, but run from a separate directory (no way for uupdate, just download) +testFileExclusionSeparateDir() { + + PKG=foo + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR") + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/repo/port) + + ( + cd "$TEMP_PKG_DIR" + SCRIPT="" + OPTS="opts=repacksuffix=+dfsg1,dversionmangle=auto " + helperCreateRepo + cd repo + tar cfz $PKG-1.tar.gz * .hidden ) + + mkdir "$TEMP_PKG_DIR"/otherdir + ( + cd "$TEMP_PKG_DIR"/otherdir; + $COMMAND --package $PKG --force-download --upstream-version 1 \ + --watchfile ../$PKG/debian/watch --copyright-file ../$PKG/debian/copyright + ) + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + + TARBALL=${PKG}_1+dfsg1.orig.tar.xz + assertTrue 'downloaded tarfile not present' "[ -f "$TEMP_PKG_DIR"/${PKG}-1.tar.gz ]" + assertTrue 'pristine tarball is not created' "[ -f "$TEMP_PKG_DIR"/$TARBALL ]" + assertFalse 'pristine tarball is a symlink (nothing repacked?)' "[ -L "$TEMP_PKG_DIR"/$TARBALL ]" + assertNotNull 'pristine tarball is not XZ-compressed' \ + "$( file "$TEMP_PKG_DIR"/$TARBALL | grep -i 'XZ compressed data' )" + CONTENTS="$(tar atf "$TEMP_PKG_DIR"/$TARBALL)" + + helperTestContent + +} + +# The same, for a zip file that is being repacked + +testFileExclusionZipToTar() { + + PKG=foo + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR") + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/repo/port) + + ( + cd "$TEMP_PKG_DIR" + SRCFORMAT="3.0 (quilt)" + helperCreateRepo + cat <<END > $PKG/debian/watch +version=3 +opts=repacksuffix=+dfsg1,dversionmangle=s/@DEB_EXT@// http://localhost:$PORT/$PKG-(\d).zip debian uupdate +END + + cd repo + zip -q -r $PKG-1.zip * .hidden ) + + (cd "$TEMP_PKG_DIR"/$PKG ; $COMMAND --repack) + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + + TARBALL=${PKG}_1+dfsg1.orig.tar.xz + assertTrue 'unrepacked zipfile not present' "[ -f "$TEMP_PKG_DIR"/${PKG}-1.zip ]" + assertTrue 'pristine tarball is not created' "[ -f "$TEMP_PKG_DIR"/$TARBALL ]" + assertNotNull 'pristine tarball is not xz-compressed' \ + "$( file "$TEMP_PKG_DIR"/$TARBALL | grep 'XZ compressed data' )" + CONTENTS="$(tar atf "$TEMP_PKG_DIR"/$TARBALL)" + helperTestContent + + # check uupdate + assertTrue 'pristine tarball is not extracted' "[ -f "$TEMP_PKG_DIR"/${PKG}-1+dfsg1/debian/changelog ]" + DVERSION=`dpkg-parsechangelog -l"$TEMP_PKG_DIR"/${PKG}-1+dfsg1/debian/changelog -SVersion` + assertEquals "uscan: Version should be 1+dfsg1-$SUFFIX but $DVERSION" "$DVERSION" "1+dfsg1-$SUFFIX" + +} + +testPlainMode() { + PKG=foo + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR") + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/repo/port) + + mkdir -p "$TEMP_PKG_DIR"/$PKG/debian + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/watch +version=4 +opts="searchmode=plain" \ +http://localhost:$PORT/src.json http://localhost:$PORT/foo-(\d).zip +END + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/changelog +$PKG (0-1) unstable; urgency=low + + * Initial release + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + + mkdir -p "$TEMP_PKG_DIR"/repo/foo + touch "$TEMP_PKG_DIR"/repo/foo/content + + ( cd "$TEMP_PKG_DIR"/repo ; + zip -q -r $PKG-1.zip *; + cat > src.json <<END +{"1.0":{"tarball":"http://localhost:$PORT/foo-1.zip"}} +END + ) + + OUTPUT=$( (cd "$TEMP_PKG_DIR"/$PKG ; $COMMANDDEHS) ) + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + + TARBALL=${PKG}_1.orig.tar.$to_comp + assertTrue 'unrepacked zipfile present' "[ -f "$TEMP_PKG_DIR"/${PKG}-1.zip ]" + +} + +testLinksWithRelativeBase() { + PKG=foo + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR") + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/repo/port) + to_comp=xz + + mkdir -p "$TEMP_PKG_DIR"/$PKG/debian + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/watch +version=4 +http://localhost:$PORT/foo/index.html foo-([\d\.]+).zip +END + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/changelog +$PKG (0-1) unstable; urgency=low + + * Initial release + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + + mkdir -p "$TEMP_PKG_DIR"/repo/foo + touch "$TEMP_PKG_DIR"/repo/foo/content + + for href in foo-1.zip /foo/foo-1.zip //localhost:$PORT/foo/foo-1.zip ../foo/foo-1.zip x/../../foo/foo-1.zip; do + ( cd "$TEMP_PKG_DIR"/repo/foo ; + zip -q -r $PKG-1.zip *; + zip -q -r $PKG-0.9.zip *; + cat > index.html <<END +<html><body> +<base href="/foo/" /> +<a href="$href">foo-1.zip</a> +</body></html> +END + ) + + (cd "$TEMP_PKG_DIR"/$PKG ; $COMMAND) + assertEquals "uscan: exit_code!=0 but exit_code=0 with $href" "$?" "0" + done + + assertTrue 'unrepacked zipfile present' "[ -f "$TEMP_PKG_DIR"/${PKG}-1.zip ]" + +} + +testComponentDehsOutput() { + PKG=foo + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR") + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/repo/port) + + mkdir -p "$TEMP_PKG_DIR"/$PKG/debian + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/watch +version=4 +http://localhost:$PORT/$PKG-(\d).zip debian + +opts="searchmode=plain,component=baz" \ +http://localhost:$PORT/src.json http://localhost:$PORT/foo-(\d).zip +END + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/changelog +$PKG (0-1) unstable; urgency=low + + * Initial release + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + + mkdir -p "$TEMP_PKG_DIR"/repo/foo + touch "$TEMP_PKG_DIR"/repo/foo/content + + ( cd "$TEMP_PKG_DIR"/repo ; + zip -q -r $PKG-1.zip *; + cat > src.json <<END +{"1.0":{"tarball":"http://localhost:$PORT/foo-1.zip"}} +END + ) + + OUTPUT=$( (cd "$TEMP_PKG_DIR"/$PKG ; $COMMANDDEHS --report --dehs) ) + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + assertTrue "malfored target in dehs output: $OUTPUT" \ + $(containsName "$OUTPUT" '<component id="baz">') + assertTrue "malfored target in dehs output: $OUTPUT" \ + $(containsName "$OUTPUT" "<component-upstream-version>1</component-upstream-version>") +} + +testSimpleHeader() { + PKG=foo + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR") + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/repo/port) + + mkdir -p "$TEMP_PKG_DIR"/$PKG/debian/source + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/watch +version=4 +http://localhost:$PORT/$PKG-(\d).zip debian + +opts="searchmode=plain,component=baz" \ +http://localhost:$PORT/src.json http://localhost:$PORT/foo-(\d).zip +END + + echo -n '3.0 (quilt)' > "$TEMP_PKG_DIR"/$PKG/debian/source/format + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/changelog +$PKG (0-1) unstable; urgency=low + + * Initial release + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + + mkdir -p "$TEMP_PKG_DIR"/repo/foo + touch "$TEMP_PKG_DIR"/repo/foo/content + + ( cd "$TEMP_PKG_DIR"/repo ; + zip -q -r $PKG-1.zip *; + cat > src.json <<END +{"1.0":{"tarball":"http://localhost:$PORT/foo-1.zip"}} +END + ) + + OUTPUT=$( (cd "$TEMP_PKG_DIR"/$PKG ; $COMMAND -v \ + --http-header http://localhost:$PORT@Simple-Token=localtoken \ + --http-header http://another.com@Ext-Token=exttoken \ + ) ) + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + assertTrue "per-host header not exported: $OUTPUT" \ + $(containsName "$OUTPUT" "Set per-host custom header Simple-Token for http://localhost:$PORT/foo") + assertFalse "ext per-host header is exported: $OUTPUT" \ + $(containsName "$OUTPUT" "Set per-host custom header Ext-Token") +} + +. shunit2 diff --git a/test/test_uscan_ftp b/test/test_uscan_ftp new file mode 100755 index 0000000..e49a9a9 --- /dev/null +++ b/test/test_uscan_ftp @@ -0,0 +1,489 @@ +#!/bin/bash +# vim: set shiftwidth=4 tabstop=8 noexpandtab: + +# Copyright (C) 2018, Osamu Aoki <osamu@debian.org> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# On Debian systems, the complete text of the GNU General Public License +# version 3 can be found in the /usr/share/common-licenses/GPL-3 file. + +set -u + +TESTTYPE=FTP +. ./lib_test_uscan + +DEB_HOST_OS="$(dpkg-architecture -qDEB_HOST_ARCH_OS)" +if [ "$DEB_HOST_OS" = "kfreebsd" ]; then + # kbsd has a non-working semaphore, that is needed here. + echo "This test is not supported on $(dpkg-architecture -qDEB_HOST_ARCH), skipping" + exit 0 +fi + +COMMAND="uscan --no-conf" + +# set safe defaults +WEBSCRIPT=":" +DEBUGECHO=":" +DEBUGLSLR=":" +DEBUGBASH=":" +# comment out for debug +#COMMAND="$COMMAND --debug" +#COMMAND="$COMMAND --verbose" +#DEBUGECHO=echo +#DEBUGLSLR="ls -laR" +#DEBUGLSLR="ls -la" +#DEBUGBASH="bash -i" + +# Initial Debian revision value is distribution dependent +SUFFIX="1" +if which dpkg-vendor >/dev/null 2>&1; then + VENDER="$(dpkg-vendor --query Vendor 2>/dev/null|tr 'A-Z' 'a-z')" + case "$VENDER" in + debian) SUFFIX="1" ;; + *) SUFFIX="0${VENDER}1" ;; + esac +fi + +cleanup(){ + kill -9 $(cat $TMPDIR/$REPOPATH/pid) + rm -rf $TMPDIR + echo "" +} + +spawnFtpServer(){ + ( + local USCAN_FTP_SERVER=${USCAN_FTP_SERVER:-ftpserver.py} + mkdir -p "$TMPDIR/$REPOPATH" + cd "$TMPDIR/$REPOPATH" || exit 1 + echo "FTP starting ... $TMPDIR/$REPOPATH" + local pid + python3 "$test_dir/uscan/$USCAN_FTP_SERVER" 2>log & + pid=$! + echo $pid > pid + while ! [ -s port ]; do + sleep 2s + if ! kill -0 $pid 2> /dev/null ; then + echo "The FTP server returned an error:" + cat log + exit 1 + fi + done + ) +} + +trap cleanup 1 2 3 13 15 + +containsName(){ + echo "$1" | grep -qF "$2" + echo $? +} + +. "${0%/*}/shunit2-helper-functions.sh" + +# The following tests do the following: (1) create a minimal Debian package +# directory, containing minimal files debian/{changelog,watch,copyright}, +# (2) create a minimal repository, containing a tarball (built on the fly), +# (3) start an FTP server that works offline, using the pyftpdlib +# module of Python, and (4) run uscan inside that minimal universe. + +# make debian/ in `pwd` +# debian/watch contains $WATCHVER and $WATCHLINE with template URL updated +makeDebianDir() { + DEBNAME=${1:-foo} # Debian source package name + DEBVER=${2:-1.0} # Debian source package version + mkdir -p debian/source + + cat <<END > debian/rules +%: + dh $@ +END +chmod 755 debian/rules + + cat <<END > debian/changelog +$DEBNAME ($DEBVER) unstable; urgency=low + + * Release of the $DEBNAME package $DEBVER. + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + # debian/source/format + case $DEBVER in + *-*) # non-native package + echo "3.0 (quilt)" > debian/source/format + ;; + *) # native package + echo "3.0 (native)" > debian/source/format + ;; + esac + # debian/copyright + echo "Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/" \ + > debian/copyright + # debian/watch + echo "version=$WATCHVER" > debian/watch + echo "$WATCHLINE" | sed -e "s,@@@url@@@,ftp://127.0.0.1:${PORT}/,g" - \ + >> debian/watch + # debian/upstream/signing-key.asc + mkdir -p debian/upstream + cp -f $test_dir/uscan/PUBLIC_KEY.asc debian/upstream/signing-key.asc +} + + +# make tarball in $REPOPATH/$POOLPATH +makeUpstreamTar() { + UPNAME=${1:-foo} # Upstream package name + UPVER=${2:-1.0} # upstream package version + COMPRESSION=${3:-gz} # archve compression type + TYPE=${4:-non-native} # set this if native-type upstream + OLDDIR=`pwd` + mkdir -p $TMPDIR/$REPOPATH/$POOLPATH/$UPNAME-$UPVER + cd $TMPDIR/$REPOPATH/$POOLPATH + touch $UPNAME-$UPVER/FILE.$UPNAME.$UPVER + if [ "$TYPE" = "native" ]; then + cd $TMPDIR/$REPOPATH/$POOLPATH/$UPNAME-$UPVER + makeDebianDir $UPNAME $UPVER + cd $TMPDIR/$REPOPATH/$POOLPATH + fi + case $COMPRESSION in + gz|gzip) + NEWTAR=$UPNAME-$UPVER.tar + tar -cf $NEWTAR $UPNAME-$UPVER + NEWTAR=$UPNAME-$UPVER.tar.gz + tar -czf $NEWTAR $UPNAME-$UPVER + ;; + bz2|bzip2) + NEWTAR=$UPNAME-$UPVER.tar + tar -cf $NEWTAR $UPNAME-$UPVER + NEWTAR=$UPNAME-$UPVER.tar.bz2 + tar --bzip2 -cf $NEWTAR $UPNAME-$UPVER + ;; + xz) + NEWTAR=$UPNAME-$UPVER.tar + tar -cf $NEWTAR $UPNAME-$UPVER + NEWTAR= $UPNAME-$UPVER.tar.xz + tar --xz -cf $NEWTAR $UPNAME-$UPVER + ;; + zip) + NEWTAR=$UPNAME-$UPVER.zip + zip -r $NEWTAR $UPNAME-$UPVER + ;; + *) echo "Wrong compression mode: $COMPRESSION" + exit 1 + ;; + esac + # make $NEWTAR.asc + $GPG --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \ + --secret-keyring $PRIVATE_KEYRING --default-key 72543FAF \ + --armor --detach-sign $NEWTAR + if [ "$COMPRESSION" != "zip" ]; then + NEWTAR=$UPNAME-$UPVER.tar + $GPG --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \ + --secret-keyring $PRIVATE_KEYRING --default-key 72543FAF \ + --armor --detach-sign $NEWTAR + + fi + cd $OLDDIR +} + +# setup a common watch file test environment +helperWatch() { + local SITESCRIPT=${1:-siteWebNonNative} + local VEROLD=${2:-1.0} + local VERNEW=${3:-2.0} + local PREFIX="${4:-}" + local TMPDIR=$(mktemp -d) + ORIGDIR=`pwd` + PKG=${PKG:-foo} + REPOPATH=${REPOPATH:-repo} + POOLPATH=${POOLPATH:-pool} + GZREPACK=${GZREPACK:-gz} + XCOMMAND=${XCOMMAND:-$COMMAND} + WATCHVER="${WATCHVER:-3}" + WATCHLINE0="@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate" + WATCHLINE="${WATCHLINE:-$WATCHLINE0}" + cd $TMPDIR + # start FTP server with its root at $TMPDIR/$REPOPATH + spawnFtpServer || exit 1 + PORT=$(cat $TMPDIR/$REPOPATH/port) + $DEBUGECHO " ***** ftp://localhost:$PORT started showing $TMPDIR/$REPOPATH *****" + # make web site + $SITESCRIPT + # make local $VEROLD source tree + tar -xzf $TMPDIR/$REPOPATH/$POOLPATH/${PKG}-${VEROLD}.tar.gz + if [ -n "${PREFIX}" ]; then + mv $TMPDIR/${PKG}-${VEROLD} $TMPDIR/${PKG}-${PREFIX}${VEROLD} + fi + mv $TMPDIR/${PKG}-${PREFIX}${VEROLD} $TMPDIR/${PKG} + cd $TMPDIR/${PKG} + if [ ! -d debian ]; then + makeDebianDir $PKG ${PREFIX}${VEROLD}-$SUFFIX + fi + local UUPDATE="" + if grep -q "uupdate" $TMPDIR/${PKG}/debian/watch ; then + UUPDATE=uupdate + fi + local PGP="" + if grep -q "pgpurlmangle" $TMPDIR/${PKG}/debian/watch ; then + PGP=pgp + fi + if grep -q "pgpmode *= *auto" $TMPDIR/${PKG}/debian/watch ; then + PGP=pgp + fi + if grep -q "pgpmode *= *previous" $TMPDIR/${PKG}/debian/watch ; then + PGP=pgp + fi + $XCOMMAND + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + cd $TMPDIR + $DEBUGLSLR + UTARBALL=${PKG}-${VERNEW}.tar.gz + STARBALL=${PKG}_${PREFIX}${VERNEW}.orig.tar.$GZREPACK + assertTrue "$UTARBALL missing: $WATCHLINE" "[ -f $UTARBALL ]" + assertTrue "$STARBALL missing: $WATCHLINE" "[ -f $STARBALL ]" + if [ "$PGP" = "pgp" ]; then + UTARSIG=${PKG}-${VERNEW}.tar.gz.asc + if [ ! -f $UTARSIG ]; then + UTARSIG=${PKG}-${VERNEW}.tar.asc + fi + STARSUG=${PKG}_${PREFIX}${VERNEW}.orig.tar.$GZREPACK.asc + assertTrue "$UTARSIG and *.sig missing: $WATCHLINE" "[ -f $UTARSIG ]" + assertTrue "$STARSIG missing: $WATCHLINE" "[ -f $STARSIG ]" + fi + # check uupdate + if [ "$UUPDATE" = "uupdate" ]; then + cd $TMPDIR/${PKG}-${PREFIX}${VERNEW} + assertTrue 'pristine tarball is not extracted' "[ -f debian/changelog ]" + DVERSION=`dpkg-parsechangelog -ldebian/changelog -SVersion` + assertEquals "uscan: Version should be ${PREFIX}${VERNEW}-$SUFFIX but $DVERSION" "$DVERSION" "${PREFIX}${VERNEW}-$SUFFIX" + cd $TMPDIR + fi + $DEBUGBASH + cd $ORIGDIR + cleanup + unset REPOPATH + unset POOLPATH + unset GZREPACK + unset XCOMMAND + unset WATCHVER + unset WATCHLINE +} + +# setup a common watch file test environment with Zip upstream +helperWatchZip() { + local SITESCRIPT=${1:-siteWebNonNative} + local VEROLD=${2:-1.0} + local VERNEW=${3:-2.0} + local PREFIX="${4:-}" + local TMPDIR=$(mktemp -d) + ORIGDIR=`pwd` + PKG=${PKG:-foo} + REPOPATH=${REPOPATH:-repo} + POOLPATH=${POOLPATH:-pool} + GZREPACK=${GZREPACK:-xz} + XCOMMAND=${XCOMMAND:-$COMMAND} + WATCHVER="${WATCHVER:-3}" + WATCHLINE0="@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate" + WATCHLINE="${WATCHLINE:-$WATCHLINE0}" + cd $TMPDIR + # start FTP server with its root at $TMPDIR/$REPOPATH + spawnFtpServer || exit 1 + PORT=$(cat $TMPDIR/$REPOPATH/port) + $DEBUGECHO " ***** ftp://localhost:$PORT started showing $TMPDIR/$REPOPATH *****" + # make web site + $SITESCRIPT + # make local $VEROLD source tree + unzip $TMPDIR/$REPOPATH/$POOLPATH/${PKG}-${VEROLD}.zip + if [ -n "$PREFIX" ]; then + mv $TMPDIR/${PKG}-${VEROLD} $TMPDIR/${PKG}-${PREFIX}${VEROLD} + fi + mv $TMPDIR/${PKG}-${PREFIX}${VEROLD} $TMPDIR/${PKG} + cd $TMPDIR/${PKG} + if [ ! -d debian ]; then + makeDebianDir $PKG ${PREFIX}${VEROLD}-$SUFFIX + fi + local UUPDATE="" + if grep -q "uupdate" $TMPDIR/${PKG}/debian/watch ; then + UUPDATE=uupdate + fi + local PGP="" + if grep -q "pgpurlmangle" $TMPDIR/${PKG}/debian/watch ; then + PGP=pgp + fi + if grep -q "pgpmode *= *auto" $TMPDIR/${PKG}/debian/watch ; then + PGP=pgp + fi + if grep -q "pgpmode *= *previous" $TMPDIR/${PKG}/debian/watch ; then + PGP=pgp + fi + $XCOMMAND + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + cd $TMPDIR + $DEBUGLSLR + UTARBALL=${PKG}-${VERNEW}.zip + STARBALL=${PKG}_${PREFIX}${VERNEW}.orig.tar.$GZREPACK + assertTrue "$UTARBALL missing: $WATCHLINE" "[ -f $UTARBALL ]" + assertTrue "$STARBALL missing: $WATCHLINE" "[ -f $STARBALL ]" + if [ "$PGP" = "pgp" ]; then + UTARSIG=${PKG}-${VERNEW}.zip.asc + STARSUG=${PKG}_${PREFIX}${VERNEW}.orig.tar.$GZREPACK.asc + assertTrue "$UTARSIG and *.sig missing: $WATCHLINE" "[ -f $UTARSIG ]" + assertTrue "$STARSIG missing: $WATCHLINE" "[ -f $STARSIG ]" + fi + # check uupdate + if [ "$UUPDATE" = "uupdate" ]; then + cd $TMPDIR/${PKG}-${PREFIX}${VERNEW} + assertTrue 'pristine tarball is not extracted' "[ -f debian/changelog ]" + DVERSION=`dpkg-parsechangelog -ldebian/changelog -SVersion` + assertEquals "uscan: Version should be ${PREFIX}${VERNEW}-$SUFFIX but $DVERSION" "$DVERSION" "${PREFIX}${VERNEW}-$SUFFIX" + cd $TMPDIR + fi + $DEBUGBASH + cd $ORIGDIR + cleanup + unset REPOPATH + unset POOLPATH + unset GZREPACK + unset XCOMMAND + unset WATCHVER + unset WATCHLINE +} + +siteNonNative() { + local PKG=${1:-foo} + local EXTRA=${2:-} + makeUpstreamTar $PKG 0.0 gz non-native + makeUpstreamTar $PKG 1.0 gz non-native + makeUpstreamTar $PKG 2.0 gz non-native + mkdir -p $TMPDIR/$REPOPATH/0.0/$PKG/ooo/ + mkdir -p $TMPDIR/$REPOPATH/1.0/$PKG/ooo/ + mkdir -p $TMPDIR/$REPOPATH/2.0/$PKG/ooo/ + if [ -n "$EXTRA" ]; then + makeUpstreamTar $PKG 3.0 gz non-native + mkdir -p $TMPDIR/$REPOPATH/3.0/$PKG/ooo/ + fi + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz.asc $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.gz.asc + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.asc $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.asc + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz.asc $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.gz.asc + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.asc $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.asc + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz.asc $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.gz.asc + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.asc $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.asc + if [ -n "$EXTRA" ]; then + ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz.asc $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.gz.asc + ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.asc $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.asc + fi +} + +siteNonNativeZip() { + local PKG=${1:-foo} + local EXTRA=${2:-} + makeUpstreamTar $PKG 0.0 zip non-native + makeUpstreamTar $PKG 1.0 zip non-native + makeUpstreamTar $PKG 2.0 zip non-native + mkdir -p $TMPDIR/$REPOPATH/0.0/$PKG/ooo/ + mkdir -p $TMPDIR/$REPOPATH/1.0/$PKG/ooo/ + mkdir -p $TMPDIR/$REPOPATH/2.0/$PKG/ooo/ + if [ -n "$EXTRA" ]; then + makeUpstreamTar $PKG 3.0 gz non-native + mkdir -p $TMPDIR/$REPOPATH/3.0/$PKG/ooo/ + fi + ln -sf ../../../$POOLPATH/${PKG}-0.0.zip $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.zip + ln -sf ../../../$POOLPATH/${PKG}-0.0.zip.asc $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.zip.asc + ln -sf ../../../$POOLPATH/${PKG}-1.0.zip $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.zip + ln -sf ../../../$POOLPATH/${PKG}-1.0.zip.asc $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.zip.asc + ln -sf ../../../$POOLPATH/${PKG}-2.0.zip $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.zip + ln -sf ../../../$POOLPATH/${PKG}-2.0.zip.asc $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.zip.asc + if [ -n "$EXTRA" ]; then + ln -sf ../../../$POOLPATH/${PKG}-3.0.zip $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.zip + ln -sf ../../../$POOLPATH/${PKG}-3.0.zip.asc $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.zip.asc + fi +} + +siteNonNativeR() { + local PKG=${1:-foo} + local EXTRA=${2:-} + makeUpstreamTar $PKG 0.0 gz non-native + makeUpstreamTar $PKG 1.0 gz non-native + makeUpstreamTar $PKG 2.0 gz non-native + mkdir -p $TMPDIR/$REPOPATH/0.0/$PKG/ooo/ + mkdir -p $TMPDIR/$REPOPATH/1.0/$PKG/ooo/ + mkdir -p $TMPDIR/$REPOPATH/2.0/$PKG/ooo/ + if [ -n "$EXTRA" ]; then + makeUpstreamTar $PKG 3.0 gz non-native + mkdir -p $TMPDIR/$REPOPATH/3.0/$PKG/ooo/ + fi + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-0.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz.asc $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-0.0.tar.gz.asc + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-1.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz.asc $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-1.0.tar.gz.asc + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-2.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz.asc $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-2.0.tar.gz.asc + if [ -n "$EXTRA" ]; then + ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-3.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz.asc $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-3.0.tar.gz.asc + fi +} + +# test a watch files + +### VERSION 4 ### +# standard tests + +# test non-native package with uupdate, bare FTP server in normal order +testWatch4NonNative() { + WATCHVER=4 + WATCHLINE='opts=pgpsigurlmangle=s/$/.asc/ @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteNonNative +} + +# test --download-current-version, bare FTP server in normal order +testWatch4NonNativeDlCurrent() { + WATCHVER=4 + XCOMMAND="$COMMAND --download-current-version" + WATCHLINE='opts=pgpsigurlmangle=s/$/.asc/ @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteNonNative 1.0 1.0 +} + +# test --download-version, bare FTP server in normal order +testWatch4NonNativeDlUversion() { + WATCHVER=4 + XCOMMAND="$COMMAND --download-version 0.0" + WATCHLINE='opts=pgpsigurlmangle=s/$/.asc/ @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteNonNative 1.0 0.0 +} + +# test non-native package with uupdate, bare FTP server in normal order with upstream ZIP +testWatch4NonNativeZip() { + WATCHVER=4 + COMPRESSION='zip' + WATCHLINE='opts=pgpsigurlmangle=s/$/.asc/ @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatchZip siteNonNativeZip +} + +# test non-native package with uupdate, bare FTP server in normal order with repack to xz +testWatch4NonNativeXz() { + WATCHVER=4 + GZREPACK='xz' + WATCHLINE='opts=pgpsigurlmangle=s/$/.asc/,compression=xz,repack @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteNonNative +} + +# test non-native package with uupdate, bare FTP server in normal order with ungzsig +testWatch4NonNativeUngzsig() { + WATCHVER=4 + WATCHLINE='opts=pgpsigurlmangle=s/.gz$/.asc/,decompress @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteNonNative +} + +. shunit2 diff --git a/test/test_uscan_git b/test/test_uscan_git new file mode 100755 index 0000000..61b5c81 --- /dev/null +++ b/test/test_uscan_git @@ -0,0 +1,207 @@ +#!/bin/bash + +# Copyright (C) 2018, Xavier <yadd@debian.org> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# On Debian systems, the complete text of the GNU General Public License +# version 3 can be found in the /usr/share/common-licenses/GPL-3 file. + +set -u +#set -x + +TESTTYPE=Git +. ./lib_test_uscan + +COMMAND="chronic_sh uscan --no-conf --compression=xz --dehs" + +# prevent the local from messing with this test +export GIT_CONFIG_NOGLOBAL=1 +export HOME="" +export XDG_CONFIG_HOME="" + +# comment out for debug +#COMMAND="$COMMAND --verbose" +#COMMAND="$COMMAND --debug" + +cleanup(){ + rm -rf "$TEMP_PKG_DIR" +} + +spawnGitRepo(){ + mkdir -p "$TEMP_PKG_DIR/repo" + (cd "$TEMP_PKG_DIR/repo" || exit 1 + chronic_sh git init + git config user.name "Joe Developer" + git config user.email "none@debian.org" + touch changelog file.c extra.c + echo 'extra.c export-ignore' >.gitattributes + chronic_sh git add changelog file.c extra.c .gitattributes + chronic_sh git commit -a -m 'Init' + for version in 1.0 2.0; do + echo "# Version $version" >> file.c + cat >> changelog <<END +Version $version + +END + chronic_sh git commit -a -m "Releasing $version" + chronic_sh git tag -s -u 72543FAF -m "Version $version" "v$version" + done) +} + +trap cleanup EXIT + +containsName(){ + echo "$1" | grep -F -q "$2" + echo $? +} + +# shellcheck source=shunit2-helper-functions.sh +. "${0%/*}/shunit2-helper-functions.sh" + +PKG=foo + +makeDebianDir() { + WATCHARGS=$1 + TEMP_PKG_DIR=$(mktemp -d --tmpdir="$SHUNIT_TMPDIR" uscan_git.XXXXXX) + if [ -z "$TEMP_PKG_DIR" ]; then + echo "Failed to create temporary directory" >&2 + exit 1 + fi + mkdir -p "$TEMP_PKG_DIR"/$PKG/debian/upstream + mkdir -p "$TEMP_PKG_DIR"/$PKG/debian/source + spawnGitRepo + + cat <<END > "$TEMP_PKG_DIR/$PKG/debian/watch" +version=4 +opts="mode=git,gitmode=shallow,$WATCHARGS" \ +file:///$TEMP_PKG_DIR/repo refs/tags/v([\\d\\.]+) debian +END + + cat <<END > "$TEMP_PKG_DIR/$PKG/debian/changelog" +$PKG (0-1) unstable; urgency=low + + * Initial release + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + echo '3.0 (quilt)' > "$TEMP_PKG_DIR/$PKG/debian/source/format" + cp -f "$test_dir/uscan/PUBLIC_KEY.asc" "$TEMP_PKG_DIR/$PKG/debian/upstream/signing-key.asc" +} + +makeDebianDirWithUpstream() { + WATCHARGS=$1 + makeDebianDir "$WATCHARGS" + cd "$TEMP_PKG_DIR/$PKG" || exit 1 + chronic_sh git init + chronic_sh git remote add upstream "file:///$TEMP_PKG_DIR/repo" + chronic_sh git fetch upstream + cd - > /dev/null || exit 1 +} + +makeDebianDirHead() { + WATCHARGS=$1 + makeDebianDir "$WATCHARGS" + cat <<END > "$TEMP_PKG_DIR/$PKG/debian/watch" +version=4 +opts="mode=git,pretty=0.0+git%cd.%h" \ +file:///$TEMP_PKG_DIR/repo HEAD +END +} + +helperLaunch() { + WATCHARGS=$1 + ARG="${2:-}" + CMD_ARG="${3:-}" + if test "$ARG" = "upstream"; then + makeDebianDirWithUpstream "$WATCHARGS" + elif test "$ARG" = "HEAD"; then + makeDebianDirHead "$WATCHARGS" + else + makeDebianDir "$WATCHARGS" + fi + ( cd "$TEMP_PKG_DIR/$PKG" || exit 1 ; $COMMAND $CMD_ARG --watchfile=debian/watch ) + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" +} + +testGit() { + helperLaunch "pgpmode=none" + TARBALL=${PKG}_2.0.orig.tar.xz + assertTrue 'downloaded tarfile not present' "[ -f '$TEMP_PKG_DIR/${PKG}-2.0.tar.xz' ]" + assertTrue 'pristine tarball is not created' "[ -f '$TEMP_PKG_DIR/$TARBALL' ]" + assertTrue 'pristine tarball is a symlink' "[ -L '$TEMP_PKG_DIR/$TARBALL' ]" + cleanup +} + +testGitHead() { + helperLaunch "pgpmode=none" HEAD + ORIG=$(find "$TEMP_PKG_DIR" | perl -ne 'print if/\/foo.*\.orig\.tar\.xz$/') + UPSTREAM=$(find "$TEMP_PKG_DIR" | perl -ne 'print if/\/foo.*(?<!orig)\.tar\.xz$/') + assertTrue 'downloaded tarfile not present' "[ -f '$UPSTREAM' ]" + assertTrue 'pristine tarball is not created' "[ -f '$ORIG' ]" + assertTrue 'pristine tarball is a symlink' "[ -L '$ORIG' ]" + cleanup +} + +testGitSignedTag() { + helperLaunch "pgpmode=gittag" + TARBALL=${PKG}_2.0.orig.tar.xz + assertTrue 'downloaded tarfile not present' "[ -f '$TEMP_PKG_DIR/${PKG}-2.0.tar.xz' ]" + assertTrue 'pristine tarball is not created' "[ -f '$TEMP_PKG_DIR/$TARBALL' ]" + assertTrue 'pristine tarball is a symlink' "[ -L '$TEMP_PKG_DIR/$TARBALL' ]" + cleanup +} + +testGitUpstream() { + helperLaunch "pgpmode=none" upstream + TARBALL=${PKG}_2.0.orig.tar.xz + assertTrue 'downloaded tarfile not present' "[ -f '$TEMP_PKG_DIR/${PKG}-2.0.tar.xz' ]" + assertTrue 'pristine tarball is not created' "[ -f '$TEMP_PKG_DIR/$TARBALL' ]" + assertTrue 'pristine tarball is a symlink' "[ -L '$TEMP_PKG_DIR/$TARBALL' ]" + cleanup +} + +testGitUpstreamSignedTag() { + helperLaunch "pgpmode=gittag" upstream + TARBALL=${PKG}_2.0.orig.tar.xz + assertTrue 'downloaded tarfile not present' "[ -f '$TEMP_PKG_DIR/${PKG}-2.0.tar.xz' ]" + assertTrue 'pristine tarball is not created' "[ -f '$TEMP_PKG_DIR/$TARBALL' ]" + assertTrue 'pristine tarball is a symlink' "[ -L '$TEMP_PKG_DIR/$TARBALL' ]" + cleanup +} + +testGitIgnoreExclusions() { + helperLaunch "gitexport=all" + assertTrue 'downloaded tarfile is incomplete' \ + "tar tf '$TEMP_PKG_DIR/${PKG}-2.0.tar.xz' '${PKG}-2.0/extra.c'" + cleanup +} + +testGitUpstreamIgnoreExclusions() { + helperLaunch "gitexport=all" upstream + assertTrue 'downloaded tarfile is incomplete' \ + "tar tf '$TEMP_PKG_DIR/${PKG}-2.0.tar.xz' '${PKG}-2.0/extra.c'" + cleanup +} + +testGitSignedTagWithDestDir() { + DESTDIR=$TEMP_PKG_DIR/destdir + mkdir -p $DESTDIR + helperLaunch "pgpmode=gittag" "" "--destdir $TEMP_PKG_DIR/destdir" + TARBALL=${PKG}_2.0.orig.tar.xz + assertTrue 'downloaded tarfile not present' "[ -f '$DESTDIR/${PKG}-2.0.tar.xz' ]" + assertTrue 'pristine tarball is not created' "[ -f '$DESTDIR/$TARBALL' ]" + assertTrue 'pristine tarball is a symlink' "[ -L '$DESTDIR/$TARBALL' ]" + cleanup +} + +# shellcheck disable=SC1091 +. shunit2 diff --git a/test/test_uscan_group b/test/test_uscan_group new file mode 100755 index 0000000..dca4b9d --- /dev/null +++ b/test/test_uscan_group @@ -0,0 +1,206 @@ +#!/bin/bash + +# Copyright (C) 2020, Xavier Guimard <yadd@debian.org> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# On Debian systems, the complete text of the GNU General Public License +# version 3 can be found in the /usr/share/common-licenses/GPL-3 file. + +set -u + +TESTTYPE=base +test_dir=$(readlink -f "${0%/*}") +. "$test_dir/lib_test_uscan" + +SUFFIX="1" +if which dpkg-vendor >/dev/null 2>&1; then + VENDER="$(dpkg-vendor --query Vendor 2>/dev/null|tr 'A-Z' 'a-z')" + case "$VENDER" in + debian) SUFFIX="1" ;; + *) SUFFIX="0${VENDER}1" ;; + esac +fi + +if test "${1:-}" = --installed; then + COMMAND="uscan --no-conf --compression=gz" + shift +else + top_srcdir=$(readlink -f "${0%/*}/..") + make -C "$top_srcdir/scripts" uscan mk-origtargz uupdate debchange + PATH="$top_srcdir/scripts:$PATH" + export PATH + PERL5LIB="$top_srcdir/lib" + export PERL5LIB + COMMAND="uscan --no-conf --compression=xz" +fi + +COMMANDDEHS="$COMMAND --dehs" + +# comment out for debug +#COMMAND="$COMMAND --debug" + +tearDown(){ + killHttpServer + echo +} + +trap tearDown EXIT + +containsName(){ + echo "$1" | grep -qF "$2" + echo $? +} + +makeRepo() { + lv="$1" + cmpopt1="$2" + lv1="$3" + cmpopt2="$4" + lv2="$5" + cmpopt3="$6" + lv3="$7" + cmpopt4="$8" + lv4="$9" + prev="${10}" + PKG=foo + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR") + + mkdir -p "$TEMP_PKG_DIR"/$PKG/debian/source + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/repo/port) + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/watch +version=4 +http://localhost:$PORT/ .*$PKG-([\d\.]+).tar.gz $lv + +opts="component=bar1$cmpopt1" http://localhost:$PORT/ .*bar1-([\d\.]+).tar.gz $lv1 +opts="component=bar2$cmpopt2" http://localhost:$PORT/ .*bar2-([\d\.]+).tar.gz $lv2 +opts="component=bar3$cmpopt3" http://localhost:$PORT/ .*bar3-([\d\.]+).tar.gz $lv3 +opts="component=bar4$cmpopt4" http://localhost:$PORT/ .*bar4-([\d\.]+).tar.gz $lv4 +END + + cat <<END > "$TEMP_PKG_DIR"/$PKG/debian/changelog +$PKG ($prev) unstable; urgency=medium + + * Initial release + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + + echo -n '3.0 (quilt)' > "$TEMP_PKG_DIR"/$PKG/debian/source/format + mkdir -p "$TEMP_PKG_DIR"/repo/foo + touch "$TEMP_PKG_DIR"/repo/foo/content + + # Upstream repo + ( cd "$TEMP_PKG_DIR"/repo ; + tar -czf $PKG-1.0.0.tar.gz $PKG/* ) + + for i in 1 2 3 4; do + # Upstream repo + mkdir -p "$TEMP_PKG_DIR"/repo/bar$i + touch "$TEMP_PKG_DIR"/repo/bar$i/content + ( cd "$TEMP_PKG_DIR"/repo ; + tar -czf bar$i-2.0.$i.tar.gz bar$i/* ) + # Debian dir + mkdir $TEMP_PKG_DIR/$PKG/bar$i + echo '{"name":"bar'$i'","version":"'1.0.$i'"}' > $TEMP_PKG_DIR/$PKG/bar$i/package.json + done +} + +helperDownload() { + next="${11}" + makeRepo "$@" + + OUTPUT=$( cd "$TEMP_PKG_DIR"/$PKG ; $COMMANDDEHS --dehs ) + BASETARBALL=${PKG}_$next.orig + assertTrue 'pristine tarball foo is not created' "[ -f "$TEMP_PKG_DIR"/$BASETARBALL.tar.gz ]" + assertTrue "malformed target in dehs output: $OUTPUT" \ + $(containsName "$OUTPUT" "<target>$BASETARBALL.tar.gz</target>") + for i in 1 2 3 4; do + assertTrue "pristine tarball bar$i is not created" "[ -f "$TEMP_PKG_DIR"/$BASETARBALL-bar$i.tar.gz ]" + assertTrue "malformed target in dehs output: $OUTPUT" \ + $(containsName "$OUTPUT" "<component-target>$BASETARBALL-bar$i.tar.gz</component-target>") + done + #cat "$TEMP_PKG_DIR"/$PKG/debian/watch +} + +testCmpIgnore() { + helperDownload "debian" "" "ignore" "" "ignore" "" "ignore" "" "ignore" "0.0.1" "1.0.0" +} + +testCmpGroup() { + helperDownload "group" "" "group" "" "group" "" "group" "" "group" "0.0.1+~1" "1.0.0+~2.0.1+~2.0.2+~2.0.3+~2.0.4" +} + +testCmpGroupOneCmpChanged() { + helperDownload "group" "" "group" "" "group" "" "group" "" "group" "1.0.0+~2.0.1+~2.0.2+~2.0.2+~2.0.4" "1.0.0+~2.0.1+~2.0.2+~2.0.3+~2.0.4" +} + +testCmpPartialGroup() { + helperDownload "group" "" "group" "" "group" "" "ignore" "" "ignore" "0.0.1+~1" "1.0.0+~2.0.1+~2.0.2" +} + +testCmpPartialGroup2() { + helperDownload "group" "" "group" "" "ignore" "" "group" "" "ignore" "0.0.1+~1" "1.0.0+~2.0.1+~2.0.3" +} + +testCmpChecksum() { + helperDownload "group" "" "checksum" "" "checksum" "" "checksum" "" "checksum" "0.0.1+~1" "1.0.0+~cs8.0.10" +} + +testCmpChecksumOneCmpChanged() { + helperDownload "group" "" "checksum" "" "checksum" "" "checksum" "" "checksum" "1.0.0+~cs8.0.9" "1.0.0+~cs8.0.10" +} + +testCmpGroupAndChecksum() { + helperDownload "group" "" "group" "" "checksum" "" "checksum" "" "checksum" "0.0.1+~1" "1.0.0+~2.0.1+~cs6.0.9" +} + +testCmpGroupIgnoreAndChecksum() { + helperDownload "group" "" "group" "" "ignore" "" "checksum" "" "checksum" "0.0.1+~1" "1.0.0+~2.0.1+~cs4.0.7" +} + +helperNoDownload() { + next="${10}" + makeRepo "$@" + + OUTPUT=$( cd "$TEMP_PKG_DIR"/$PKG ; $COMMANDDEHS --dehs ) + assertTrue "bad change detected: $OUTPUT" \ + $(containsName "$OUTPUT" "<status>up to date</status>") + BASETARBALL=${PKG}_$next.orig + assertTrue 'pristine tarball foo is created' "[ ! -f "$TEMP_PKG_DIR"/$BASETARBALL.tar.gz ]" +} + +testCmpIgnoreND() { + helperNoDownload "debian" "" "ignore" "" "ignore" "" "ignore" "" "ignore" "1.0.0" +} + +testCmpGroupND() { + helperNoDownload "group" "" "group" "" "group" "" "group" "" "group" "1.0.0+~2.0.1+~2.0.2+~2.0.3+~2.0.4" +} + +testCmpChecksumND() { + helperNoDownload "group" "" "checksum" "" "checksum" "" "checksum" "" "checksum" "1.0.0+~cs8.0.10" +} + +# Same test but here Ctype detects change even if previous checksum is wrong +testCmpChecksumCtype() { + helperDownload "group" ",ctype=nodejs" "checksum" ",ctype=nodejs" "checksum" ",ctype=nodejs" "checksum" ",ctype=nodejs" "checksum" "1.0.0+~cs8.0.10" "1.0.0+~cs8.0.10" +} + +testCmpIgnoreCtype() { + helperNoDownload "debian" ",ctype=nodejs" "ignore" "" "ignore" "" "ignore" "" "ignore" "1.0.0" + assertTrue "Component change is not detected: $OUTPUT" \ + $(containsName "$OUTPUT" "Newest version of bar1 on remote site is 2.0.1, local version is 1.0.1") +} + +. shunit2 diff --git a/test/test_uscan_mangle b/test/test_uscan_mangle new file mode 100755 index 0000000..7ab651e --- /dev/null +++ b/test/test_uscan_mangle @@ -0,0 +1,1178 @@ +#!/bin/bash + +# Copyright (C) 2013, Rafael Laboissiere <rafael@laboissiere.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# On Debian systems, the complete text of the GNU General Public License +# version 3 can be found in the /usr/share/common-licenses/GPL-3 file. + +set -u + +TESTTYPE=Mangle +. ./lib_test_uscan + +COMMAND="uscan --no-conf" + +# set safe defaults +WEBSCRIPT=":" +DEBUGECHO=":" +DEBUGLSLR=":" +DEBUGBASH=":" +# comment out for debug +#COMMAND="$COMMAND --debug" +#COMMAND="$COMMAND --verbose" +#DEBUGECHO=echo +#DEBUGLSLR="ls -laR" +#DEBUGLSLR="ls -la" +#DEBUGBASH="bash -i" + +# Initial Debian revision value is distribution dependent +SUFFIX="1" +if which dpkg-vendor >/dev/null 2>&1; then + VENDER="$(dpkg-vendor --query Vendor 2>/dev/null|tr 'A-Z' 'a-z')" + case "$VENDER" in + debian) SUFFIX="1" ;; + *) SUFFIX="0${VENDER}1" ;; + esac +fi + +tearDown(){ + killHttpServer + echo +} + +trap tearDown EXIT + +containsName(){ + echo "$1" | grep -qF "$2" + echo $? +} + +. "${0%/*}/shunit2-helper-functions.sh" + +# The following tests do the following: (1) create a minimal Debian package +# directory, containing minimal files debian/{changelog,watch,copyright}, +# (2) create a minimal repository, containing a tarball (built on the fly), +# (3) start an HTTP server that works offline, using the SimpleHTTPServer +# module of Python, and (4) run uscan inside that minimal universe. + +# make debian/ in `pwd` +# debian/watch contains $WATCHVER and $WATCHLINE with template URL updated +makeDebianDir() { + DEBNAME=${1:-foo} # Debian source package name + DEBVER=${2:-1.0} # Debian source package version + mkdir -p debian/source + + cat <<END > debian/rules +%: + dh $@ +END +chmod 755 debian/rules + + cat <<END > debian/changelog +$DEBNAME ($DEBVER) unstable; urgency=low + + * Release of the $DEBNAME package $DEBVER. + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + # debian/source/format + case $DEBVER in + *-*) # non-native package + echo "3.0 (quilt)" > debian/source/format + ;; + *) # native package + echo "3.0 (native)" > debian/source/format + ;; + esac + # debian/copyright + echo "Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/" \ + > debian/copyright + if [ "${FILEEXCLUDE:-0}" = "1" ]; then + # exclude just for main + cat <<'END' >> debian/copyright +Files-Excluded: exclude-this + */exclude-dir + .* + */js/jquery.js + ;?echo?baz;?# +END + elif [ "${FILEEXCLUDE:-0}" = "2" ]; then + # exclude for main(=foo) bar baz + cat <<'END' >> debian/copyright +Files-Excluded: exclude-this + */exclude-dir + .* + */js/jquery.js + ;?echo?baz;?# +Files-Excluded-bar: exclude-this + */exclude-dir + .* + */js/jquery.js + ;?echo?baz;?# +Files-Excluded-baz: exclude-this + */exclude-dir + .* + */js/jquery.js + ;?echo?baz;?# +END + elif [ "${FILEEXCLUDE:-0}" = "3" ]; then + # exclude for foo bar baz + cat <<'END' >> debian/copyright +Files-Excluded-foo: exclude-this + */exclude-dir + .* + */js/jquery.js + ;?echo?baz;?# +Files-Excluded-bar: exclude-this + */exclude-dir + .* + */js/jquery.js + ;?echo?baz;?# +Files-Excluded-baz: exclude-this + */exclude-dir + .* + */js/jquery.js + ;?echo?baz;?# +END + fi + # debian/watch + echo "version=$WATCHVER" > debian/watch + echo "$WATCHLINE" | sed -e "s,@@@url@@@,http://localhost:${PORT}/,g" - \ + >> debian/watch + # debian/upstream/signing-key.asc + mkdir -p debian/upstream + if [ "$KEYMODE" = "ASC" ]; then + cp -f $test_dir/uscan/PUBLIC_KEY.asc debian/upstream/signing-key.asc + else + cp -f "$GPGHOME/pubring.gpg" debian/upstream/signing-key.pgp + fi +} + + +# make tarball in $REPOPATH/$POOLPATH +makeUpstreamTar() { + UPNAME=${1:-foo} # Upstream package name + UPVER=${2:-1.0} # upstream package version + COMPRESSION=${3:-gz} # archve compression type + TYPE=${4:-non-native} # set this if native-type upstream + OLDDIR=`pwd` + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/$POOLPATH/$UPNAME-$UPVER + cd "$TEMP_PKG_DIR"/$REPOPATH/$POOLPATH + touch $UPNAME-$UPVER/FILE.$UPNAME.$UPVER + touch $UPNAME-$UPVER/include-this + touch $UPNAME-$UPVER/exclude-this + touch $UPNAME-$UPVER/.hidden + mkdir -p "$UPNAME-$UPVER/; echo baz; #/" + mkdir -p $UPNAME-$UPVER/exclude-dir + touch $UPNAME-$UPVER/exclude-dir/file + mkdir -p $UPNAME-$UPVER/subdir/exclude-dir + touch $UPNAME-$UPVER/subdir/exclude-dir/file2 + mkdir -p $UPNAME-$UPVER/docs/html/js/ + touch $UPNAME-$UPVER/docs/html/js/jquery.js + if [ "$TYPE" = "native" ]; then + cd "$TEMP_PKG_DIR"/$REPOPATH/$POOLPATH/$UPNAME-$UPVER + makeDebianDir $UPNAME $UPVER + cd "$TEMP_PKG_DIR"/$REPOPATH/$POOLPATH + fi + case $COMPRESSION in + gz|gzip) + NEWTAR=$UPNAME-$UPVER.tar.gz + tar -czf $NEWTAR $UPNAME-$UPVER + ;; + bz2|bzip2) + NEWTAR=$UPNAME-$UPVER.tar.bz2 + tar --bzip2 -cf $NEWTAR $UPNAME-$UPVER + ;; + xz) + NEWTAR= $UPNAME-$UPVER.tar.xz + tar --xz -cf $NEWTAR $UPNAME-$UPVER + ;; + zip) + NEWTAR=$UPNAME-$UPVER.zip + zip -r $NEWTAR $UPNAME-$UPVER + ;; + *) echo "Wrong compression mode: $COMPRESSION" + exit 1 + ;; + esac + case "${SIGMODE:-}" in # undefined SIGMODE → no sig + ASC) # make $NEWTAR.asc + $GPG --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \ + --secret-keyring $PRIVATE_KEYRING --default-key 72543FAF \ + --armor --detach-sign $NEWTAR + ;; + BIN) #make $NEWTAR.sig + $GPG --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \ + --secret-keyring $PRIVATE_KEYRING --default-key 72543FAF \ + --detach-sign $NEWTAR + ;; + SELF) #make $NEWTAR.gpg + $GPG --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \ + --secret-keyring $PRIVATE_KEYRING --default-key 72543FAF \ + --sign $NEWTAR + esac + + cd $OLDDIR +} + +# setup a common watch file test environment +helperWatch() { + local SITESCRIPT=${1:-siteWebNonNative} + local VEROLD=${2:-1.0} + local VERNEW=${3:-2.0} + local PREFIX="${4:-}" + TEMP_PKG_DIR=${TEMP_PKG_DIR:-$(mktemp -d -p "$SHUNIT_TMPDIR" uscan_mangle.XXXXXX)} + ORIGDIR=`pwd` + PKG=${PKG:-foo} + REPOPATH=${REPOPATH:-repo} + POOLPATH=${POOLPATH:-pool} + GZREPACK=${GZREPACK:-xz} + MGZREPACK=${MGZREPACK:-gz} + XCOMMAND=${XCOMMAND:-$COMMAND} + WATCHVER="${WATCHVER:-3}" + WATCHLINE0="@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate" + WATCHLINE="${WATCHLINE:-$WATCHLINE0}" + COMPONENTS=${COMPONENTS:-} + FILEEXCLUDE=${FILEEXCLUDE:-0} # no exclude + SIGMODE=${SIGMODE:-ASC} # ASC=ASCII or BIN=BINARY or SELF + KEYMODE=${KEYMODE:-ASC} # ASC=ASCII AEMORED or BIN=DEARMORED BINARY + cd "$TEMP_PKG_DIR" + # start HTTP server with its root at "$TEMP_PKG_DIR"/$REPOPATH + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/$REPOPATH/port) + $DEBUGECHO " ***** http://localhost:$PORT started showing "$TEMP_PKG_DIR"/$REPOPATH *****" + # make web site + $SITESCRIPT + # make local $VEROLD source tree + tar -xzf "$TEMP_PKG_DIR"/$REPOPATH/$POOLPATH/${PKG}-${VEROLD}.tar.gz + if [ -n "$PREFIX" ]; then + mv "$TEMP_PKG_DIR"/${PKG}-${VEROLD} "$TEMP_PKG_DIR"/${PKG}-${PREFIX}${VEROLD} + fi + mv "$TEMP_PKG_DIR"/${PKG}-${PREFIX}${VEROLD} "$TEMP_PKG_DIR"/${PKG} + cd "$TEMP_PKG_DIR"/${PKG} + if [ ! -d debian ]; then + makeDebianDir $PKG ${PREFIX}${VEROLD}-$SUFFIX + fi + local UUPDATE="" + if grep -q "uupdate" "$TEMP_PKG_DIR"/${PKG}/debian/watch ; then + UUPDATE=uupdate + fi + local PGP="" + if grep -q "pgpurlmangle" "$TEMP_PKG_DIR"/${PKG}/debian/watch ; then + PGP=pgp + fi + if grep -q "pgpmode *= *auto" "$TEMP_PKG_DIR"/${PKG}/debian/watch ; then + PGP=pgp + fi + if grep -q "pgpmode *= *previous" "$TEMP_PKG_DIR"/${PKG}/debian/watch ; then + PGP=pgp + fi + $XCOMMAND + assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0" + cd "$TEMP_PKG_DIR" + $DEBUGLSLR + UTARBALL=${PKG}-${UVERSION:-${VERNEW}}.tar.gz + STARBALL=${PKG}_${PREFIX}${VERNEW}.orig.tar.$MGZREPACK + assertTrue "$UTARBALL missing: $WATCHLINE" "[ -f $UTARBALL ]" + assertTrue "$STARBALL missing: $WATCHLINE" "[ -f $STARBALL ]" + if [ "$PGP" = "pgp" ]; then + UTARSIG=${PKG}-${UVERSION:-${VERNEW}}.tar.gz.sig + if [ ! -f $UTARSIG ]; then + UTARSIG=${PKG}-${UVERSION:-${VERNEW}}.tar.gz.asc + fi + STARSIG=${PKG}_${PREFIX}${VERNEW}.orig.tar.$MGZREPACK.asc + assertTrue "$UTARSIG and *.sig missing: $WATCHLINE" "[ -f $UTARSIG ]" + assertTrue "$STARSIG missing: $WATCHLINE" "[ -f $STARSIG ]" + fi + for cpnt in $COMPONENTS; do + UTARBALL=${cpnt}-${CMPVERSION:-${VERNEW}}.tar.gz + STARBALL=${PKG}_${PREFIX}${VERNEW}.orig-${cpnt}.tar.$GZREPACK + assertTrue "$UTARBALL missing: $WATCHLINE" "[ -f $UTARBALL ]" + assertTrue "$STARBALL missing: $WATCHLINE" "[ -f $STARBALL ]" + if [ "$PGP" = "pgp" ]; then + UTARSIG=${cpnt}-${CMPVERSION:-${VERNEW}}.tar.gz.sig + if [ ! -f $UTARSIG ]; then + UTARSIG=${cpnt}-${CMPVERSION:-${VERNEW}}.tar.gz.asc + fi + STARSIG=${PKG}_${PREFIX}${VERNEW}.orig-${cpnt}.tar.$GZREPACK.asc + assertTrue "$UTARSIG and *.sig missing: $WATCHLINE" "[ -f $UTARSIG ]" + # Skipping this: signature link skipped when upstream file is repacked + #assertTrue "$STARSIG missing: $WATCHLINE" "[ -f $STARSIG ]" + fi + done + # check uupdate + if [ "$UUPDATE" = "uupdate" ]; then + cd "$TEMP_PKG_DIR"/${PKG}-${PREFIX}${VERNEW} + assertTrue 'pristine tarball is not extracted' "[ -f debian/changelog ]" + DVERSION=`dpkg-parsechangelog -ldebian/changelog -SVersion` + assertEquals "uscan: Version should be ${PREFIX}${VERNEW}-$SUFFIX but $DVERSION" "$DVERSION" "${PREFIX}${VERNEW}-$SUFFIX" + if [ "$FILEEXCLUDE" != "3" ]; then + # main is dummy + assertTrue 'file that must be present is excluded in the tarball' '[ -f include-this ]' + fi + if [ "$FILEEXCLUDE" = "1" ] || [ "$FILEEXCLUDE" = "2" ]; then + assertFalse "file that must be excluded is present in the tarball" '[ -f exclude-this ]' + assertFalse "hidden file that must be excluded is present in the tarball" '[ -f .hidden ]' + assertFalse "dir that must be excluded is present in the tarball" '[ -d exclude-dir ]' + assertFalse "subdir that must be excluded is present in the tarball" '[ -d subdir/exclude-dir ]' + CONTENTS=$(ls -R) + assertFalse "non-root-file that must be excluded is present in the tarball" \ + $(containsName "$CONTENTS" jquery.js) + assertFalse "path with whitespace that must be excluded is present in the tarball" \ + $(containsName "$CONTENTS" "; echo baz; #/") + fi + for c in $COMPONENTS ; do + cd "$TEMP_PKG_DIR"/${PKG}-${PREFIX}${VERNEW}/$c + assertTrue 'file that must be present is excluded in the tarball' '[ -f include-this ]' + if [ "$FILEEXCLUDE" = "1" ] || [ "$FILEEXCLUDE" = "2" ]; then + assertFalse "file that must be excluded is present in the orig-$c.tar" '[ -f exclude-this ]' + assertFalse "hidden file that must be excluded is present in the orig-$c.tar" '[ -f .hidden ]' + assertFalse "dir that must be excluded is present in the orig-$c.tar" '[ -d exclude-dir ]' + assertFalse "subdir that must be excluded is present in the orig-$c.tar" '[ -d subdir/exclude-dir ]' + CONTENTS=$(ls -R) + assertFalse "non-root-file that must be excluded is present in the orig-$c.tar" \ + $(containsName "$CONTENTS" jquery.js) + assertFalse "path with whitespace that must be excluded is present in the orig-$c.tar" \ + $(containsName "$CONTENTS" "; echo baz; #/") + fi + done + cd "$TEMP_PKG_DIR" + fi + $DEBUGBASH + cd $ORIGDIR + unset REPOPATH + unset POOLPATH + unset GZREPACK + unset MGZREPACK + unset XCOMMAND + unset WATCHVER + unset WATCHLINE + unset COMPONENTS + unset FILEEXCLUDE + unset SIGMODE + unset KEYMODE +} + +# setup a common watch file test environment to see user-agent +helperWatchUA() { + local SITESCRIPT=${1:-siteWebNonNative} + TEMP_PKG_DIR=$(mktemp -d -p "$SHUNIT_TMPDIR" uscan_mangle.XXXXXX) + ORIGDIR=`pwd` + PKG=${PKG:-foo} + REPOPATH=${REPOPATH:-repo} + POOLPATH=${POOLPATH:-pool} + XCOMMAND=${XCOMMAND:-$COMMAND} + WATCHVER="${WATCHVER:-3}" + WATCHLINE0="@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate" + WATCHLINE="${WATCHLINE:-$WATCHLINE0}" + KEYMODE=${KEYMODE:-ASC} # ASC=ASCII AEMORED or BIN=DEARMORED BINARY + cd "$TEMP_PKG_DIR" + # start HTTP server with its root at "$TEMP_PKG_DIR"/$REPOPATH + spawnHttpServer + PORT=$(cat "$TEMP_PKG_DIR"/$REPOPATH/port) + $DEBUGECHO " ***** http://localhost:$PORT started showing "$TEMP_PKG_DIR"/$REPOPATH *****" + # make web site + $SITESCRIPT + # make local $VEROLD source tree + mkdir -p "$TEMP_PKG_DIR"/${PKG} + cd "$TEMP_PKG_DIR"/${PKG} + if [ ! -d debian ]; then + makeDebianDir $PKG 1.0-$SUFFIX + fi + $XCOMMAND + USERAGENTX="$(grep -ie '^User-Agent:' ../repo/log |head -1 | perl -p -e "s/\r//g" )" + assertTrue "Bad $USERAGENTX" "[ \"$USERAGENTX\" = \"User-Agent: $USERAGENT\" ]" + echo "SENT: \"User-Agent: $USERAGENT\"" + echo "GOT : \"$USERAGENTX\"" + $DEBUGBASH + cd $ORIGDIR + unset REPOPATH + unset POOLPATH + unset XCOMMAND + unset WATCHVER + unset WATCHLINE + unset KEYMODE +} + +# populate pool directory +siteNative() { + local PKG=${1:-foo} + makeUpstreamTar $PKG 0.0 gz native + makeUpstreamTar $PKG 1.0 gz native + makeUpstreamTar $PKG 2.0 gz native + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/0.0/$PKG/ooo/ + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/1.0/$PKG/ooo/ + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/2.0/$PKG/ooo/ + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.gz +} + +siteNonNative() { + local PKG=${1:-foo} + local EXTRA=${2:-} + makeUpstreamTar $PKG 0.0 gz non-native + makeUpstreamTar $PKG 1.0 gz non-native + makeUpstreamTar $PKG 2.0 gz non-native + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/0.0/$PKG/ooo/ + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/1.0/$PKG/ooo/ + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/2.0/$PKG/ooo/ + if [ -n "$EXTRA" ]; then + makeUpstreamTar $PKG 3.0 gz non-native + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/3.0/$PKG/ooo/ + fi + if [ "${SIGMODE:-}" = "ASC" ]; then + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz.asc "$TEMP_PKG_DIR"/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.gz.asc + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz.asc "$TEMP_PKG_DIR"/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.gz.asc + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz.asc "$TEMP_PKG_DIR"/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.gz.asc + if [ -n "$EXTRA" ]; then + ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz.asc "$TEMP_PKG_DIR"/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.gz.asc + fi + elif [ "${SIGMODE:-}" = "BIN" ]; then + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz.sig "$TEMP_PKG_DIR"/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.gz.sig + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz.sig "$TEMP_PKG_DIR"/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.gz.sig + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz.sig "$TEMP_PKG_DIR"/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.gz.sig + if [ -n "$EXTRA" ]; then + ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.gz + ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz.sig "$TEMP_PKG_DIR"/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.gz.sig + fi + elif [ "${SIGMODE:-}" = "SELF" ]; then + ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz.gpg "$TEMP_PKG_DIR"/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.gz.gpg + ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz.gpg "$TEMP_PKG_DIR"/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.gz.gpg + ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz.gpg "$TEMP_PKG_DIR"/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.gz.gpg + if [ -n "$EXTRA" ]; then + ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz.gpg "$TEMP_PKG_DIR"/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.gz.gpg + fi + fi +} + +# hide siteNative behind a web page +siteWebNative() { + siteNative + cat <<END > "$TEMP_PKG_DIR"/$REPOPATH/index.html +<html> +<head> + <meta charset="utf-8"> +</head> +<body> +<a href="/0.0/foo/ooo/foo-0.0.tar.gz">Very old</a> <br/ > +<a href="/1.0/foo/ooo/foo-1.0.tar.gz">A bit OLD</a> <br /> +<a href="/2.0/foo/ooo/foo-2.0.tar.gz">Latest</a> <br /> +</body> +<html> +END +} + +siteWebNonNative() { + siteNonNative + cat <<END > "$TEMP_PKG_DIR"/$REPOPATH/index.html +<html> +<head> + <meta charset="utf-8"> +</head> +<body> +<a href="/0.0/foo/ooo/foo-0.0.tar.gz">Very old</a> <br/ > +<a href="/1.0/foo/ooo/foo-1.0.tar.gz">A bit OLD</a> <br /> +<a href="/2.0/foo/ooo/foo-2.0.tar.gz">Latest</a> <br /> +</body> +<html> +END +} + +siteWebNonNativeRecWithBase() { + siteNonNative "$@" + for DIR in "$TEMP_PKG_DIR"/$REPOPATH/[0-9].*; do + [ -d "$DIR" ] && cat <<END > "$DIR"/index.html +<html> +<head> + <meta charset="utf-8"> +<base href="/${DIR##*/}/foo/ooo/x.html"/> +</head> +<body> +<a href="foo-${DIR##*/}.tar.gz">Blah</a> <br/ > +</body> +<html> +END + done +} + +siteWebNonNativeR() { + makeUpstreamTar foo 0.0 gz non-native + makeUpstreamTar foo 1.0 gz non-native + makeUpstreamTar foo 2.0 gz non-native + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/123/foo/ooo/ + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/124/foo/ooo/ + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/125/foo/ooo/ + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/325/foo/ooo/ + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/424/foo/ooo/ + mkdir -p "$TEMP_PKG_DIR"/$REPOPATH/523/foo/ooo/ + if [ "$SIGMODE" = "ASC" ]; then + ln -sf ../../../$POOLPATH/foo-0.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/125/foo/ooo/foo-0.0.tar.gz + ln -sf ../../../$POOLPATH/foo-1.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/124/foo/ooo/foo-1.0.tar.gz + ln -sf ../../../$POOLPATH/foo-2.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/123/foo/ooo/foo-2.0.tar.gz + ln -sf ../../../$POOLPATH/foo-0.0.tar.gz.asc "$TEMP_PKG_DIR"/$REPOPATH/325/foo/ooo/foo-0.0.tar.gz.asc + ln -sf ../../../$POOLPATH/foo-1.0.tar.gz.asc "$TEMP_PKG_DIR"/$REPOPATH/424/foo/ooo/foo-1.0.tar.gz.asc + ln -sf ../../../$POOLPATH/foo-2.0.tar.gz.asc "$TEMP_PKG_DIR"/$REPOPATH/523/foo/ooo/foo-2.0.tar.gz.asc + cat <<END > "$TEMP_PKG_DIR"/$REPOPATH/index.html +<html> +<head> + <meta charset="utf-8"> +</head> +<body> +<a href="/125/foo/ooo/foo-0.0.tar.gz">Very old</a> <br/ > +<a href="/124/foo/ooo/foo-1.0.tar.gz">A bit OLD</a> <br /> +<a href="/123/foo/ooo/foo-2.0.tar.gz">Latest</a> <br /> +<a href="/325/foo/ooo/foo-0.0.tar.gz.asc">Very old sig</a> <br/ > +<a href="/424/foo/ooo/foo-1.0.tar.gz.asc">A bit OLD sig</a> <br /> +<a href="/523/foo/ooo/foo-2.0.tar.gz.asc">Latest sig</a> <br /> +</body> +<html> +END + elif [ "$SIGMODE" = "BIN" ]; then + ln -sf ../../../$POOLPATH/foo-0.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/125/foo/ooo/foo-0.0.tar.gz + ln -sf ../../../$POOLPATH/foo-1.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/124/foo/ooo/foo-1.0.tar.gz + ln -sf ../../../$POOLPATH/foo-2.0.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/123/foo/ooo/foo-2.0.tar.gz + ln -sf ../../../$POOLPATH/foo-0.0.tar.gz.sig "$TEMP_PKG_DIR"/$REPOPATH/325/foo/ooo/foo-0.0.tar.gz.sig + ln -sf ../../../$POOLPATH/foo-1.0.tar.gz.sig "$TEMP_PKG_DIR"/$REPOPATH/424/foo/ooo/foo-1.0.tar.gz.sig + ln -sf ../../../$POOLPATH/foo-2.0.tar.gz.sig "$TEMP_PKG_DIR"/$REPOPATH/523/foo/ooo/foo-2.0.tar.gz.sig + cat <<END > "$TEMP_PKG_DIR"/$REPOPATH/index.html +<html> +<head> + <meta charset="utf-8"> +</head> +<body> +<a href="/125/foo/ooo/foo-0.0.tar.gz">Very old</a> <br/ > +<a href="/124/foo/ooo/foo-1.0.tar.gz">A bit OLD</a> <br /> +<a href="/123/foo/ooo/foo-2.0.tar.gz">Latest</a> <br /> +<a href="/325/foo/ooo/foo-0.0.tar.gz.sig">Very old sig</a> <br/ > +<a href="/424/foo/ooo/foo-1.0.tar.gz.sig">A bit OLD sig</a> <br /> +<a href="/523/foo/ooo/foo-2.0.tar.gz.sig">Latest sig</a> <br /> +</body> +<html> +END + elif [ "$SIGMODE" = "SELF" ]; then + ln -sf ../../../$POOLPATH/foo-0.0.tar.gz.gpg "$TEMP_PKG_DIR"/$REPOPATH/325/foo/ooo/foo-0.0.tar.gz.gpg + ln -sf ../../../$POOLPATH/foo-1.0.tar.gz.gpg "$TEMP_PKG_DIR"/$REPOPATH/424/foo/ooo/foo-1.0.tar.gz.gpg + ln -sf ../../../$POOLPATH/foo-2.0.tar.gz.gpg "$TEMP_PKG_DIR"/$REPOPATH/523/foo/ooo/foo-2.0.tar.gz.gpg + cat <<END > "$TEMP_PKG_DIR"/$REPOPATH/index.html +<html> +<head> + <meta charset="utf-8"> +</head> +<body> +<a href="/125/foo/ooo/foo-0.0.tar.gz">Very old</a> <br/ > +<a href="/124/foo/ooo/foo-1.0.tar.gz">A bit OLD</a> <br /> +<a href="/123/foo/ooo/foo-2.0.tar.gz">Latest</a> <br /> +<a href="/325/foo/ooo/foo-0.0.tar.gz.gpg">Very old sig</a> <br/ > +<a href="/424/foo/ooo/foo-1.0.tar.gz.gpg">A bit OLD sig</a> <br /> +<a href="/523/foo/ooo/foo-2.0.tar.gz.gpg">Latest sig</a> <br /> +</body> +<html> +END + fi +} + +sitePrWebNonNative() { + siteNonNative + cat <<END > "$TEMP_PKG_DIR"/$REPOPATH/index.html +<html> +<head> + <meta charset="utf-8"> +</head> +<body> +<a href="/0.0/boo/xxx/boo-0.0.tar.gz">Very old</a> <br/ > +<a href="/1.0/boo/xxx/boo-1.0.tar.gz">A bit OLD</a> <br /> +<a href="/2.0/boo/xxx/boo-2.0.tar.gz">Latest</a> <br /> +</body> +<html> +END +} + +siteWebNonNativeLarge() { + makeUpstreamTar foo 19990101 gz non-native + makeUpstreamTar foo 20000101 gz non-native + makeUpstreamTar foo 20010101 gz non-native + mkdir -p $REPOPATH/0.0/foo/ooo/ + mkdir -p $REPOPATH/1.0/foo/ooo/ + mkdir -p $REPOPATH/2.0/foo/ooo/ + ln -sf ../../../$POOLPATH/foo-19990101.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/0.0/foo/ooo/foo-19990101.tar.gz + ln -sf ../../../$POOLPATH/foo-20000101.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/1.0/foo/ooo/foo-20000101.tar.gz + ln -sf ../../../$POOLPATH/foo-20010101.tar.gz "$TEMP_PKG_DIR"/$REPOPATH/2.0/foo/ooo/foo-20010101.tar.gz + cat <<END > "$TEMP_PKG_DIR"/$REPOPATH/index.html +<html> +<head> + <meta charset="utf-8"> +</head> +<body> +<a href="/0.0/foo/ooo/foo-19990101.tar.gz">Very old</a> <br/ > +<a href="/1.0/foo/ooo/foo-20000101.tar.gz">A bit OLD</a> <br /> +<a href="/2.0/foo/ooo/foo-20010101.tar.gz">Latest</a> <br /> +</body> +<html> +END +} + +siteXmlNonNative() { + siteNonNative + cat <<END > "$TEMP_PKG_DIR"/$REPOPATH/index.html +<html> +<head> + <meta charset="utf-8"> +</head> +<body> +<Key>/0.0/foo/ooo/foo-0.0.tar.gz</Key> <br/ > +<Key>/1.0/foo/ooo/foo-1.0.tar.gz</Key> <br /> +<Key>/2.0/foo/ooo/foo-2.0.tar.gz</Key> <br /> +</body> +<html> +END +} + +siteWebNonNativeMUT() { + siteNonNative foo + siteNonNative bar EXTRA + siteNonNative baz EXTRA + cat <<END > "$TEMP_PKG_DIR"/$REPOPATH/index.html +<html> +<head> + <meta charset="utf-8"> +</head> +<body> +<a href="/0.0/foo/ooo/foo-0.0.tar.gz">Very old</a> <br/ > +<a href="/1.0/foo/ooo/foo-1.0.tar.gz">A bit OLD</a> <br /> +<a href="/2.0/foo/ooo/foo-2.0.tar.gz">Latest</a> <br /> +<a href="/2.0/foo/ooo/foo-2.0.tar.gz.asc">Latest sig</a> <br /> +<a href="/0.0/bar/ooo/bar-0.0.tar.gz">Very old</a> <br/ > +<a href="/1.0/bar/ooo/bar-1.0.tar.gz">A bit OLD</a> <br /> +<a href="/2.0/bar/ooo/bar-2.0.tar.gz">Latest</a> <br /> +<a href="/3.0/bar/ooo/bar-3.0.tar.gz">OOPS Latest</a> <br /> +<a href="/3.0/bar/ooo/bar-3.0.tar.gz.asc">Latest sig</a> <br /> +<a href="/0.0/baz/ooo/baz-0.0.tar.gz">Very old</a> <br/ > +<a href="/1.0/baz/ooo/baz-1.0.tar.gz">A bit OLD</a> <br /> +<a href="/2.0/baz/ooo/baz-2.0.tar.gz">Latest</a> <br /> +<a href="/3.0/baz/ooo/baz-3.0.tar.gz">OOPS Latest</a> <br /> +<a href="/3.0/baz/ooo/baz-3.0.tar.gz.asc">Latest sig</a> <br /> +</body> +<html> +END +} + +siteWebNonNativeGetOnlyHref() { + siteNonNative foo + cat <<END > "$TEMP_PKG_DIR"/$REPOPATH/index.html +<html> +<head> + <meta charset="utf-8"> +</head> +<body> +<a href="/0.0/foo/ooo/foo-0.0.tar.gz">Very old</a> <br/ > +<a href="/1.0/bar/ooo/foo-1.0.tar.gz">A bit OLD</a> <br /> +<a href="/2.0/foo/ooo/foo-2.0.tar.gz" data-foobar-href="">Latest</a> <br /> +<aueu href="/2.0/foo/ooo/foo-3.0.tar.gz" data-foobar-href="">Nothing here</a> <br /> +</body> +<html> +END +} + +# test a watch files + +### VERSION3 ### +# version locking calls suffer changes due to uupdate calling differences + +# test --download-current-version +testWatch3WebNonNativeDlCurrent() { + WATCHVER=3 + XCOMMAND="$COMMAND --download-current-version" + WATCHLINE='@@@url@@@/ (?:.*)/foo-([\.\d]+).tar.gz debian uupdate' + helperWatch siteWebNonNative 1.0 1.0 +} + +# test --download-version +testWatch3WebNonNativeDlUversion() { + WATCHVER=3 + XCOMMAND="$COMMAND --download-version 0.0" + WATCHLINE='@@@url@@@/ (?:.*)/foo-([\.\d]+).tar.gz debian uupdate' + helperWatch siteWebNonNative 1.0 0.0 +} + +# test --download-debversion uupdate +testWatch3WebNonNativeDlDversion() { + WATCHVER=3 + XCOMMAND="$COMMAND --download-debversion 0.0-1" + WATCHLINE='@@@url@@@/ (?:.*)/foo-([\.\d]+).tar.gz debian uupdate' + helperWatch siteWebNonNative 1.0 0.0 +} + +### VERSION 4 ### +# standard tests + +# test native package w/o uupdate, bare HTTP server in normal order +testWatch4Native() { + WATCHVER=4 + WATCHLINE='@@@url@@@/([\.\d]+)/(.+)/(.+)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian' + helperWatch siteNative +} + +# test non-native package with uupdate, bare HTTP server in normal order +testWatch4NonNative() { + WATCHVER=4 + WATCHLINE='@@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteNonNative +} + +# test non-native package with uupdate, bare HTTP server with dirversionmangle +testWatch4NonNativeDMangle() { + WATCHVER=4 + WATCHLINE='opts="dirversionmangle=s/^\d*[13579]\./0~$&/, uversionmangle=s/^\d*[13579]\./0~$&/" @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch "siteNonNative foo EXTRA" +} + +# ... and without dirversionmangle, should return version 3 +testWatch4NonNativeDMangleWithoutD() { + WATCHVER=4 + WATCHLINE='@@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch "siteNonNative foo EXTRA" 1.0 3.0 +} + +# test non-native package with uupdate, bare HTTP server with dirversionmangle and base +testWatch4NonNativeDMangleB() { + WATCHVER=4 + WATCHLINE='opts="dirversionmangle=s/^\d*[13579]\./0~$&/, uversionmangle=s/^\d*[13579]\./0~$&/" @@@url@@@([\.\d]+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch "siteWebNonNativeRecWithBase foo EXTRA" +} + +# ... and without dirversionmangle, should return version 3 +testWatch4NonNativeDMangleBWithoutD() { + WATCHVER=4 + WATCHLINE='@@@url@@@([\.\d]+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch "siteWebNonNativeRecWithBase foo EXTRA" 1.0 3.0 +} + +# test 3 parameter watch line +testWatch4WebNative() { + WATCHVER=4 + WATCHLINE='@@@url@@@ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian' + helperWatch siteWebNative +} + +# test normal web page +testWatch4WebNonNative() { + WATCHVER=4 + helperWatch +} + +# test normal web page (Files-exclude) +testWatch4WebNonNativeFE() { + MGZREPACK=xz + FILEEXCLUDE=1 + WATCHVER=4 + helperWatch +} + +# test normal web page (file path reverse order) +testWatch4WebNonNativeR() { + WATCHVER=4 + helperWatch siteWebNonNativeR +} + +# test for downloadurlmangle and filenamemangle for tricky web page +testWatch4PrWebNonNative() { + WATCHVER=4 + WATCHLINE='opts="downloadurlmangle = s%boo/xxx%@PACKAGE@/ooo% ; s%boo-%@PACKAGE@-%, \ + filenamemangle = s%.*boo-(.*)%@PACKAGE@-$1% " \ + @@@url@@@/ (?:.*)/boo@ANY_VERSION@@ARCHIVE_EXT@ \ + debian uupdate' + helperWatch sitePrWebNonNative +} + +# test --download-current-version +testWatch4NonNativeDlCurrent() { + WATCHVER=4 + XCOMMAND="$COMMAND --download-current-version" + WATCHLINE='@@@url@@@/([\d\.]+)/@PACKAGE@/ooo/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteNonNative 1.0 1.0 +} + +# test --download-version +testWatch4NonNativeDlUversion() { + WATCHVER=4 + XCOMMAND="$COMMAND --download-version 0.0" + WATCHLINE='@@@url@@@/([\d\.]+)/@PACKAGE@/ooo/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteNonNative 1.0 0.0 +} + +# test --download-debversion uupdate +testWatch4NonNativeDlDversion() { + WATCHVER=4 + XCOMMAND="$COMMAND --download-debversion 0.0-1" + WATCHLINE='@@@url@@@/([\d\.]+)/@PACKAGE@/ooo/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteNonNative 1.0 0.0 +} + +# test --download-current-version +testWatch4WebNonNativeDlCurrent() { + WATCHVER=4 + XCOMMAND="$COMMAND --download-current-version" + WATCHLINE='@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteWebNonNative 1.0 1.0 +} + +# test --download-version +testWatch4WebNonNativeDlUversion() { + WATCHVER=4 + XCOMMAND="$COMMAND --download-version 0.0" + WATCHLINE='@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteWebNonNative 1.0 0.0 +} + +# test --download-debversion uupdate +testWatch4WebNonNativeDlDversion() { + WATCHVER=4 + XCOMMAND="$COMMAND --download-debversion 0.0-1" + WATCHLINE='@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteWebNonNative 1.0 0.0 +} + +# Debian version is 0.19990101 for future proof while upstream is 19990101 +testWatch4WebNonNativeLarge() { + WATCHVER=4 + WATCHLINE='opts=" dversionmangle = s/0\.(.*)/$1/ , \ + oversionmangle = s/(.*)/0.$1/" \ + @@@url@@@ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteWebNonNativeLarge 20000101 20010101 0. +} + +# test for pagemangle +testWatch4XmlNonNative() { + WATCHVER=4 + WATCHLINE='opts="pagemangle = \ + s%<Key>([^<]*)</Key>%<Key><a href=\"$1\">$1</a></Key>%g" \ + @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteXmlNonNative +} + +# test user-agent string setting via opts= +testWatch4WebNonNativeUA() { + WATCHVER=4 + KEYMODE=BIN + USERAGENT="foo/bar; baz:12,3.45" + WATCHLINE='opts="useragent= '$USERAGENT' "'" \ +"'@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatchUA + unset USERAGENT +} + +# test repack and compression +testWatch4WebNonNativeBZ2() { + WATCHVER=4 + WATCHLINE='opts=repack,compression=bz2 @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + GZREPACK=bz2 + MGZREPACK=bz2 + helperWatch + unset GZREPACK +} + +# test repack and compression +testWatch4WebNonNativeXZ() { + MGZREPACK=xz + WATCHVER=4 + WATCHLINE='opts=repack,compression=xz @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + GZREPACK=xz + helperWatch + unset GZREPACK +} + +# test spaces everywhere +testWatch4PrWebNonNativeXZ() { + MGZREPACK=xz + WATCHVER=4 + WATCHLINE='opts = "downloadurlmangle = s%boo/xxx%@PACKAGE@/ooo% ; s%boo-%@PACKAGE@-%, \ + filenamemangle = s%.*boo-(.*)%@PACKAGE@-$1% , \ + repack , compression=xz" \ + @@@url@@@/ (?:.*)/boo@ANY_VERSION@@ARCHIVE_EXT@ \ + debian uupdate' + GZREPACK=xz + helperWatch sitePrWebNonNative + unset GZREPACK +} + +# test get strictly href from links and not something like foo-href. See #904578 and MR !25 +testWatchGetOnlyHref() { + WATCHVER=4 + WATCHLINE='@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch siteWebNonNativeGetOnlyHref 1.0 2.0 +} + +### VERSION 4 with sig check ### + +# test normal web page with sig(asc) +testWatch4WebNonNativeSig() { + WATCHVER=4 + WATCHLINE='opts = "pgpsigurlmangle = s%(.*)%$1.asc%" \ + @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch +} + +# test normal web page with sig(asc) with < and > +testWatch4WebNonNativeSigAngleBraket() { + WATCHVER=4 + WATCHLINE='opts = "pgpsigurlmangle = s<(.*)><$1.asc>" \ + @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch +} + +# test normal web page with sig(asc) with < and > with space +testWatch4WebNonNativeSigAngleBraketSpace() { + WATCHVER=4 + WATCHLINE='opts = "pgpsigurlmangle = s<(.*)> <$1.asc>" \ + @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch +} + +# test normal web page with sig(asc) with < and > with tab +testWatch4WebNonNativeSigAngleBraketTab() { + WATCHVER=4 + WATCHLINE='opts = "pgpsigurlmangle = s<(.*)> <$1.asc>" \ + @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch +} + +# test normal web page with sig(asc) with [ and ] +testWatch4WebNonNativeSigSquareBraket() { + WATCHVER=4 + WATCHLINE='opts = "pgpsigurlmangle = s[(.*)][$1.asc]" \ + @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch +} + +# test normal web page with sig(asc) with { and } +testWatch4WebNonNativeSigCurlyBraket() { + WATCHVER=4 + WATCHLINE='opts = "pgpsigurlmangle = s{(.*)}{$1.asc}" \ + @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch +} + +# test normal web page with sig(asc) - auto +testWatch4WebNonNativeSigAuto() { + WATCHVER=4 + WATCHLINE='opts = "pgpmode = auto" \ + @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate' + helperWatch +} + +# test normal web page with sig(bin) (Files-exclude) +testWatch4WebNonNativeFESig() { + MGZREPACK=xz + FILEEXCLUDE=1 + WATCHVER=4 + SIGMODE=BIN + KEYMODE=BIN + WATCHLINE='opts = "pgpsigurlmangle = s%(.*)%$1.sig%" \ + @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ \ + debian uupdate' + helperWatch +} + +# test normal web page with sig (different file path for sig and tar; reverse order) +testWatch4WebNonNativeRSig() { + WATCHVER=4 + WATCHLINE='opts = "pgpmode=next" @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian +opts = "pgpmode=previous" @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@.asc previous uupdate' + helperWatch siteWebNonNativeR +} + +# test normal web page with sig (different file path for sig and tar; reverse order, BIN) +testWatch4WebNonNativeRSigBIN() { + WATCHVER=4 + SIGMODE=BIN + WATCHLINE='opts = "pgpmode=next" @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian +opts = "pgpmode=previous" @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@.sig previous uupdate' + helperWatch siteWebNonNativeR +} + +# test normal web page with sig (different file path for sig and tar; reverse order, BIN BIN) +testWatch4WebNonNativeRSigBINiBIN() { + WATCHVER=4 + SIGMODE=BIN + KEYMODE=BIN + WATCHLINE='opts = "pgpmode=next" @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian +opts = "pgpmode=previous" @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@.sig previous uupdate' + helperWatch siteWebNonNativeR +} + +# test normal web page with sig (self) +testWatch4WebNonNativeSelfSig() { + WATCHVER=4 + SIGMODE=SELF + WATCHLINE='opts = "pgpmode = self" \ + @@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@.gpg debian uupdate' + helperWatch siteWebNonNativeR +} + +### VERSION 4 only ### + +# test normal web page (MUT) +testWatch4WebNonNativeMUT() { + MGZREPACK=xz + WATCHVER=4 + COMPONENTS="bar baz" + SIGMODE=BIN + FILEEXCLUDE=2 + WATCHLINE=' +opts=" pgpsigurlmangle=s/$/.sig/" @@@url@@@ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian +opts="component=bar,pgpsigurlmangle=s/$/.sig/" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@ same +opts="component=baz,pgpsigurlmangle=s/$/.sig/" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@ same uupdate' + helperWatch siteWebNonNativeMUT +} + +# test normal web page (MUT with O main) +testWatch4WebNonNativeMUT0() { + WATCHVER=4 + COMPONENTS="foo bar baz" + FILEEXCLUDE=3 + WATCHLINE=' +opts="component=foo,pgpsigurlmangle=s/$/.asc/" @@@url@@@ (?:.*)/foo@ANY_VERSION@@ARCHIVE_EXT@ debian +opts="component=bar,pgpsigurlmangle=s/$/.asc/" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@ same +opts="component=baz,pgpsigurlmangle=s/$/.asc/" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@ same uupdate' + helperWatch siteWebNonNativeMUT +} + +# Group test without signatures +testWatch4WebNonNativeGroup() { + WATCHVER=4 + COMPONENTS="bar baz" + FILEEXCLUDE=3 + UVERSION=2.0 + CMPVERSION=3.0 + GZREPACK=gz + WATCHLINE=' +opts="pgpmode=none" @@@url@@@ (?:.*)/foo@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=bar,pgpmode=none" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=baz,pgpmode=none" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@ group' + helperWatch siteWebNonNativeMUT 1.0 2.0+~3.0+~3.0 +} + +# Group test with repack suffix +testWatch4WebNonNativeGroupRepackSuffix() { + WATCHVER=4 + COMPONENTS="bar baz" + FILEEXCLUDE=3 + UVERSION=2.0 + CMPVERSION=3.0 + GZREPACK=gz + WATCHLINE=' +opts="pgpmode=none" @@@url@@@ (?:.*)/foo@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=bar,repacksuffix=+ds,pgpmode=none" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=baz,pgpmode=none" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@ group' + helperWatch siteWebNonNativeMUT 1.0 2.0+~3.0+ds+~3.0 +} + +# Group test with pgpsigurlmangle +testWatch4WebNonNativeGroupSigned() { + WATCHVER=4 + COMPONENTS="bar baz" + FILEEXCLUDE=3 + UVERSION=2.0 + CMPVERSION=3.0 + GZREPACK=gz + WATCHLINE=' +opts="pgpsigurlmangle=s/$/.asc/" @@@url@@@ (?:.*)/foo@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=bar,pgpsigurlmangle=s/$/.asc/" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=baz,pgpsigurlmangle=s/$/.asc/" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@ group' + helperWatch siteWebNonNativeMUT 1.0 2.0+~3.0+~3.0 +} + +# Group test with pgpmode next/previous +testWatch4WebNonNativeGroupSignedNext() { + WATCHVER=4 + COMPONENTS="bar baz" + FILEEXCLUDE=3 + UVERSION=2.0 + CMPVERSION=3.0 + GZREPACK=gz + SIGMODE=ASC + WATCHLINE=' +opts="pgpmode=next" @@@url@@@ (?:.*)/foo@ANY_VERSION@@ARCHIVE_EXT@ group +opts="pgpmode=previous" @@@url@@@/ (?:.*)/foo@ANY_VERSION@@ARCHIVE_EXT@.asc previous +opts="component=bar,pgpmode=next" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=bar,pgpmode=previous" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@.asc previous +opts="component=baz,pgpmode=next" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=baz,pgpmode=previous" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@.asc previous' + helperWatch siteWebNonNativeMUT 1.0 2.0+~3.0+~3.0 +} + +testWatch4WebNonNativeGroupWithCompression() { + WATCHVER=4 + COMPONENTS="bar baz" + FILEEXCLUDE=3 + UVERSION=2.0 + CMPVERSION=3.0 + GZREPACK=gz + WATCHLINE=' +opts="pgpmode=none" @@@url@@@ (?:.*)/foo@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=bar,compression=xz,repack,pgpmode=none" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=baz,repack,pgpmode=none" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@ group' + helperWatch siteWebNonNativeMUT 1.0 2.0+~3.0+~3.0 +} + +testWatch4WebNonNativeGroupWithChecksum1() { + WATCHVER=4 + COMPONENTS="bar baz" + FILEEXCLUDE=3 + UVERSION=2.0 + CMPVERSION=3.0 + GZREPACK=gz + WATCHLINE=' +opts="pgpmode=none" @@@url@@@ (?:.*)/foo@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=bar,compression=xz,repack,pgpmode=none" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=baz,repack,pgpmode=none" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@ checksum' + helperWatch siteWebNonNativeMUT 1.0 2.0+~3.0+~cs3.0 +} + +testWatch4WebNonNativeGroupWithChecksum2() { + WATCHVER=4 + COMPONENTS="bar baz" + FILEEXCLUDE=3 + UVERSION=2.0 + CMPVERSION=3.0 + GZREPACK=gz + WATCHLINE=' +opts="pgpmode=none" @@@url@@@ (?:.*)/foo@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=bar,compression=xz,repack,pgpmode=none" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@ checksum +opts="component=baz,repack,pgpmode=none" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@ checksum' + helperWatch siteWebNonNativeMUT 1.0 2.0+~cs6.0 +} + +testWatch4WebNonNativeGroupWithChecksumAndIgnore() { + WATCHVER=4 + COMPONENTS="bar baz" + FILEEXCLUDE=3 + UVERSION=2.0 + CMPVERSION=3.0 + GZREPACK=gz + WATCHLINE=' +opts="pgpmode=none" @@@url@@@ (?:.*)/foo@ANY_VERSION@@ARCHIVE_EXT@ group +opts="component=bar,compression=xz,repack,pgpmode=none" @@@url@@@ (?:.*)/bar@ANY_VERSION@@ARCHIVE_EXT@ checksum +opts="component=baz,repack,pgpmode=none" @@@url@@@ (?:.*)/baz@ANY_VERSION@@ARCHIVE_EXT@ ignore' + helperWatch siteWebNonNativeMUT 1.0 2.0+~cs3.0 +} + +. shunit2 diff --git a/test/test_uscan_online b/test/test_uscan_online new file mode 100755 index 0000000..34968da --- /dev/null +++ b/test/test_uscan_online @@ -0,0 +1,50 @@ +#!/bin/sh + +# Copyright (C) 2012, Benjamin Drung <bdrung@debian.org> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +set -u + +# Operation mode +if test "${1:-}" = --installed; then + COMMAND="uscan --no-conf" + shift +else + top_srcdir=$(readlink -f "${0%/*}/..") + make -C "$top_srcdir/scripts" uscan mk-origtargz uupdate debchange + PATH="$top_srcdir/scripts:$PATH" + export PATH + PERL5LIB="$top_srcdir/lib" + export PERL5LIB + COMMAND="uscan --no-conf" +fi + +. "${0%/*}/shunit2-helper-functions.sh" + +found() { + runCommand "--report --watchfile ${0%/*}/uscan/$1 --package $2 --upstream-version $3" "$4" "" 0 +} + +testS3Bucket() { + local latest=$(curl -s http://s3.amazonaws.com/rds-downloads | \ + sed 's@\(</[A-Za-z]*>\)@\1\n@g' | grep '<Key>RDSCli-' | \ + sed 's@.*<Key>RDSCli-\([-0-9.]*\)\.zip</Key>.*@\1@g' | \ + sort -n | tail -n 1) + local result="uscan: Newest version of rdscli on remote site is ${latest}, local version is 1.4.007 +uscan: => Newer package available from + http://s3.amazonaws.com/rds-downloads/RDSCli-${latest}.zip" + found "s3bucket" "rdscli" "1.4.007" "$result" +} + +. shunit2 diff --git a/test/test_uscan_svn b/test/test_uscan_svn new file mode 100755 index 0000000..fd60e16 --- /dev/null +++ b/test/test_uscan_svn @@ -0,0 +1,196 @@ +#!/bin/bash + +# Copyright (C) 2018, Xavier <yadd@debian.org> +# 2019-2020, Andrius Merkys <merkys@debian.org> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# On Debian systems, the complete text of the GNU General Public License +# version 3 can be found in the /usr/share/common-licenses/GPL-3 file. + +set -u +#set -x + +DEB_HOST_OS="$(dpkg-architecture -qDEB_HOST_ARCH_OS)" +if [ "$DEB_HOST_OS" = "kfreebsd" ]; then + # kbsd has a non-working semaphore, that is needed here. + echo "This test is not supported on $(dpkg-architecture -qDEB_HOST_ARCH), skipping" + exit 0 +fi + +TESTTYPE=Svn +. ./lib_test_uscan + +COMMAND="chronic_sh uscan --no-conf --compression=xz --dehs" + +# prevent the local from messing with this test +export HOME="" +export XDG_CONFIG_HOME="" + +# comment out for debug +#COMMAND="$COMMAND --verbose" +#COMMAND="$COMMAND --debug" + +cleanup(){ + rm -rf "$TEMP_PKG_DIR" +} + +spawnSvnRepo(){ + mkdir -p "$TEMP_PKG_DIR/repo" + (cd "$TEMP_PKG_DIR/repo" || exit 1 + chronic_sh svnadmin create .) + mkdir -p "$TEMP_PKG_DIR/working-copy" + (cd "$TEMP_PKG_DIR/working-copy" || exit 1 + chronic_sh svn checkout "file:///$TEMP_PKG_DIR/repo" . + chronic_sh mkdir trunk tags + touch trunk/changelog trunk/file.c + chronic_sh svn add trunk tags + chronic_sh svn commit -m 'Init' + export TZ=UTC + for version in 1.0 2.0; do + echo "# Version $version" >> trunk/file.c + cat >> trunk/changelog <<END +Version $version + +END + chronic_sh faketime -f '2000-01-01 12:34:56' svn commit -m "Releasing $version" + chronic_sh faketime -f '2000-01-01 12:34:56' svn copy ^/trunk "^/tags/v$version" -m "Version $version" + done) +} + +trap cleanup EXIT + +containsName(){ + echo "$1" | grep -F -q "$2" + echo $? +} + +# shellcheck source=shunit2-helper-functions.sh +. "${0%/*}/shunit2-helper-functions.sh" + +PKG=foo + +makeDebianDir() { + WATCHARGS=$1 + TEMP_PKG_DIR=$(mktemp -d --tmpdir="$SHUNIT_TMPDIR" uscan_svn.XXXXXX) + if [ -z "$TEMP_PKG_DIR" ]; then + echo "Failed to create temporary directory" >&2 + exit 1 + fi + mkdir -p "$TEMP_PKG_DIR/$PKG/debian/source" + spawnSvnRepo + + cat <<END > "$TEMP_PKG_DIR/$PKG/debian/watch" +version=4 +opts="mode=svn,$WATCHARGS" \ +file:///$TEMP_PKG_DIR/repo/tags v([\\d\\.]+)\/ debian +END + + cat <<END > "$TEMP_PKG_DIR/$PKG/debian/changelog" +$PKG (0-1) unstable; urgency=low + + * Initial release + + -- Joe Developer <jd@debian.org> Mon, 02 Nov 2013 22:21:31 -0100 +END + echo '3.0 (quilt)' > "$TEMP_PKG_DIR/$PKG/debian/source/format" +} + +makeDebianDirHead() { + WATCHARGS=$1 + makeDebianDir "$WATCHARGS" + cat <<END > "$TEMP_PKG_DIR/$PKG/debian/watch" +version=4 +opts="mode=svn,$WATCHARGS" \ +file:///$TEMP_PKG_DIR/repo/trunk HEAD +END +} + +helperLaunch() { + WATCHARGS=$1 + ARG="${2:-}" + if test "$ARG" = "HEAD"; then + makeDebianDirHead "$WATCHARGS" + else + makeDebianDir "$WATCHARGS" + fi + ( cd "$TEMP_PKG_DIR/$PKG" || exit 1 ; $COMMAND --watchfile=debian/watch ) + assertEquals "uscan: exit_code!=0 but exit_code=0" "0" "$?" +} + +helperLaunchFail() { + WATCHARGS=$1 + ARG="${2:-}" + if test "$ARG" = "HEAD"; then + makeDebianDirHead "$WATCHARGS" + else + makeDebianDir "$WATCHARGS" + fi + # discard output as it's expected to fail + ( cd "$TEMP_PKG_DIR/$PKG" || exit 1 ; $COMMAND --watchfile=debian/watch > /dev/null) + assertEquals "uscan: exit_code!=2 but exit_code=2" "2" "$?" +} + +testSvn() { + helperLaunch "pgpmode=none" + TARBALL="${PKG}_2.0.orig.tar.xz" + CHECKSUM=$(sha1sum "$TEMP_PKG_DIR/${PKG}-2.0.tar.xz" | awk '{print $1}') + assertTrue 'downloaded tarfile not present' "[ -f '$TEMP_PKG_DIR/${PKG}-2.0.tar.xz' ]" + assertTrue 'pristine tarball is not created' "[ -f '$TEMP_PKG_DIR/$TARBALL' ]" + assertTrue 'pristine tarball is a symlink' "[ -L '$TEMP_PKG_DIR/$TARBALL' ]" + if [ "$CHECKSUM" != 'bd4a60786013848e402bcf20db211fd465afeda5' ]; then + set -x + echo "Copying the faulty tarball to the artefact directory, if available..." + if [ -n "${AUTOPKGTEST_ARTIFACTS:-}" ] && [ -d "$AUTOPKGTEST_ARTIFACTS" ]; then + cp -v "$TEMP_PKG_DIR/${PKG}-2.0.tar.xz" "$AUTOPKGTEST_ARTIFACTS"/ + fi + set +x + fi + assertTrue 'checksums do not match' "[ '${CHECKSUM}' = 'bd4a60786013848e402bcf20db211fd465afeda5' ]" + cleanup +} + +testSvnPgpmodeDefault() { + helperLaunch "pgpmode=default" + TARBALL="${PKG}_2.0.orig.tar.xz" + assertTrue 'downloaded tarfile not present' "[ -f '$TEMP_PKG_DIR/${PKG}-2.0.tar.xz' ]" + assertTrue 'pristine tarball is not created' "[ -f '$TEMP_PKG_DIR/$TARBALL' ]" + assertTrue 'pristine tarball is a symlink' "[ -L '$TEMP_PKG_DIR/$TARBALL' ]" + cleanup +} + +testSvnPgpmodeNext() { + helperLaunchFail "pgpmode=next" + cleanup +} + +testSvnHead() { + helperLaunch "pgpmode=none" HEAD + ORIG="$TEMP_PKG_DIR/foo_0.0~svn4.orig.tar.xz" + UPSTREAM="$TEMP_PKG_DIR/foo-0.0~svn4.tar.xz" + assertTrue 'downloaded tarfile not present' "[ -f '$UPSTREAM' ]" + assertTrue 'pristine tarball is not created' "[ -f '$ORIG' ]" + assertTrue 'pristine tarball is a symlink' "[ -L '$ORIG' ]" + cleanup +} + +testSvnHeadMangle() { + helperLaunch "pgpmode=none,uversionmangle=s/^[^~]+/1.23.45/" HEAD + ORIG="$TEMP_PKG_DIR/foo_1.23.45~svn4.orig.tar.xz" + UPSTREAM="$TEMP_PKG_DIR/foo-1.23.45~svn4.tar.xz" + assertTrue 'downloaded tarfile not present' "[ -f '$UPSTREAM' ]" + assertTrue 'pristine tarball is not created' "[ -f '$ORIG' ]" + assertTrue 'pristine tarball is a symlink' "[ -L '$ORIG' ]" + cleanup +} + +# shellcheck disable=SC1091 +. shunit2 |