3 [ -f testing.sh ] && . testing.sh
5 #testing "name" "command" "result" "infile" "stdin"
8 # On success, the input files are removed and replaced by new
9 # files with the .gz suffix.
12 testing "with input files" "gzip f1 f2 &&
13 test -f f1.gz && test -f f2.gz &&
14 ! test -f f1 && ! test -f f2 &&
15 zcat f1.gz f2.gz" "foo bar\n" "" ""
16 rm -f f1 f2 f1.gz f2.gz
18 # With no files, compresses stdin to stdout.
19 testing "no files (stdin to stdout)" "echo hello world | gzip > f.gz &&
20 test -f f.gz && zcat f.gz" "hello world\n" "" ""
26 testing "with input files and -c" "gzip -c f1 f2 > out.gz &&
27 ! test -f f1.gz && ! test -f f2.gz &&
28 test -f f1 && test -f f2 &&
29 zcat out.gz" "foo bar\n" "" ""
32 # -d Decompress (act as gunzip)
33 echo "hello world" | gzip > f.gz
34 testing "-d (act as gunzip)" "gzip -d f.gz &&
35 test -f f && ! test -f f.gz && cat f" "hello world\n" "" ""
38 echo "hello world" | gzip > f.gz
39 testing "-dc (act as zcat)" "gzip -dc f.gz &&
40 ! test -f f && test -f f.gz" "hello world\n" "" ""
43 # -f Force: allow overwrite of output file
44 echo "hello world" > f1
45 echo "precious data" > f1.gz
46 testing "no overwrite without -f" \
47 "gzip f1 2>/dev/null || echo refused && cat f1 f1.gz" \
48 "refused\nhello world\nprecious data\n" "" ""
49 testing "overwrite with -f" \
50 "gzip -f f1 && echo allowed && ! test -f f1 && zcat f1.gz" \
51 "allowed\nhello world\n" "" ""
54 # -k Keep input files (don't remove)
55 echo "hello world" > f1
56 testing "-k" "gzip -k f1 && cat f1 && zcat f1.gz" \
57 "hello world\nhello world\n" "" ""
60 # Test that -9 compresses better than -1.
61 for i in $(seq 1 1000) ; do echo "hello world" >> x ; done
65 "test $(stat -c '%s' x1.gz) -gt $(stat -c '%s' x9.gz) && echo okay" \
69 # Test that gzip preserves permissions and times.
71 echo "hello world" > f1
73 touch -a -t 197801020304 f1
74 touch -m -t 198704030201 f1
75 testing "permissions/times preservation" \
76 "gzip -k f1 && TZ=UTC stat -c '%a %Y' f1 && stat -c '%a %X %Y' f1.gz" \
77 "411 544413660\n411 252558240 544413660\n" "" ""