OSDN Git Service

update Hacking_of_LHa
[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 # test start
118
119 message testing $lha_cmd
120 message `$lha --version 2>&1`
121
122 testsuite lha-test1             # create test data. it is needed for each test
123
124 if [[ $perform_number != "" ]] && [[ $perform_number != all ]]; then
125   testsuite lha-test$perform_number
126 else
127   testsuite lha-test2
128   testsuite lha-test3
129   testsuite lha-test4
130   testsuite lha-test5
131   #testsuite lha-test6          # this feature was removed.
132   testsuite lha-test7
133   testsuite lha-test8
134   #testsuite lha-test9          # incomplete
135   testsuite lha-test10
136   testsuite lha-test11
137   testsuite lha-test12
138   testsuite lha-test13
139   case `$lha --version 2>&1` in
140   *djgpp* | *-pc-mingw*)
141     # No symlink support on DJGPP and MinGW
142     message testing to handle symbolic links ... skip
143     ;;
144   *)
145     testsuite lha-test14
146   esac
147   testsuite lha-test15
148   testsuite lha-test16
149   testsuite lha-test17
150   testsuite lha-test18
151   # followings will take a long time
152   if [[ $perform_number = all ]]; then
153     testsuite lha-test51        # extract 2G over files
154     testsuite lha-test52        # extract 4G over files
155   fi
156 fi
157
158 if (( $error_num != 0 )); then
159   message $error_num tests failed!
160   message test number: $error_tests
161 fi
162
163 exit $result