Package: gzip
Version: 1.14-1~exp2ubuntu1
Severity: wishlist
X-Debbugs-Cc: [email protected]

Dear Maintainer,

Right now, the autopkgtests for gzip are very simple, just a roundtrip 
compress/decompress
of an extremely trivial file. The attached patch (forwarding upstream from 
Ubuntu) adds a
some more tests for more advanced usage (mutlifile (re)compression and envar 
support).

-- System Information:
Debian Release: forky/sid
  APT prefers resolute-updates
  APT policy: (500, 'resolute-updates'), (500, 'resolute-security'), (500, 
'resolute')
Architecture: amd64 (x86_64)

Kernel: Linux 7.0.0-15-generic (SMP w/24 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages gzip depends on:
ii  libc6  2.43-2ubuntu2

gzip recommends no packages.

Versions of packages gzip suggests:
ii  less  668-1build1

-- no debconf information
diff --git a/debian/tests/advanced-usage-gzip b/debian/tests/advanced-usage-gzip
new file mode 100755
index 0000000..867fc33
--- /dev/null
+++ b/debian/tests/advanced-usage-gzip
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+# Tests the "advanced usage" section of the manpage, namely:
+# 1. compression of multiple files one after another (exit code 3 on failure)
+# 2. compression of multiple files at once (exit code 4 on failure)
+# 3. setting gzip parameters with environment variables (exit code 5 on 
failure)
+
+# Set command as an envvar so that this test can be used for other gzip 
implementations
+export ZIP=gzip
+export UNZIP=gunzip
+
+# Some nontrivial files
+export A=debian/changelog
+export B=ChangeLog
+
+
+# Test multi-file concatenation
+$ZIP -c $A > multi.gz
+$ZIP -c $B >> multi.gz
+
+cat $A $B > rawcat.txt
+$UNZIP -c multi.gz > multiout.txt
+
+if cmp -s rawcat.txt multiout.txt; then
+       echo "Multi-file concatenation passed."
+else
+       echo "ERROR: MULTI-FILE COMPRESSION FAILED"
+       exit 3
+fi
+
+# Test multi-file recompression
+# (does compressing together give equal results to compressing one at a time 
then recompressing?)
+cat $A $B | $ZIP > oneshot.gz
+$ZIP -cd multi.gz | $ZIP > remulti.gz
+
+if cmp -s oneshot.gz remulti.gz; then
+       echo "Multi-file recompression passed."
+else
+       echo "ERROR: MULTI-FILE RECOMPRESSION FAILED"
+       exit 4
+fi
+
+# Cleanup
+rm multi.gz rawcat.txt multiout.txt oneshot.gz remulti.gz
+
+# Test envvar reading (this is deprecated yet still well documented, so still 
merits an inclusion)
+# Will loop through compression levels 1 to 9 to verify
+
+FILE_FLAG="file_flag.gz"
+FILE_ENV="file_env.gz"
+
+for level in {1..9}; do
+    $ZIP -"$level" -c "$A" > "$FILE_FLAG"
+    GZIP=-"$level" $ZIP -c "$A" > "$FILE_ENV"
+
+    if ! cmp -s "$FILE_FLAG" "$FILE_ENV"; then
+        echo "ERROR: Env/Flag Mismatch detected at compression level -$level!" 
>&2
+        exit 5
+    fi
+
+    rm -f "$FILE_FLAG" "$FILE_ENV"
+done
+echo "GZIP envvar test passed."
diff --git a/debian/tests/control b/debian/tests/control
index ad73a0d..d4cc1cf 100644
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -1,2 +1,2 @@
-Tests: simple-gzip
+Tests: simple-gzip, advanced-usage-gzip
 Depends: gzip
diff --git a/debian/tests/simple-gzip b/debian/tests/simple-gzip
index 2f09030..c3e28c3 100755
--- a/debian/tests/simple-gzip
+++ b/debian/tests/simple-gzip
@@ -1,11 +1,59 @@
-#!/bin/sh
+#!/bin/bash
 
 set -e
 
+# Set command as an envvar so that this test can be used for other gzip 
implementations
+export ZIP=gzip
+export UNZIP=gunzip
+
+check_gzip_roundtrip() {
+    local file="$1"
+
+    if [[ ! -f "$file" ]]; then
+        echo "Error: file '$file' does not exist"
+        return 1
+    fi
+
+    local orig="${file}.orig"
+    local gz="${file}.gz"
+
+    cp "$file" "$orig" || return 1
+
+    $ZIP "$file" || {
+        echo "Error: compression failed"
+        rm -f "$orig"
+        return 1
+    }
+
+    $ZIP -l "$gz"
+
+    $UNZIP "$gz" || {
+        echo "Error: decompression failed"
+        rm -f "$orig"
+        return 1
+    }
+
+    if ! cmp -s "$file" "$orig"; then
+        echo "Error: decompressed file does not match original ($file)"
+        rm -f "$file" "$orig"
+        return 1
+    fi
+
+    echo "Success: decompressed file matches original ($file)"
+
+    rm -f "$file" "$orig"
+}
+
+# Test roundtrip compression of a few files
+
+# Trivial
 echo "Blablablablablablablablablablablablablabla" > bla.file
-cp bla.file bla.file.orig
-gzip bla.file
-gzip -l bla.file.gz
-gunzip bla.file.gz
-cmp bla.file bla.file.orig
-rm bla.file bla.file.orig
+check_gzip_roundtrip bla.file
+
+# Largeish file, bad compression ratio
+dd if=/dev/urandom of=random_data.bin bs=1M count=10 status=none
+check_gzip_roundtrip random_data.bin
+
+# Largeish file, good compression ratio
+cp debian/changelog changelog_f
+check_gzip_roundtrip changelog_f

Reply via email to