OSDN Git Service

* tests/lha-test.in: added some tests.
[lha/lha.git] / tests / lha-test.in
1 #!/bin/sh
2
3 : ${lha_dir=@top_builddir@/src}
4 : ${lha=$(cd $lha_dir && pwd)/lha}
5
6 trap "rm -rf test-*" 0 1 2 3 15
7
8 declare -i test_number=0
9
10 exec > test.log
11
12 message() {
13   echo "$@" >&2
14   echo "$@"
15 }
16
17 check() {
18   ((test_number = test_number + 1))
19   local status=$1
20   if [[ $status -eq 0 ]]; then
21     message test $test_number ... ok
22   else
23     message test $test_number ... failed
24     result=1
25   fi
26 }
27
28 message testing $lha
29 message testing to create/list/extract lha archive.
30
31 for i in `seq 100`
32 do
33     echo foo >> test-a
34 done
35 sed 's/foo/bar/g' < test-a > test-b
36 sed 's/foo/baz/g' < test-a > test-c
37
38 $lha c test-1.lzh test-a test-b test-c
39                                                         check $?
40 test -s test-1.lzh
41                                                         check $?
42
43 $lha l test-1.lzh
44                                                         check $?
45
46 test -d test-1 || mkdir test-1
47 mv test-[abc] test-1
48 $lha x test-1.lzh
49                                                         check $?
50 diff test-1/test-a test-a
51                                                         check $?
52 diff test-1/test-b test-b
53                                                         check $?
54 diff test-1/test-c test-c
55                                                         check $?
56
57 message testing to generic, lh5, lh6 and lh7 method archive.
58 $lha co  test-m1.lzh test-a test-b test-c
59                                                         check $?
60 $lha co5 test-m5.lzh test-a test-b test-c
61                                                         check $?
62 $lha co6 test-m6.lzh test-a test-b test-c
63                                                         check $?
64 $lha co7 test-m7.lzh test-a test-b test-c
65                                                         check $?
66 $lha v test-m1.lzh | grep lh1
67                                                         check $?
68 $lha v test-m5.lzh | grep lh5
69                                                         check $?
70 $lha v test-m6.lzh | grep lh6
71                                                         check $?
72 $lha v test-m7.lzh | grep lh7
73                                                         check $?
74
75 $lha xw=test-m1 test-m1.lzh
76                                                         check $?
77 $lha xw=test-m5 test-m5.lzh
78                                                         check $?
79 $lha xw=test-m6 test-m6.lzh
80                                                         check $?
81 $lha xw=test-m7 test-m7.lzh
82                                                         check $?
83
84 diff -r test-1 test-m1
85                                                         check $?
86 diff -r test-1 test-m5
87                                                         check $?
88 diff -r test-1 test-m6
89                                                         check $?
90 diff -r test-1 test-m7
91                                                         check $?
92
93 message testing to print lha archive.
94
95 $lha pq test-m1.lzh test-a | diff test-a -
96                                                         check $?
97 $lha pq test-m5.lzh test-a | diff test-a -
98                                                         check $?
99 $lha pq test-m6.lzh test-a | diff test-a -
100                                                         check $?
101 $lha pq test-m7.lzh test-a | diff test-a -
102                                                         check $?
103
104 cat test-[abc] > test-abc
105 $lha pq test-m1.lzh | diff test-abc -
106                                                         check $?
107 $lha pq test-m5.lzh | diff test-abc -
108                                                         check $?
109 $lha pq test-m6.lzh | diff test-abc -
110                                                         check $?
111 $lha pq test-m7.lzh | diff test-abc -
112                                                         check $?
113
114 message testing to delete files from archive.
115
116 cp test-m5.lzh test-2.lzh
117
118 # do nothing
119 $lha d test-2.lzh 2> test-stderr
120                                                         check $?
121 test -s test-stderr
122                                                         check $?
123 $lha d test-2.lzh test-a
124                                                         check $?
125 $lha xw=test-2 test-2.lzh &&
126 test ! -f test-2/test-a &&
127 diff test-1/test-b test-2/test-b &&
128 diff test-1/test-c test-2/test-c
129                                                         check $?
130 rm -rf test-2
131                                                         check $?
132 $lha d test-2.lzh test-b
133                                                         check $?
134 $lha xw=test-2 test-2.lzh &&
135 test ! -f test-2/test-a &&
136 test ! -f test-2/test-b &&
137 diff test-1/test-c test-2/test-c
138                                                         check $?
139 rm -rf test-2
140                                                         check $?
141 $lha d test-2.lzh test-c 2> test-stderr
142                                                         check $?
143 test -s test-stderr
144                                                         check $?
145 test ! -f test-2.lzh
146                                                         check $?
147
148 message testing to treat stdin/stdout as archive file.
149
150 $lha c - test-a test-b test-c > test-3.lzh
151                                                         check $?
152 cat test-3.lzh | $lha xw=test-3 -
153                                                         check $?
154 diff -r test-m5 test-3
155                                                         check $?
156
157 message testing to treat stdin/stdout as file list.
158 # On MinGW, these tests will fail for now.
159 cat <<EOF | $lha c test-4.lzh
160 test-a
161 test-b
162 test-c
163 EOF
164                                                         check $?
165 echo test-b | $lha xw=test-4 test-4.lzh
166                                                         check $?
167 test ! -f test-4/test-a &&
168 test ! -f test-4/test-c &&
169 diff test-b test-4/test-b
170                                                         check $?
171
172 message testing to add/update files to archive.
173 $lha a test-5.lzh test-c
174                                                         check $?
175 $lha a test-5.lzh test-b
176                                                         check $?
177 $lha a test-5.lzh test-a
178                                                         check $?
179 $lha xw=test-5 test-5.lzh
180                                                         check $?
181 diff -r test-1 test-5
182                                                         check $?
183 mkdir test-5.2 &&
184 (cd test-5.2
185  echo foo > test-a
186  echo bar > test-b
187  echo baz > test-c
188
189  $lha u ../test-5.lzh test-[abc]
190 )
191                                                         check $?
192 $lha xw=test-5.3 test-5.lzh
193                                                         check $?
194 diff -r test-5.2 test-5.3
195                                                         check $?
196 # no update old files
197 (cd test-5 &&
198  $lha u ../test-5.lzh test-[abc]
199 )
200
201 $lha xw=test-5.4 test-5.lzh
202                                                         check $?
203 diff -r test-5.3 test-5.4
204                                                         check $?
205 # replace old files
206 (cd test-5 &&
207  $lha a ../test-5.lzh test-[abc]
208 )
209 $lha xw=test-5.5 test-5.lzh
210                                                         check $?
211 diff -r test-5 test-5.5
212                                                         check $?
213
214 exit $result