1 #!/bin/bash 2 3 [ -f testing.sh ] && . testing.sh 4 5 #testing "name" "command" "result" "infile" "stdin" 6 7 # Decompress files. 8 # On success, the input files are removed and replaced by new 9 # files without the .gz suffix. 10 echo -n "foo " | gzip > f1.gz 11 echo "bar" | gzip > f2.gz 12 testing "with input files" "gunzip f1.gz f2.gz && 13 ! test -f f1.gz && ! test -f f2.gz && 14 test -f f1 && test -f f2 && 15 cat f1 f2" "foo bar\n" "" "" 16 rm -f f1 f2 f1.gz f2.gz 17 18 # With no files, decompresses stdin to stdout. 19 echo "hello world" | gzip > f.gz 20 testing "no files (stdin to stdout)" "cat f.gz | gunzip > f && 21 test -f f.gz && cat f" "hello world\n" "" "" 22 rm -f f f.gz 23 24 # -c Output to stdout 25 echo -n "foo " | gzip > f1.gz 26 echo "bar" | gzip > f2.gz 27 testing "with input files and -c" "gunzip -c f1.gz f2.gz > out && 28 test -f f1.gz && test -f f2.gz && 29 ! test -f f1 && ! test -f f2 && 30 cat out" "foo bar\n" "" "" 31 rm -f f1.gz f2.gz out 32 33 # TODO: how to test "gunzip -f"? 34 35 # -k Keep input files (don't remove) 36 echo "hello world" | gzip > f1.gz 37 testing "-k" "gunzip -k f1.gz && cat f1 && zcat f1.gz" \ 38 "hello world\nhello world\n" "" "" 39 rm -f f1 f1.gz 40 41 # Test that gunzip preserves permissions and times. 42 export TZ=UTC 43 echo "hello world" | gzip > f1.gz 44 chmod 0411 f1.gz 45 touch -a -t 197801020304 f1.gz 46 touch -m -t 198704030201 f1.gz 47 testing "permissions/times preservation" \ 48 "gunzip -k f1.gz && stat -c '%a %X %Y' f1 && stat -c '%a %Y' f1.gz" \ 49 "411 252558240 544413660\n411 544413660\n" "" "" 50 rm -f f1 f1.gz 51