> 0008-Improve-debian-tests-build-with-variables.patch
>  * Although it makes sense, would it be possible to provide patches
> implementing the same approach for the other tests too?

A new suggestion is attached.
>From f0cbf09c046174e41e8706bcd680c79b6e7b7794 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <[email protected]>
Subject: Reduce redundancy in source code for tests

--- a/debian/tests/build
+++ b/debian/tests/build
@@ -1,39 +1,21 @@
 #!/bin/sh
-set -e
+set -Ceu
+. debian/tests/debomatictest.sh
 
+pkg=hello
+hostarchitecture=None
+version=$(debomatictest_version $pkg)
 cd "$AUTOPKGTEST_TMP"
+mkdir incoming
 
-sed -i 's/modules: True/modules: False/' /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "modules: False" || exit 1
-sed -i "s|incoming: /incoming|incoming: $AUTOPKGTEST_TMP/incoming|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "incoming: $AUTOPKGTEST_TMP/incoming" || exit 1
-sed -i "s|loglevel: info|loglevel: debug|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "loglevel: debug" || exit 1
+debomatictest_clean
 
-mkdir -p $HOME/.dput.d/profiles
-cat > $HOME/.dput.d/profiles/local.json << EOF
-{
-    "meta": "debomatic",
-    "incoming": "$AUTOPKGTEST_TMP/incoming",
-    "method": "local",
-    "check-debs": {
-        "skip": true
-    }
-}
-EOF
+debomatictest_dget
+debomatictest_build_source
+debomatictest_dput
 
-mkdir "$AUTOPKGTEST_TMP"/incoming
-version=$(rmadison -u debian -a source -s unstable hello | cut -d"|" -f 2 | xargs)
-upstream=$(echo $version | cut -d"-" -f1 | xargs)
-component=$(rmadison -u debian -a source -s unstable hello | cut -d"|" -f 3 | cut -d"/" -f2 | sed 's/unstable/main/' | xargs)
-dget -u http://deb.debian.org/debian/pool/$component/h/hello/hello_$version.dsc
-cd hello-$upstream/
-debuild -S -d -uc -us
-dput local ../hello_"$version"_source.changes
-debomatic -c /etc/debomatic/debomatic.conf -o "$AUTOPKGTEST_TMP"/incoming/hello_"$version"_source.changes -i
-cat "$AUTOPKGTEST_TMP"/incoming/unstable/pool/hello_$version/hello_$version.buildlog
-grep "$AUTOPKGTEST_TMP"/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "Status: successful" || exit 1
+debomatictest_debomatic incoming/${pkg}_${version}_source.changes
 
-rm -fr /etc/schroot/chroot.d/unstable-*-debomatic-*
-rm -fr /etc/sbuild/chroot/unstable-*-debomatic
-rm -fr /$AUTOPKGTEST_TMP/incoming/unstable/unstable
+debomatictest_check_log
+
+debomatictest_clean
--- a/debian/tests/command-binnmu
+++ b/debian/tests/command-binnmu
@@ -1,26 +1,22 @@
 #!/bin/sh
-set -e
+set -Ceu
+. debian/tests/debomatictest.sh
 
+pkg=hello
+hostarchitecture=None
+version=$(debomatictest_version $pkg)
 cd "$AUTOPKGTEST_TMP"
+mkdir incoming
 
-sed -i 's/modules: True/modules: False/' /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "modules: False" || exit 1
-sed -i "s|incoming: /incoming|incoming: $AUTOPKGTEST_TMP/incoming|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "incoming: $AUTOPKGTEST_TMP/incoming" || exit 1
-sed -i "s|loglevel: info|loglevel: debug|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "loglevel: debug" || exit 1
+debomatictest_clean
 
