~dricottone/my-utils

ref: 618b5e7801dd9bdc6100b6ed88f04d9dcd75a3ab my-utils/tests/compression_test.sh -rwxr-xr-x 3.0 KiB
618b5e78Dominic Ricottone Slight refactor of a usage message 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh

# mktar and tarcat

# create temp directory
mkdir -p tests/temp_compression

# compress file with algorithms set by options
cd tests/static
mktar compression_target.txt --compress=none
mktar compression_target.txt --compress=gzip
mktar compression_target.txt --compress=xz
mktar compression_target.txt --compress=zstd
mktar compression_target.txt --compress=bzip2
mv archive* ../temp_compression/
cd ..

# uncompress and combine compressed files
cd temp_compression
tarcat archive* > basic_concat.txt
cd ..

# test
if ! cmp static/compression_result.txt temp_compression/basic_concat.txt >/dev/null 2>&1; then
  printf "Failure in compression tests: basic compression\n"
  exit 1
fi

# compress file with algorithms implicitly set by output filename
cd static
mktar compression_target.txt -n implicit.tar
mktar compression_target.txt -n implicit.tar.gz
mktar compression_target.txt -n implicit.tar.xz
mktar compression_target.txt -n implicit.tar.zst
mktar compression_target.txt -n implicit.tar.bz2
mv implicit* ../temp_compression/
cd ..

# uncompress and combine compressed files
cd temp_compression
tarcat implicit* > implicit_concat.txt
cd ..

# test
if ! cmp static/compression_result.txt temp_compression/implicit_concat.txt >/dev/null 2>&1; then
  printf "Failure in compression tests: implicit compression\n"
  exit 1
fi

# compress file with algorithms set and filenames set
cd static
mktar compression_target.txt --compress=none  -n explicit.tar
mktar compression_target.txt --compress=gzip  -n explicit.tar.gz
mktar compression_target.txt --compress=xz    -n explicit.tar.xz
mktar compression_target.txt --compress=zstd  -n explicit.tar.zst
mktar compression_target.txt --compress=bzip2 -n explicit.tar.bz2
mv explicit* ../temp_compression/
cd ..

# uncompress and combine compressed files
cd temp_compression
tarcat explicit* > explicit_concat.txt
cd ..

# test
if ! cmp static/compression_result.txt temp_compression/explicit_concat.txt >/dev/null 2>&1; then
  printf "Failure in compression tests: explicit compression\n"
  exit 1
fi

# untar

# copy archives to temp directory
cp static/decompression_target* temp_compression/

# decompress files
cd temp_compression
untar decompression_target.tar decompression_target.tar.gz decompression_target.tar.xz decompression_target.tar.zst decompression_target.tar.bz2
cd ..

# test
if ! cmp static/decompression_result.txt temp_compression/tar.txt >/dev/null 2>&1; then
  printf "Failure in decompression tests: tar\n"
  exit 1
elif ! cmp static/decompression_result.txt temp_compression/gzip.txt >/dev/null 2>&1; then
  printf "Failure in decompression tests: gzip\n"
  exit 1
elif ! cmp static/decompression_result.txt temp_compression/xz.txt >/dev/null 2>&1; then
  printf "Failure in decompression tests: xz\n"
  exit 1
elif ! cmp static/decompression_result.txt temp_compression/zstd.txt >/dev/null 2>&1; then
  printf "Failure in decompression tests: zstd\n"
  exit 1
elif ! cmp static/decompression_result.txt temp_compression/bzip2.txt >/dev/null 2>&1; then
  printf "Failure in decompression tests: bzip2\n"
  exit 1
fi