aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/gunzip.test50
-rw-r--r--tests/gzip.test78
-rw-r--r--[-rwxr-xr-x]tests/zcat.test34
3 files changed, 142 insertions, 20 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
diff --git a/tests/gzip.test b/tests/gzip.test
new file mode 100644
index 00000000..24bd01ed
--- /dev/null
+++ b/tests/gzip.test
@@ -0,0 +1,78 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+# Compress files.
+# On success, the input files are removed and replaced by new
+# files with the .gz suffix.
+echo -n "foo " > f1
+echo "bar" > f2
+testing "with input files" "gzip f1 f2 &&
+ test -f f1.gz && test -f f2.gz &&
+ ! test -f f1 && ! test -f f2 &&
+ zcat f1.gz f2.gz" "foo bar\n" "" ""
+rm -f f1 f2 f1.gz f2.gz
+
+# With no files, compresses stdin to stdout.
+testing "no files (stdin to stdout)" "echo hello world | gzip > f.gz &&
+ test -f f.gz && zcat f.gz" "hello world\n" "" ""
+rm -f f.gz
+
+# -c Output to stdout
+echo -n "foo " > f1
+echo "bar" > f2
+testing "with input files and -c" "gzip -c f1 f2 > out.gz &&
+ ! test -f f1.gz && ! test -f f2.gz &&
+ test -f f1 && test -f f2 &&
+ zcat out.gz" "foo bar\n" "" ""
+rm -f f1 f2 out.gz
+
+# -d Decompress (act as gunzip)
+echo "hello world" | gzip > f.gz
+testing "-d (act as gunzip)" "gzip -d f.gz &&
+ test -f f && ! test -f f.gz && cat f" "hello world\n" "" ""
+rm -f f.gz f
+
+echo "hello world" | gzip > f.gz
+testing "-dc (act as zcat)" "gzip -dc f.gz &&
+ ! test -f f && test -f f.gz" "hello world\n" "" ""
+rm -f f.gz f
+
+# -f Force: allow overwrite of output file
+echo "hello world" > f1
+echo "precious data" > f1.gz
+testing "no overwrite without -f" \
+ "gzip f1 2>/dev/null || echo refused && cat f1 f1.gz" \
+ "refused\nhello world\nprecious data\n" "" ""
+testing "overwrite with -f" \
+ "gzip -f f1 && echo allowed && ! test -f f1 && zcat f1.gz" \
+ "allowed\nhello world\n" "" ""
+rm -f f1 f1.gz
+
+# -k Keep input files (don't remove)
+echo "hello world" > f1
+testing "-k" "gzip -k f1 && cat f1 && zcat f1.gz" \
+ "hello world\nhello world\n" "" ""
+rm -f f1 f1.gz
+
+# Test that -9 compresses better than -1.
+for i in $(seq 1 1000) ; do echo "hello world" >> x ; done
+gzip -c1 x > x1.gz
+gzip -c9 x > x9.gz
+testing "-1 vs -9" \
+ "test $(stat -c '%s' x1.gz) -gt $(stat -c '%s' x9.gz) && echo okay" \
+ "okay\n" "" ""
+rm -f x x1.gz x9.gz
+
+# Test that gzip preserves permissions and times.
+export TZ=UTC
+echo "hello world" > f1
+chmod 0411 f1
+touch -a -t 197801020304 f1
+touch -m -t 198704030201 f1
+testing "permissions/times preservation" \
+ "gzip -k f1 && TZ=UTC stat -c '%a %Y' f1 && stat -c '%a %X %Y' f1.gz" \
+ "411 544413660\n411 252558240 544413660\n" "" ""
+rm -f f1 f1.gz
diff --git a/tests/zcat.test b/tests/zcat.test
index ccd472cd..57af1097 100755..100644
--- a/tests/zcat.test
+++ b/tests/zcat.test
@@ -1,26 +1,20 @@
#!/bin/bash
-# Copyright 2014 Divya Kothari <divya.s.kothari@gmail.com>
-# Copyright 2014 Naha Maggu <maggu.neha@gmail.com>
-
[ -f testing.sh ] && . testing.sh
#testing "name" "command" "result" "infile" "stdin"
-echo "hello" > file
-tar -czf file.gz file
-# Get system zcat
-zcatExe=`which zcat`
-$zcatExe file.gz > zcatOut
-testing "- decompresses a single file" "zcat file.gz > Tempfile && echo "yes"; diff Tempfile zcatOut && echo "yes"; rm -rf file* zcatOut Tempfile" "yes\nyes\n" "" ""
-#testing "name" "command" "result" "infile" "stdin"
-echo "hello" > file1
-echo "hi" > file2
-echo "Hi, Good morning !! I am a bzcat tester" > file3
-tar -czf file1.gz file1
-tar -czf file2.gz file2
-tar -czf file3.gz file3
-# Get system zcat
-zcatExe=`which zcat`
-$zcatExe file1.gz file2.gz file3.gz > zcatOut
-testing "- decompresses multiple files" "zcat file1.gz file2.gz file3.gz > Tempfile && echo "yes" ; diff Tempfile zcatOut && echo "yes"; rm -rf file* zcatOut Tempfile " "yes\nyes\n" "" ""
+echo -n "foo " | gzip > f1.gz
+echo "bar" | gzip > f2.gz
+
+# zcat is basically just `gzip -dc`...
+testing "files" "zcat f1.gz f2.gz && test -f f1.gz && test -f f2.gz" \
+ "foo bar\n" "" ""
+
+# zcat -c is allowed, but the -c changes nothing.
+testing "-c" "zcat -c f1.gz f2.gz && test -f f1.gz && test -f f2.gz" \
+ "foo bar\n" "" ""
+
+# TODO: how to test "zcat -f"?
+
+rm -f f1 f2 f1.gz f2.gz