OSDN Git Service

*** empty log message ***
[lha/lha.git] / tests / lha-test.in
1 #!/bin/bash
2
3 : ${lha_dir=@top_builddir@/src}
4 : ${lha=$(cd $lha_dir && pwd)/lha}
5 : ${srcdir=@srcdir@}
6
7 trap "rm -rf test-*" 0 1 2 3 15
8
9 declare -i test_number=0 error_num=0
10 error_tests=""
11
12 exec > test.log
13
14 message() {
15   echo "$@" >&2
16   echo "$@"
17 }
18
19 check() {
20   ((test_number = test_number + 1))
21   local status=$1
22   local lineno=$2
23   if [[ $status -eq 0 ]]; then
24     message test $test_number ... ok
25     echo at line $lineno
26   else
27     message test $test_number ... failed at line $lineno
28     ((error_num = error_num + 1))
29     error_tests="$error_tests #$test_number"
30     result=1
31   fi
32 }
33
34 seq() {
35   awk 'BEGIN {
36     for (i = 0; i < '$1'; i++) print i
37   }'
38 }
39
40 cleanup()
41 {
42   rm -rf test-tmp*
43 }
44
45 # create test data
46
47 message testing $lha
48 message testing to create/list/extract lha archive.
49
50 for i in `seq 100`
51 do
52     echo foo >> test-a
53 done
54 sed 's/foo/bar/g' < test-a > test-b
55 sed 's/foo/baz/g' < test-a > test-c
56
57 $lha c test-1.lzh test-a test-b test-c
58                                                         check $? $LINENO
59 test -s test-1.lzh
60                                                         check $? $LINENO
61
62 $lha l test-1.lzh
63                                                         check $? $LINENO
64
65 test -d test-1 || mkdir test-1
66 mv test-[abc] test-1
67 $lha x test-1.lzh
68                                                         check $? $LINENO
69 diff test-1/test-a test-a
70                                                         check $? $LINENO
71 diff test-1/test-b test-b
72                                                         check $? $LINENO
73 diff test-1/test-c test-c
74                                                         check $? $LINENO
75
76 # followings are test data for remaining tests.
77 test -f test-1.lzh &&
78 test -f test-a &&
79 test -f test-b &&
80 test -f test-c &&
81 test -d test-1 &&
82 test -f test-1/test-a &&
83 test -f test-1/test-b &&
84 test -f test-1/test-c
85                                                         check $? $LINENO
86
87
88 . $srcdir/lha-test2; cleanup
89 . $srcdir/lha-test3; cleanup
90 . $srcdir/lha-test4; cleanup
91 . $srcdir/lha-test5; cleanup
92 # . $srcdir/lha-test6; cleanup          # this feature was removed.
93 . $srcdir/lha-test7; cleanup
94 . $srcdir/lha-test8; cleanup
95 case `$lha --version 2>&1` in
96 *pc-cygwin*|*pc-mingw*)
97     message testing extracting to existent files ... skip;;
98 *)
99 #    . $srcdir/lha-test9; cleanup
100     ;;
101 esac
102 . $srcdir/lha-test10; cleanup
103
104 if (( $error_num != 0 )); then
105   echo $error_num tests failed! >&2
106   echo test number: $error_tests >&2
107 fi
108
109 exit $result