]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Fix compression tests
authorSergey Poznyakoff <gray@gnu.org>
Mon, 14 Jan 2019 16:08:21 +0000 (18:08 +0200)
committerSergey Poznyakoff <gray@gnu.org>
Mon, 14 Jan 2019 16:55:43 +0000 (18:55 +0200)
Existing compression tests used tar with compiled-in defaults. However,
some of the defaults are sure to create archives that are not byte-to-byte
reproducible (e.g. DEFAULT_ARCHIVE_FORMAT=POSIX, because the name field
in posix extended headers uses PID of the creating process by default).
Moreover, some compressors (e.g. gzip) store current timestamp in
the file header when compressing from stdin, so that using cmp on the
two created archives as the tests did is error-prone. Another problem
is that the tests implicitly assumed that tar uses archive suffix to
recognize its format when extracting, which isn't the case. Finally,
there's hardly any reason in using sed to create m4 sources, when
everything can be achieved by m4 itself.

* tests/Makefile.am: Remove generation of compress-*.at files.
* tests/compress.at.in: Remove.
* tests/compress.m4: New file.
* tests/testsuite.at: Include compress.m4, use TAR_CHECK_COMPRESS to
check compression options.

tests/Makefile.am
tests/compress.at.in [deleted file]
tests/compress.m4 [new file with mode: 0644]
tests/testsuite.at

index 25ac1bf02899ca763ecdd161ff93cf145446d027..bc657da2973af4c41163b03f820fd351b3f0e78f 100644 (file)
@@ -19,7 +19,7 @@
 
 EXTRA_DIST = $(TESTSUITE_AT) \
   testsuite package.m4 star/README star/quicktest.sh \
-  compress.at.in
+  compress.m4
 
 DISTCLEANFILES       = atconfig $(check_SCRIPTS)
 MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
@@ -47,6 +47,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
 
 TESTSUITE_AT = \
  testsuite.at\
+ compress.m4\
  T-cd.at\
  T-dir00.at\
  T-dir01.at\
@@ -70,12 +71,6 @@ TESTSUITE_AT = \
  chtype.at\
  comprec.at\
  comperr.at\
- compress-zstd.at\
- compress-xz.at\
- compress-bzip2.at\
- compress-gzip.at\
- compress-lzip.at\
- compress-lzop.at\
  checkpoint/defaults.at\
  checkpoint/interval.at\
  checkpoint/dot.at\
@@ -282,42 +277,6 @@ TESTSUITE_AT = \
  selacl01.at\
  capabs_raw01.at
 
-CLEANFILES += compress-zstd.at
-compress-zstd.at: compress.at.in
-       $(AM_V_GEN)rm -rf $@ $@-t
-       $(AM_V_at)sed 's/@tool@/zstd/g;s/@suff@/zst/g;s/@suff2@/tzst/g;' \
-         $(srcdir)/compress.at.in > $@-t && chmod a-w $@-t && mv $@-t $@
-
-CLEANFILES += compress-gzip.at
-compress-gzip.at: compress.at.in
-       $(AM_V_GEN)rm -rf $@ $@-t
-       $(AM_V_at)sed 's/@tool@/gzip/g;s/@suff@/gz/g;s/@suff2@/tgz/g;' \
-         $(srcdir)/compress.at.in > $@-t && chmod a-w $@-t && mv $@-t $@
-
-CLEANFILES += compress-xz.at
-compress-xz.at: compress.at.in
-       $(AM_V_GEN)rm -rf $@ $@-t
-       $(AM_V_at)sed 's/@tool@/xz/g;s/@suff@/xz/g;s/@suff2@/txz/g;' \
-         $(srcdir)/compress.at.in > $@-t && chmod a-w $@-t && mv $@-t $@
-
-CLEANFILES += compress-bzip2.at
-compress-bzip2.at: compress.at.in
-       $(AM_V_GEN)rm -rf $@ $@-t
-       $(AM_V_at)sed 's/@tool@/bzip2/g;s/@suff@/bz2/g;s/@suff2@/tbz2/g;' \
-         $(srcdir)/compress.at.in > $@-t && chmod a-w $@-t && mv $@-t $@
-
-CLEANFILES += compress-lzip.at
-compress-lzip.at: compress.at.in
-       $(AM_V_GEN)rm -rf $@ $@-t
-       $(AM_V_at)sed 's/@tool@/lzip/g;s/@suff@/lz/g;s/@suff2@//g;' \
-         $(srcdir)/compress.at.in > $@-t && chmod a-w $@-t && mv $@-t $@
-
-CLEANFILES += compress-lzop.at
-compress-lzop.at: compress.at.in
-       $(AM_V_GEN)rm -rf $@ $@-t
-       $(AM_V_at)sed 's/@tool@/lzop/g;s/@suff@/lzo/g;s/@suff2@//g;' \
-         $(srcdir)/compress.at.in > $@-t && chmod a-w $@-t && mv $@-t $@
-
 distclean-local:
        -rm -rf download
 