-mkdir "$AUTOPKGTEST_TMP"/incoming
-version=$(rmadison -u debian -a source -s unstable hello | cut -d"|" -f 2 | xargs)
-echo "binnmu hello_$version unstable 1 \"Deb-o-Matic test suite\" Luca Falavigna <[email protected]>" > "$AUTOPKGTEST_TMP"/incoming/binnmu.commands
-debomatic -c /etc/debomatic/debomatic.conf -o /$AUTOPKGTEST_TMP/incoming/binnmu.commands -i
-cat /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog
-grep /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "Status: successful" || exit 1
-grep /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "Maintainer: Luca Falavigna <[email protected]>" || exit 1
-grep /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "hello ($version+b1) unstable" || exit 1
-grep /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "* Binary-only non-maintainer upload for" || exit 1
-grep /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "* Deb-o-Matic test suite" || exit 1
+commands=incoming/binnmu.commands
+echo "binnmu ${pkg}_$version unstable 1 \"Deb-o-Matic test suite\" Luca Falavigna <[email protected]>" > $commands
+debomatictest_debomatic $commands
 
-rm -fr /etc/schroot/chroot.d/unstable-*-debomatic-*
-rm -fr /etc/sbuild/chroot/unstable-*-debomatic
-rm -fr /$AUTOPKGTEST_TMP/incoming/unstable/unstable
+debomatictest_check_log 'Maintainer: Luca Falavigna <[email protected]>' \
+                        "$pkg ($version+b1) unstable" \
+                        '* Binary-only non-maintainer upload for' \
+                        '* Deb-o-Matic test suite'
+
+debomatictest_clean
--- a/debian/tests/command-builddep
+++ b/debian/tests/command-builddep
@@ -1,24 +1,20 @@
 #!/bin/sh
-set -e
+set -Ceu
+. debian/tests/debomatictest.sh
 
+pkg=hello
+hostarchitecture=None
+version=$(debomatictest_version $pkg)
 cd "$AUTOPKGTEST_TMP"
+mkdir incoming
 
-sed -i 's/modules: True/modules: False/' /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "modules: False" || exit 1
-sed -i "s|incoming: /incoming|incoming: $AUTOPKGTEST_TMP/incoming|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "incoming: $AUTOPKGTEST_TMP/incoming" || exit 1
-sed -i "s|loglevel: info|loglevel: debug|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "loglevel: debug" || exit 1
+debomatictest_clean
 
-mkdir "$AUTOPKGTEST_TMP"/incoming
-version=$(rmadison -u debian -a source -s unstable hello | cut -d"|" -f 2 | xargs)
-bdversion=$(rmadison -u debian -a source -s unstable lintian | cut -d"|" -f 2 | xargs)
-echo "builddep hello_$version unstable lintian (>= $bdversion)" > "$AUTOPKGTEST_TMP"/incoming/builddep.commands
-debomatic -c /etc/debomatic/debomatic.conf -o /$AUTOPKGTEST_TMP/incoming/builddep.commands -i
-cat /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog
-grep /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "Status: successful" || exit 1
-grep /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "Setting up lintian ($bdversion)" || exit 1
+commands=incoming/builddep.commands
+bdversion=$(debomatictest_version lintian)
+echo "builddep ${pkg}_$version unstable lintian (>= $bdversion)" > $commands
+debomatictest_debomatic $commands
 
-rm -fr /etc/schroot/chroot.d/unstable-*-debomatic-*
-rm -fr /etc/sbuild/chroot/unstable-*-debomatic
-rm -fr /$AUTOPKGTEST_TMP/incoming/unstable/unstable
+debomatictest_check_log "Setting up lintian ($bdversion)"
+
+debomatictest_clean
--- a/debian/tests/command-porter
+++ b/debian/tests/command-porter
@@ -1,23 +1,19 @@
 #!/bin/sh
-set -e
+set -Ceu
+. debian/tests/debomatictest.sh
 
+pkg=hello
+hostarchitecture=None
+version=$(debomatictest_version $pkg)
 cd "$AUTOPKGTEST_TMP"
+mkdir incoming
 
