toybox/tests/gunzip.test
<<
>>
Prefs
   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.
  10echo -n "foo " | gzip > f1.gz
  11echo "bar" | gzip > f2.gz
  12testing "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" "" ""
  16rm -f f1 f2 f1.gz f2.gz
  17
  18# With no files, decompresses stdin to stdout.
  19echo "hello world" | gzip > f.gz
  20testing "no files (stdin to stdout)" "cat f.gz | gunzip > f && 
  21    test -f f.gz && cat f" "hello world\n" "" ""
  22rm -f f f.gz
  23
  24# test FEXTRA support
  25echo "1f8b08040000000000ff04000000ffff4bcbcfe70200a865327e04000000" | xxd -r -p > f1.gz
  26testing "FEXTRA flag skipped properly" "gunzip f1.gz &&
  27    ! test -f f1.gz && test -f f1 &&
  28    cat f1" "foo\n" "" ""
  29rm -f f1 f1.gz
  30
  31# -c    Output to stdout
  32echo -n "foo " | gzip > f1.gz
  33echo "bar" | gzip > f2.gz
  34testing "with input files and -c" "gunzip -c f1.gz f2.gz > out && 
  35    test -f f1.gz && test -f f2.gz && 
  36    ! test -f f1 && ! test -f f2 && 
  37    cat out" "foo bar\n" "" ""
  38rm -f f1.gz f2.gz out
  39
  40# TODO: how to test "gunzip -f"?
  41
  42# -k    Keep input files (don't remove)
  43echo "hello world" | gzip > f1.gz
  44testing "-k" "gunzip -k f1.gz && cat f1 && zcat f1.gz" \
  45    "hello world\nhello world\n" "" ""
  46rm -f f1 f1.gz
  47
  48# Test that gunzip preserves permissions and times.
  49export TZ=UTC
  50echo "hello world" | gzip > f1.gz
  51chmod 0411 f1.gz
  52touch -a -t 197801020304 f1.gz
  53touch -m -t 198704030201 f1.gz
  54testing "permissions/times preservation" \
  55    "gunzip -k f1.gz && stat -c '%a %X %Y' f1 && stat -c '%a %Y' f1.gz" \
  56    "411 252558240 544413660\n411 544413660\n" "" ""
  57rm -f f1 f1.gz
  58