From 36beb6ac93362790ba6633f56109cde5f01d20c4 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 24 Apr 2017 13:29:30 -0700 Subject: Add the gzip/gunzip/zcat tests I wrote for toolbox gzip/gunzip/zcat. Bringing the zlib-based gzip/gunzip/zcat over to toybox is a problem for another day, but at least the tests are easy... (These tests pass with TEST_HOST and on the toolbox versions, but the toybox toys are in pending and very broken.) --- tests/gunzip.test | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/gunzip.test (limited to 'tests/gunzip.test') diff --git a/tests/gunzip.test b/tests/gunzip.test new file mode 100644 index 00000000..9f9ef5eb --- /dev/null +++ b/tests/gunzip.test @@ -0,0 +1,50 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# Decompress files. +# On success, the input files are removed and replaced by new +# files without the .gz suffix. +echo -n "foo " | gzip > f1.gz +echo "bar" | gzip > f2.gz +testing "with input files" "gunzip f1.gz f2.gz && + ! test -f f1.gz && ! test -f f2.gz && + test -f f1 && test -f f2 && + cat f1 f2" "foo bar\n" "" "" +rm -f f1 f2 f1.gz f2.gz + +# With no files, decompresses stdin to stdout. +echo "hello world" | gzip > f.gz +testing "no files (stdin to stdout)" "cat f.gz | gunzip > f && + test -f f.gz && cat f" "hello world\n" "" "" +rm -f f f.gz + +# -c Output to stdout +echo -n "foo " | gzip > f1.gz +echo "bar" | gzip > f2.gz +testing "with input files and -c" "gunzip -c f1.gz f2.gz > out && + test -f f1.gz && test -f f2.gz && + ! test -f f1 && ! test -f f2 && + cat out" "foo bar\n" "" "" +rm -f f1.gz f2.gz out + +# TODO: how to test "gunzip -f"? + +# -k Keep input files (don't remove) +echo "hello world" | gzip > f1.gz +testing "-k" "gunzip -k f1.gz && cat f1 && zcat f1.gz" \ + "hello world\nhello world\n" "" "" +rm -f f1 f1.gz + +# Test that gunzip preserves permissions and times. +export TZ=UTC +echo "hello world" | gzip > f1.gz +chmod 0411 f1.gz +touch -a -t 197801020304 f1.gz +touch -m -t 198704030201 f1.gz +testing "permissions/times preservation" \ + "gunzip -k f1.gz && stat -c '%a %X %Y' f1 && stat -c '%a %Y' f1.gz" \ + "411 252558240 544413660\n411 544413660\n" "" "" +rm -f f1 f1.gz -- cgit v1.2.3