aboutsummaryrefslogtreecommitdiff
path: root/tests/gunzip.test
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-04-24 13:29:30 -0700
committerRob Landley <rob@landley.net>2018-01-09 11:15:58 -0600
commit36beb6ac93362790ba6633f56109cde5f01d20c4 (patch)
treed62e28956c9d75bdd1fff75dae9e004307038ef5 /tests/gunzip.test
parentb432aee484bfca4d53cdce13343e6ee5c850d0f3 (diff)
downloadtoybox-36beb6ac93362790ba6633f56109cde5f01d20c4.tar.gz
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.)
Diffstat (limited to 'tests/gunzip.test')
-rw-r--r--tests/gunzip.test50
1 files changed, 50 insertions, 0 deletions
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