gunzip.test 1.7 KB

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