OSDN Git Service

1dc8632e11e19125be7f9375279a12b36dd72b3f
[lha/lha.git] / tests / lha-test.in
1 #!/bin/bash
2
3 : ${lha_dir=@top_builddir@/src}
4 : ${lha_cmd=$(cd $lha_dir && pwd)/lha}
5 : ${srcdir=@srcdir@}
6
7 trap '_stat=$?; rm -rf test-*; exit $_stat' 0 1 2 3 15
8
9 typeset -i i    # for loop
10 typeset -i test_number=0 error_num=0
11 error_tests=""
12
13 # fd 1: for logging
14 # fd 2: output screen
15 # fd 5: for logging
16 exec 5>test.log >&5
17
18 lha=exec_lha
19 exec_lha()
20 {
21   echo "$ lha $@" >&5   # for logging (stdout(fd 1) may be redirected)
22   $lha_cmd "$@"
23 }
24
25 message()
26 {
27   echo "$@" >&2
28   echo "$@"
29 }
30
31 check()
32 {
33   ((test_number = test_number + 1))
34   typeset status=$1
35   typeset lineno=$2
36   if [[ $status -eq 0 ]]; then
37     echo    "$FILENAME #$test_number ... ok" >&2
38     echo    "$FILENAME #$test_number ... ok at line $lineno"
39   else
40     message "$FILENAME #$test_number ... failed at line $lineno"
41     ((error_num = error_num + 1))
42     error_tests="$error_tests $FILENAME #$test_number"
43     result=1
44   fi
45 }
46
47 cleanup()
48 {
49   rm -rf test-tmp*
50 }
51
52 testsuite()
53 {
54     # the `FILENAME' variable should be set the each test filename.
55     FILENAME=$1 test_number=0
56
57     . $srcdir/$FILENAME
58
59     cleanup
60 }
61
62 # utility functions
63
64 change_timestamp()
65 {
66     typeset time=$1; shift
67
68     # assume that `touch' command supports POSIX's -t switch.
69
70     # -t [[CC]YY]MMDDhhmm[.ss]
71     touch -t $time "$@"
72
73     # [[CC]YY]MMDDhhmm
74     # touch $time "$@"
75 }
76
77 # test start
78
79 message testing $lha
80 message `$lha --version 2>&1`
81
82 testsuite lha-test1             # create test data. it is needed for each test
83 testsuite lha-test2
84 testsuite lha-test3
85 testsuite lha-test4
86 testsuite lha-test5
87 #testsuite lha-test6            # this feature was removed.
88 testsuite lha-test7
89 testsuite lha-test8
90 #testsuite lha-test9            # incomplete
91 testsuite lha-test10
92 testsuite lha-test11
93 testsuite lha-test12
94 testsuite lha-test13
95 case `$lha --version 2>&1` in
96 *-pc-mingw*)
97   message testing to handle symbolic links ... skip
98   ;;
99 *)
100   testsuite lha-test14
101 esac
102 testsuite lha-test15
103
104 if (( $error_num != 0 )); then
105   message $error_num tests failed!
106   message test number: $error_tests
107 fi
108
109 exit $result