-sed -i 's/modules: True/modules: False/' /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "modules: False" || exit 1
-sed -i "s|incoming: /incoming|incoming: $AUTOPKGTEST_TMP/incoming|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "incoming: $AUTOPKGTEST_TMP/incoming" || exit 1
-sed -i "s|loglevel: info|loglevel: debug|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "loglevel: debug" || exit 1
+debomatictest_clean
 
-mkdir "$AUTOPKGTEST_TMP"/incoming
-version=$(rmadison -u debian -a source -s unstable hello | cut -d"|" -f 2 | xargs)
-echo "porter hello_$version unstable Luca Falavigna <[email protected]>" > "$AUTOPKGTEST_TMP"/incoming/porter.commands
-debomatic -c /etc/debomatic/debomatic.conf -o /$AUTOPKGTEST_TMP/incoming/porter.commands -i
-cat /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog
-grep /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "Status: successful" || exit 1
-grep /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "Maintainer: Luca Falavigna <[email protected]>" || exit 1
+commands=incoming/porter.commands
+echo "porter ${pkg}_$version unstable Luca Falavigna <[email protected]>" > $commands
+debomatictest_debomatic $commands
 
-rm -fr /etc/schroot/chroot.d/unstable-*-debomatic-*
-rm -fr /etc/sbuild/chroot/unstable-*-debomatic
-rm -fr /$AUTOPKGTEST_TMP/incoming/unstable/unstable
+debomatictest_check_log 'Maintainer: Luca Falavigna <[email protected]>'
+
+debomatictest_clean
--- a/debian/tests/command-rebuild
+++ b/debian/tests/command-rebuild
@@ -1,22 +1,19 @@
 #!/bin/sh
-set -e
+set -Ceu
+. debian/tests/debomatictest.sh
 
+pkg=hello
+hostarchitecture=None
+version=$(debomatictest_version $pkg)
 cd "$AUTOPKGTEST_TMP"
+mkdir incoming
 
-sed -i 's/modules: True/modules: False/' /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "modules: False" || exit 1
-sed -i "s|incoming: /incoming|incoming: $AUTOPKGTEST_TMP/incoming|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "incoming: $AUTOPKGTEST_TMP/incoming" || exit 1
-sed -i "s|loglevel: info|loglevel: debug|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "loglevel: debug" || exit 1
+debomatictest_clean
 
-mkdir "$AUTOPKGTEST_TMP"/incoming
-version=$(rmadison -u debian -a source -s unstable hello | cut -d"|" -f 2 | xargs)
-echo "rebuild hello_$version unstable" > "$AUTOPKGTEST_TMP"/incoming/rebuild.commands
-debomatic -c /etc/debomatic/debomatic.conf -o /$AUTOPKGTEST_TMP/incoming/rebuild.commands -i
-cat /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog
-grep /$AUTOPKGTEST_TMP/incoming/unstable/pool/hello_$version/hello_$version.buildlog -e "Status: successful" || exit 1
+commands=incoming/rebuild.commands
+echo "rebuild ${pkg}_$version unstable" > $commands
+debomatictest_debomatic $commands
 
-rm -fr /etc/schroot/chroot.d/unstable-*-debomatic-*
-rm -fr /etc/sbuild/chroot/unstable-*-debomatic
-rm -fr /$AUTOPKGTEST_TMP/incoming/unstable/unstable
+debomatictest_check_log
+
+debomatictest_clean
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -10,31 +10,10 @@ Depends: debomatic,
          dput-ng
 Restrictions: needs-root, allow-stderr
 
-Tests: command-rebuild
-Depends: debomatic,
-         devscripts,
-         wget,
-         liburi-perl,
-         ca-certificates
-Restrictions: needs-root, allow-stderr
-
-Tests: command-porter
-Depends: debomatic,
-         devscripts,
-         wget,
-         liburi-perl,
-         ca-certificates
-Restrictions: needs-root, allow-stderr
-
 Tests: command-binnmu
