OSDN Git Service

refined.
[lha/lha.git] / tests / lha-test.in
1 #!/bin/sh
2
3 : ${lha=@top_builddir@/src/lha}
4
5 trap "rm -rf test-*" 0 1 2 3 15
6
7 declare -i test_number=0
8
9 exec > test.log
10
11 message() {
12   echo "$@" >&2
13   echo "$@"
14 }
15
16 check() {
17   ((test_number = test_number + 1))
18   local status=$1
19   if [[ $status -eq 0 ]]; then
20     message test $test_number ... ok
21   else
22     message test $test_number ... failed
23     result=1
24   fi
25 }
26
27 message testing $lha
28 message testing to create/list/extract lha archive.
29
30 for i in `seq 100`
31 do
32     echo foo >> test-a
33 done
34 sed 's/foo/bar/g' < test-a > test-b
35 sed 's/foo/baz/g' < test-a > test-c
36
37 $lha c test-1.lzh test-a test-b test-c
38                                                         check $?
39 test -s test-1.lzh
40                                                         check $?
41
42 $lha l test-1.lzh
43                                                         check $?
44
45 test -d test-1 || mkdir test-1
46 mv test-[abc] test-1
47 $lha x test-1.lzh
48                                                         check $?
49 diff test-1/test-a test-a
50                                                         check $?
51 diff test-1/test-b test-b
52                                                         check $?
53 diff test-1/test-c test-c
54                                                         check $?
55
56 message testing to generic, lh5, lh6 and lh7 method archive.
57 $lha co  test-m1.lzh test-a test-b test-c
58                                                         check $?
59 $lha co5 test-m5.lzh test-a test-b test-c
60                                                         check $?
61 $lha co6 test-m6.lzh test-a test-b test-c
62                                                         check $?
63 $lha co7 test-m7.lzh test-a test-b test-c
64                                                         check $?
65 $lha v test-m1.lzh | grep lh1
66                                                         check $?
67 $lha v test-m5.lzh | grep lh5
68                                                         check $?
69 $lha v test-m6.lzh | grep lh6
70                                                         check $?
71 $lha v test-m7.lzh | grep lh7
72                                                         check $?
73
74 $lha xw=test-m1 test-m1.lzh
75                                                         check $?
76 $lha xw=test-m5 test-m5.lzh
77                                                         check $?
78 $lha xw=test-m6 test-m6.lzh
79                                                         check $?
80 $lha xw=test-m7 test-m7.lzh
81                                                         check $?
82
83 diff -r test-1 test-m1
84                                                         check $?
85 diff -r test-1 test-m5
86                                                         check $?
87 diff -r test-1 test-m6
88                                                         check $?
89 diff -r test-1 test-m7
90                                                         check $?
91
92 message testing to print lha archive.
93
94 $lha pq test-m1.lzh test-a | diff test-a -
95                                                         check $?
96 $lha pq test-m5.lzh test-a | diff test-a -
97                                                         check $?
98 $lha pq test-m6.lzh test-a | diff test-a -
99                                                         check $?
100 $lha pq test-m7.lzh test-a | diff test-a -
101                                                         check $?
102
103 cat test-[abc] > test-abc
104 $lha pq test-m1.lzh | diff test-abc -
105                                                         check $?
106 $lha pq test-m5.lzh | diff test-abc -
107                                                         check $?
108 $lha pq test-m6.lzh | diff test-abc -
109                                                         check $?
110 $lha pq test-m7.lzh | diff test-abc -
111                                                         check $?
112
113 message testing to delete files from archive.
114
115 cp test-m5.lzh test-2.lzh
116
117 # do nothing
118 $lha d test-2.lzh 2> test-stderr
119                                                         check $?
120 test -s test-stderr
121                                                         check $?
122 $lha d test-2.lzh test-a
123                                                         check $?
124 $lha xw=test-2 test-2.lzh
125 diff -r test-m5 test-2 2>&1 | grep -v '^Only in test-m5: test-a'
126 test $? -eq 1
127                                                         check $?
128 rm -rf test-2
129
130 $lha d test-2.lzh test-b
131                                                         check $?
132 $lha xw=test-2 test-2.lzh
133 diff -r test-m5 test-2 2>&1 |
134     grep -v '^Only in test-m5: test-a$' |
135     grep -v '^Only in test-m5: test-b$'
136 test $? -eq 1
137                                                         check $?
138 rm -rf test-2
139
140 $lha d test-2.lzh test-c 2> test-stderr
141                                                         check $?
142 test -s test-stderr
143                                                         check $?
144 test ! -f test-2.lzh
145                                                         check $?
146
147 message testing to treat stdin/stdout as archive file.
148
149 $lha c - test-a test-b test-c > test-3.lzh
150                                                         check $?
151 cat test-3.lzh | $lha xw=test-3 -
152                                                         check $?
153 diff -r test-m5 test-3
154                                                         check $?
155 exit $result