diff --git a/tests/compress.at.in b/tests/compress.at.in
deleted file mode 100644 (file)
index 91a6af2..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-# Process this file with autom4te to create testsuite. -*- Autotest -*-
-
-# Test suite for GNU tar.
-# Copyright 2018-2019 Free Software Foundation, Inc.
-
-# This file is part of GNU tar.
-
-# GNU tar 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.
-
-# GNU tar 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.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# tar can create/decompress @tool@-compressed tarballs
-
-AT_SETUP([compress: @tool@])
-AT_KEYWORDS([compression @tool@])
-
-unset TAR_OPTIONS
-
-AT_CHECK([
-AT_GZIP_PREREQ([@tool@])
-
-touch empty
-# Create with --@tool@:
-tar --@tool@ -cf - empty 2>err > k.tar.@suff@ || exit 1
-test -s err && exit 1
-tar tf k.tar.@suff@ 2>err > out || exit 1
-test "$(cat out)" = empty || exit 1
-test -s err && exit 1
-
-# Ensure -ac works with an -f-specified .@suff@-suffixed name.
-tar -acf k2.tar.@suff@ empty 2>err > out || exit 1
-cmp k2.tar.@suff@ k.tar.@suff@ || exit 1
-test -s err && exit 1
-
-# Extraction: ensure the .@suff@ suffix is recognized.
-rm -f empty || exit 1
-tar xf k.tar.@suff@ 2>err > out || exit 1
-test -s err && exit 1
-test -f empty || exit 1
-
-if test -n '@suff2@'; then
-  # Extraction: ensure the .@suff2@ suffix is also recognized.
-  mv k.tar.@suff@ k.@suff2@ || exit 1
-  rm -f empty
-  tar xf k.@suff2@ 2>err > out || exit 1
-  test -s err && exit 1
-  test -f empty || exit 1
-else
-  :
-fi
-
-],
-[0],
-[],
-[],
-[],[])
-
-AT_CLEANUP
diff --git a/tests/compress.m4 b/tests/compress.m4
new file mode 100644 (file)
index 0000000..1f22632
--- /dev/null
@@ -0,0 +1,56 @@
+# This file is part of GNU tar testsuite. -*- Autotest -*-
+# Copyright 2018-2019 Free Software Foundation, Inc.
+#
+# GNU tar 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.
+#
+# GNU tar 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+dnl TAR_CHECK_COMPRESS(TOOL, SUF[, SUF2])
+dnl Tests whether tar can create archives using TOOL (i.e. using the --TOOL
+dnl command line option). SUF and optional SUF2 are suffixes for created
+dnl archives (without leading dot). Tar should be able to use TOOL to
+dnl automatically decompress archives with names ending on these suffixes.
+m4_define([TAR_CHECK_COMPRESS],
+[AT_SETUP([compress: $1])
+AT_KEYWORDS([compression compress-$1 $1])
+
+AT_CHECK([
+AT_GZIP_PREREQ($1)
+unset TAR_OPTIONS
+
+touch empty
+set -e
+: create with --$1
+tar --$1 -cf k.tar.$2 empty
+tar tf k.tar.$2
+
+m4_foreach([SUF], m4_quote(m4_shift($@)),
+[
+echo testing .SUF
+tar -acf k2.tar.SUF empty
+cat k2.tar.SUF | $1 -d > k.SUF.tar
+tar tf k.SUF.tar
+])
+
+# Extraction: ensure compressed format is correctly recognized
+rm -f empty
+tar xf k.tar.$2
+test -f empty
+],
+[0],
+[empty
+m4_foreach([SUF],m4_quote(m4_shift($@)),[testing .SUF
+empty
+])])
+
+AT_CLEANUP
+])
index ddaf4e110afcc2327649eb80326880c7e7b62722..f764dced46509ef29229b2159dda647631c64834 100644 (file)
@@ -236,13 +236,14 @@ m4_include([checkpoint/dot-int.at])
 m4_popdef([CPT_CHECK])
 
 AT_BANNER([Compression])
-m4_include([compress-gzip.at])
-m4_include([compress-bzip2.at])
-m4_include([compress-xz.at])
+m4_include([compress.m4])
+TAR_CHECK_COMPRESS(gzip, gz, tgz)
+TAR_CHECK_COMPRESS(bzip2, bz2, tbz2)
+TAR_CHECK_COMPRESS(xz, xz, txz)
 dnl: omit lzma, because it would fail due to magic number mismatch
-m4_include([compress-lzip.at])
-m4_include([compress-lzop.at])
-m4_include([compress-zstd.at])
+TAR_CHECK_COMPRESS(lzip, lz)
+TAR_CHECK_COMPRESS(lzop, lzo)
+TAR_CHECK_COMPRESS(zstd, zst, tzst)
 
 AT_BANNER([Positional options])
 m4_include([positional01.at])