-Depends: debomatic,
-         devscripts,
-         wget,
-         liburi-perl,
-         ca-certificates
-Restrictions: needs-root, allow-stderr
-
-Tests: command-builddep
+       command-builddep
+       command-porter
+       command-rebuild
 Depends: debomatic,
          devscripts,
          wget,
--- a/debian/tests/crossbuild
+++ b/debian/tests/crossbuild
@@ -1,55 +1,25 @@
 #!/bin/sh
-set -e
+set -Ceu
+. debian/tests/debomatictest.sh
 
-cd "$AUTOPKGTEST_TMP"
-
-sed -i 's/modules: True/modules: False/' /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "modules: False" || exit 1
-sed -i "s|incoming: /incoming|incoming: $AUTOPKGTEST_TMP/incoming|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "incoming: $AUTOPKGTEST_TMP/incoming" || exit 1
-sed -i "s|loglevel: info|loglevel: debug|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "loglevel: debug" || exit 1
-sed -i "s|crossbuild: False|crossbuild: True|" /etc/debomatic/debomatic.conf
-grep /etc/debomatic/debomatic.conf -e "crossbuild: True" || exit 1
-if [ $(dpkg-architecture -qDEB_HOST_ARCH) = "arm64" ]
-then
-	sed -i "s|hostarchitecture: None|hostarchitecture: amd64|" /etc/debomatic/debomatic.conf
-	grep /etc/debomatic/debomatic.conf -e "hostarchitecture: amd64" || exit 1
+pkg=hello-traditional
+if [ $(dpkg-architecture -qDEB_HOST_ARCH) = arm64 ]; then
+    hostarchitecture=amd64
 else
-	sed -i "s|hostarchitecture: None|hostarchitecture: arm64|" /etc/debomatic/debomatic.conf
-	grep /etc/debomatic/debomatic.conf -e "hostarchitecture: arm64" || exit 1
+    hostarchitecture=arm64
 fi
+version=$(debomatictest_version $pkg)
+cd "$AUTOPKGTEST_TMP"
+mkdir incoming
 
-mkdir -p $HOME/.dput.d/profiles
-cat > $HOME/.dput.d/profiles/local.json << EOF
-{
-    "meta": "debomatic",
-    "incoming": "$AUTOPKGTEST_TMP/incoming",
-    "method": "local",
-    "check-debs": {
-        "skip": true
-    }
-}
-EOF
+debomatictest_clean
 
-mkdir "$AUTOPKGTEST_TMP"/incoming
-version=$(rmadison -u debian -a source -s unstable hello-traditional | cut -d"|" -f 2 | xargs)
-upstream=$(echo $version | cut -d"-" -f1 | xargs)
-component=$(rmadison -u debian -a source -s unstable hello-traditional | cut -d"|" -f 3 | cut -d"/" -f2 | sed 's/unstable/main/' | xargs)
-dget -u http://deb.debian.org/debian/pool/$component/h/hello-traditional/hello-traditional_$version.dsc
-cd hello-traditional-$upstream/
-debuild -S -d -uc -us
-dput local ../hello-traditional_"$version"_source.changes
-debomatic -c /etc/debomatic/debomatic.conf -o "$AUTOPKGTEST_TMP"/incoming/hello-traditional_"$version"_source.changes -i
-cat "$AUTOPKGTEST_TMP"/incoming/unstable/pool/hello-traditional_$version/hello-traditional_$version.buildlog
-grep "$AUTOPKGTEST_TMP"/incoming/unstable/pool/hello-traditional_$version/hello-traditional_$version.buildlog -e "Status: successful" || exit 1
-if [ $(dpkg-architecture -qDEB_HOST_ARCH) = "arm64" ]
-then
-	grep "$AUTOPKGTEST_TMP"/incoming/unstable/pool/hello-traditional_$version/hello-traditional_$version.buildlog -e "hello-traditional_"$version"_amd64.changes:$" || exit 1
-else
-	grep "$AUTOPKGTEST_TMP"/incoming/unstable/pool/hello-traditional_$version/hello-traditional_$version.buildlog -e "hello-traditional_"$version"_arm64.changes:$" || exit 1
-fi
+debomatictest_dget
+debomatictest_build_source
+debomatictest_dput
+
+debomatictest_debomatic incoming/${pkg}_${version}_source.changes
+
+debomatictest_check_log ${pkg}_${version}_$hostarchitecture.changes:
 
