···282282 test_brotli_level 11
283283}
284284285285+# Test framed snappy interop against the snzip CLI. snzip's default format is
286286+# `framing2`, which is the same official framing format the `snap` crate uses
287287+# (and that cmprss writes with the `.sz` extension). Snappy has no compression
288288+# level, so no --level is passed.
289289+test_snappy() {
290290+ tmpdir
291291+ echo "Testing snappy in $PWD"
292292+ echo "Creating random data"
293293+ random_file 1000000 file
294294+ echo "Compressing with snzip and cmprss"
295295+ snzip -c file >snzip_file.sz
296296+ cmprss snappy file cmprss_file.sz --progress=off
297297+ compare_size snzip_file.sz cmprss_file.sz
298298+ echo "Decompressing"
299299+ snzip -d -c snzip_file.sz >snzip_snzip
300300+ snzip -d -c cmprss_file.sz >cmprss_snzip
301301+ cmprss snappy --extract cmprss_file.sz cmprss_cmprss --progress=off
302302+ cmprss snappy --extract snzip_file.sz snzip_cmprss --progress=off
303303+ echo "Comparing the decompressed files"
304304+ compare file snzip_snzip
305305+ compare file cmprss_snzip
306306+ compare file cmprss_cmprss
307307+ compare file snzip_cmprss
308308+ echo "No errors detected"
309309+}
310310+285311# Test tar archive interop with the tar CLI. Tar has no progress bar, so no
286312# --progress flag is passed.
287313test_tar() {
···324350 echo "No errors detected"
325351}
326352327327-# Shared helper for tar.<codec> pipeline interop. Takes the compound extension
328328-# (tar.gz/tar.xz/tar.zst/tar.bz2) and the corresponding tar short flag
329329-# (-z/-J/--zstd/-j). Verifies that cmprss produces archives the tar CLI can
330330-# read, and vice versa. Pipelines are invoked without a subcommand so
331331-# --progress isn't accepted; the archive is written to a file, not stdout,
332332-# which is fine for tests.
353353+# Shared helper for tar.<codec> pipeline interop. The first arg is the compound
354354+# extension; the rest are the tar flags used to compress/extract that codec
355355+# (e.g. `-z`, `--zstd`, or `-I lzma` for codecs without a short flag).
356356+# Verifies that cmprss produces archives the tar CLI can read, and vice versa.
357357+# Pipelines are invoked without a subcommand so --progress isn't accepted; the
358358+# archive is written to a file, not stdout, which is fine for tests.
333359test_tar_pipeline() {
334360 local ext="$1"
335335- local tar_flag="$2"
361361+ shift
362362+ local tar_flags=("$@")
336363 tmpdir
337364 echo "Testing $ext pipeline in $PWD"
338365 echo "Creating random data"
339366 random_dir 10 indir
340367 echo "Creating $ext archives with each tool"
341341- tar "$tar_flag" -cf tar_archive."$ext" indir
368368+ tar "${tar_flags[@]}" -cf tar_archive."$ext" indir
342369 cmprss indir cmprss_archive."$ext"
343370 echo "Extracting each archive with the opposite tool"
344371 mkdir -p tar_from_cmprss
345345- tar "$tar_flag" -xf cmprss_archive."$ext" -C tar_from_cmprss
372372+ tar "${tar_flags[@]}" -xf cmprss_archive."$ext" -C tar_from_cmprss
346373 mkdir -p cmprss_from_tar
347374 cmprss --extract tar_archive."$ext" cmprss_from_tar
348375 echo "Comparing the extracted contents"
···355382test_tar_xz() { test_tar_pipeline tar.xz -J; }
356383test_tar_bz2() { test_tar_pipeline tar.bz2 -j; }
357384test_tar_zst() { test_tar_pipeline tar.zst --zstd; }
385385+# tar has no short flag for these codecs; drive the external CLI via -I.
386386+test_tar_lzma() { test_tar_pipeline tar.lzma -I lzma; }
387387+test_tar_br() { test_tar_pipeline tar.br -I brotli; }
388388+test_tar_lz4() { test_tar_pipeline tar.lz4 -I lz4; }
389389+test_tar_sz() { test_tar_pipeline tar.sz -I snzip; }
358390359391# Run all the tests if no arguments are given
360392if [ $# -eq 0 ]; then
361361- set -- gzip xz bzip2 zstd lz4 lzma brotli tar zip tar_gz tar_xz tar_bz2 tar_zst
393393+ set -- gzip xz bzip2 zstd lz4 lzma brotli snappy tar zip \
394394+ tar_gz tar_xz tar_bz2 tar_zst tar_lzma tar_br tar_lz4 tar_sz
362395fi
363396364397# Run the tests given on the command line