OSDN Git Service

lha-test19 is added for timestamping archive feature
[lha/lha.git] / tests / lha-test.in
1 #!/bin/bash
2
3 print_usage()
4 {
5   cat <<EOF
6 usage: $0 [-n] [test number]
7
8 option:
9    -n:   do not cleanup.
10 EOF
11   exit
12 }
13
14 for _opt
15 do
16    case $_opt in
17    --help) print_usage ;;
18    -n) no_cleanup=true; shift ;;
19    *) perform_number=$1; shift ;;
20    esac
21 done
22
23 # Be Bourne compatible
24 # -- followings are derived from configure script generated by autoconf 2.59 --
25 if test -n "${ZSH_VERSION+set}" && (emulate ksh) >/dev/null 2>&1; then
26   emulate ksh
27   NULLCMD=:
28   # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
29   # is contrary to our usage.  Disable this feature.
30   alias -g '${1+"$@"}'='"$@"'
31 elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
32   set -o posix
33 fi
34 DUALCASE=1; export DUALCASE # for MKS sh
35
36 : ${lha_dir=@top_builddir@/src}
37 : ${lha_cmd=$(cd $lha_dir && pwd)/lha}
38 : ${srcdir=@srcdir@}
39 : ${builddir=$(cd @builddir@ && pwd)}
40
41 if [[ x$no_cleanup = x ]]; then
42   trap '_stat=$?; chmod -R 755 test-* 2>/dev/null;
43         rm -rf test-*; exit $_stat' 0 1 2 3 15
44 fi
45
46 typeset -i i    # for loop
47 typeset -i test_number=0 error_num=0
48 error_tests=""
49
50 # fd 1: for logging
51 # fd 2: output screen
52 # fd 5: for logging
53 exec 5>test.log >&5
54
55 lha=exec_lha
56 exec_lha()
57 {
58   echo "$ lha $@" >&5   # for logging (stdout(fd 1) may be redirected)
59   $lha_cmd "$@"
60 }
61
62 message()
63 {
64   echo "$@" >&2
65   echo "$@"
66 }
67
68 check()
69 {
70   ((test_number = test_number + 1))
71   typeset exit_status=$1
72   typeset lineno=$2
73   if [[ $exit_status -eq 0 ]]; then
74     echo    "$FILENAME #$test_number ... ok" >&2
75     echo    "$FILENAME #$test_number ... ok at line $lineno"
76   else
77     message "$FILENAME #$test_number ... failed at line $lineno"
78     ((error_num = error_num + 1))
79     error_tests="$error_tests $FILENAME #$test_number"
80     result=1
81   fi
82 }
83
84 cleanup()
85 {
86   if [[ x$no_cleanup = x ]]; then
87     chmod -R 755 test-tmp* 2>/dev/null
88     rm -rf test-tmp*
89   fi
90 }
91
92 testsuite()
93 {
94     # the `FILENAME' variable should be set the each test filename.
95     FILENAME=$1 test_number=0
96
97     . $srcdir/$FILENAME
98
99     cleanup
100 }
101
102 # utility functions
103
104 change_timestamp()
105 {
106     typeset time=$1; shift
107
108     # assume that `touch' command supports POSIX's -t switch.
109
110     # -t [[CC]YY]MMDDhhmm[.ss]
111     touch -t $time "$@"
112
113     # [[CC]YY]MMDDhhmm
114     # touch $time "$@"
115 }
116
117 identical_timestamp()
118 {
119     test "$1" -nt "$2" || test "$1" -ot "$2"
120     test $? -ne 0
121 }
122
123 # test start
124
125 message testing $lha_cmd
126 message `$lha --version 2>&1`
127
128 testsuite lha-test1             # create test data. it is needed for each test
129
130 if [[ $perform_number != "" ]] && [[ $perform_number != all ]]; then
131   testsuite lha-test$perform_number
132 else
133   testsuite lha-test2
134   testsuite lha-test3
135   testsuite lha-test4
136   testsuite lha-test5
137   #testsuite lha-test6          # this feature was removed.
138   testsuite lha-test7
139   testsuite lha-test8
140   #testsuite lha-test9          # incomplete
141   testsuite lha-test10
142   testsuite lha-test11
143   testsuite lha-test12
144   testsuite lha-test13
145   case `$lha --version 2>&1` in
146   *djgpp* | *-pc-mingw*)
147     # No symlink support on DJGPP and MinGW
148     message testing to handle symbolic links ... skip
149     ;;
150   *)
151     testsuite lha-test14
152     ;;
153   esac
154   testsuite lha-test15
155   testsuite lha-test16
156   testsuite lha-test17
157   testsuite lha-test18
158   testsuite lha-test19
159   # followings will take a long time
160   if [[ $perform_number = all ]]; then
161     testsuite lha-test51        # extract 2G over files
162     testsuite lha-test52        # extract 4G over files
163   fi
164 fi
165
166 if (( $error_num != 0 )); then
167   message $error_num tests failed!
168   message test number: $error_tests
169 fi
170
171 exit $result