-rm -fr /etc/schroot/chroot.d/unstable-*-debomatic-*
-rm -fr /etc/sbuild/chroot/unstable-*-debomatic
-rm -fr /$AUTOPKGTEST_TMP/incoming/unstable/unstable
+debomatictest_clean
--- /dev/null
+++ b/debian/tests/debomatictest.sh
@@ -0,0 +1,81 @@
+# Helper for the debomatic tests in this directory.
+
+debomatictest_version() {
+    rmadison -u debian -a source -s unstable $1 \
+        | cut -d\| -f2 \
+        | xargs
+}
+debomatictest_dget() {
+    local component=$(rmadison -u debian -a source -s unstable $pkg \
+                          | cut -d\| -f3 \
+                          | cut -d/ -f2 \
+                          | sed s/unstable/main/ \
+                          | xargs)
+    local dsc=http://deb.debian.org/debian/pool/$component/h/$pkg/${pkg}_$version.dsc
+    dget -u $dsc
+}
+debomatictest_build_source() {
+    cd $pkg-${version%%-*}
+    debuild -S -d -uc -us
+    cd ..
+}
+debomatictest_dput() {
+    local profiles="$HOME"/.dput.d/profiles
+
+    mkdir -p "$profiles"
+    cat >| "$profiles"/local.json << EOF
+{
+    "meta": "debomatic",
+    "incoming": "$AUTOPKGTEST_TMP/incoming",
+    "method": "local",
+    "check-debs": {
+        "skip": true
+    }
+}
+EOF
+
+    dput local ${pkg}_${version}_source.changes
+}
+debomatictest_debomatic() {
+    local conf=debomatic.conf
+    if [ $hostarchitecture = None ]; then
+        local crossbuild=False
+    else
+        local crossbuild=True
+    fi
+
+    sed /etc/debomatic/debomatic.conf \
+        -e 's/^modules: True$/modules: False/' \
+        -e "s|^incoming: .*|incoming: $AUTOPKGTEST_TMP/incoming|" \
+        -e 's|^loglevel: .*|loglevel: debug|' \
+        -e "s|^crossbuild: .*|crossbuild: $crossbuild|" \
+        -e "s|^hostarchitecture: .*|hostarchitecture: $hostarchitecture|" \
+        > $conf
+    grep -F 'modules: False'                      $conf
+    grep -F "incoming: $AUTOPKGTEST_TMP/incoming" $conf
+    grep -F 'loglevel: debug'                     $conf
+    grep -F "crossbuild: $crossbuild"             $conf
+    grep -F "hostarchitecture: $hostarchitecture" $conf
+
+    debomatic -c $conf -o $1 -i
+}
+debomatictest_check_log() {
+    local log=incoming/unstable/pool/${pkg}_$version/${pkg}_$version.buildlog
+    local line
+
+    cat $log
+
+    for line in 'Status: successful' "$@"; do
+        grep -F "$line" $log
+    done
+}
+debomatictest_clean() {
+    # Remove files created by this test outside AUTOPKGTEST_TMP.
+
+    # This may be useful both before the test (in case another test
+    # has just failed without cleaning) and after the test (in case
+    # the test is not run in a throwable chroot).
+
+    rm -fr /etc/schroot/chroot.d/unstable-*-debomatic-* \
+           /etc/sbuild/chroot/unstable-*-debomatic
+}

Reply via email to