OSDN Git Service

Add a compiler clang
[lha/lha.git] / tests / lha-test.in
index 30e8c6d..e9826ec 100644 (file)
 #!/bin/bash
 
-: ${lha_dir=@top_builddir@/src}
-: ${lha=$(cd $lha_dir && pwd)/lha}
+print_usage()
+{
+  cat <<EOF
+usage: $0 [-n] [test number]
+
+option:
+   -n:   do not cleanup.
+EOF
+  exit
+}
 
-trap "rm -rf test-*" 0 1 2 3 15
+for _opt
+do
+   case $_opt in
+   --help) print_usage ;;
+   -n) no_cleanup=true; shift ;;
+   *) perform_number=$1; shift ;;
+   esac
+done
 
-declare -i test_number=0
+# Be Bourne compatible
+# -- followings are derived from configure script generated by autoconf 2.59 --
+if test -n "${ZSH_VERSION+set}" && (emulate ksh) >/dev/null 2>&1; then
+  emulate ksh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+  set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
 
-exec > test.log
+: ${lha_dir=@top_builddir@/src}
+: ${lha_cmd=$(cd $lha_dir && pwd)/lha}
+: ${srcdir=@srcdir@}
+: ${builddir=$(cd @builddir@ && pwd)}
+
+if [[ x$no_cleanup = x ]]; then
+  trap '_stat=$?; chmod -R 755 test-* 2>/dev/null;
+        rm -rf test-*; exit $_stat' 0 1 2 3 15
+fi
+
+typeset -i i   # for loop
+typeset -i test_number=0 error_num=0
+error_tests=""
+
+# fd 1: for logging
+# fd 2: output screen
+# fd 5: for logging
+exec 5>test.log >&5
+
+lha=exec_lha
+exec_lha()
+{
+  echo "$ lha $@" >&5  # for logging (stdout(fd 1) may be redirected)
+  $lha_cmd "$@"
+}
 
-message() {
+message()
+{
   echo "$@" >&2
   echo "$@"
 }
 
-check() {
+check()
+{
   ((test_number = test_number + 1))
-  local status=$1
-  if [[ $status -eq 0 ]]; then
-    message test $test_number ... ok
+  typeset exit_status=$1
+  typeset lineno=$2
+  if [[ $exit_status -eq 0 ]]; then
+    echo    "$FILENAME #$test_number ... ok" >&2
+    echo    "$FILENAME #$test_number ... ok at line $lineno"
   else
-    message test $test_number ... failed
+    message "$FILENAME #$test_number ... failed at line $lineno"
+    ((error_num = error_num + 1))
+    error_tests="$error_tests $FILENAME #$test_number"
     result=1
   fi
 }
 
-message testing $lha
-message testing to create/list/extract lha archive.
+# On HP-UX 11.23, "chmod -R" cannot change the file permission in
+# non-writable and non-executable directory.
+chmod_R()
+{
+  typeset mode="$1"; shift
+  for x in "$@"
+  do
+    chmod $mode "$x"
+    test -d "$x" && (cd "$x" && chmod_R $mode *)
+  done
+}
 
-for i in `seq 100`
-do
-    echo foo >> test-a
-done
-sed 's/foo/bar/g' < test-a > test-b
-sed 's/foo/baz/g' < test-a > test-c
-
-$lha c test-1.lzh test-a test-b test-c
-                                                       check $?
-test -s test-1.lzh
-                                                       check $?
-
-$lha l test-1.lzh
-                                                       check $?
-
-test -d test-1 || mkdir test-1
-mv test-[abc] test-1
-$lha x test-1.lzh
-                                                       check $?
-diff test-1/test-a test-a
-                                                       check $?
-diff test-1/test-b test-b
-                                                       check $?
-diff test-1/test-c test-c
-                                                       check $?
-
-message testing to generic, lh5, lh6 and lh7 method archive.
-$lha co  test-m1.lzh test-a test-b test-c
-                                                       check $?
-$lha co5 test-m5.lzh test-a test-b test-c
-                                                       check $?
-$lha co6 test-m6.lzh test-a test-b test-c
-                                                       check $?
-$lha co7 test-m7.lzh test-a test-b test-c
-                                                       check $?
-$lha v test-m1.lzh | grep lh1
-                                                       check $?
-$lha v test-m5.lzh | grep lh5
-                                                       check $?
-$lha v test-m6.lzh | grep lh6
-                                                       check $?
-$lha v test-m7.lzh | grep lh7
-                                                       check $?
-
-$lha xw=test-m1 test-m1.lzh
-                                                       check $?
-$lha xw=test-m5 test-m5.lzh
-                                                       check $?
-$lha xw=test-m6 test-m6.lzh
-                                                       check $?
-$lha xw=test-m7 test-m7.lzh
-                                                       check $?
-
-diff -r test-1 test-m1
-                                                       check $?
-diff -r test-1 test-m5
-                                                       check $?
-diff -r test-1 test-m6
-                                                       check $?
-diff -r test-1 test-m7
-                                                       check $?
-
-message testing to print lha archive.
-
-$lha pq test-m1.lzh test-a | diff test-a -
-                                                       check $?
-$lha pq test-m5.lzh test-a | diff test-a -
-                                                       check $?
-$lha pq test-m6.lzh test-a | diff test-a -
-                                                       check $?
-$lha pq test-m7.lzh test-a | diff test-a -
-                                                       check $?
-
-cat test-[abc] > test-abc
-$lha pq test-m1.lzh | diff test-abc -
-                                                       check $?
-$lha pq test-m5.lzh | diff test-abc -
-                                                       check $?
-$lha pq test-m6.lzh | diff test-abc -
-                                                       check $?
-$lha pq test-m7.lzh | diff test-abc -
-                                                       check $?
-
-message testing to delete files from archive.
-
-cp test-m5.lzh test-2.lzh
-
-# do nothing
-$lha d test-2.lzh 2> test-stderr
-                                                       check $?
-test -s test-stderr
-                                                       check $?
-$lha d test-2.lzh test-a
-                                                       check $?
-$lha xw=test-2 test-2.lzh &&
-test ! -f test-2/test-a &&
-diff test-1/test-b test-2/test-b &&
-diff test-1/test-c test-2/test-c
-                                                       check $?
-rm -rf test-2
-                                                       check $?
-$lha d test-2.lzh test-b
-                                                       check $?
-$lha xw=test-2 test-2.lzh &&
-test ! -f test-2/test-a &&
-test ! -f test-2/test-b &&
-diff test-1/test-c test-2/test-c
-                                                       check $?
-rm -rf test-2
-                                                       check $?
-$lha d test-2.lzh test-c 2> test-stderr
-                                                       check $?
-test -s test-stderr
-                                                       check $?
-test ! -f test-2.lzh
-                                                       check $?
-
-message testing to treat stdin/stdout as archive file.
-
-$lha c - test-a test-b test-c > test-3.lzh
-                                                       check $?
-cat test-3.lzh | $lha xw=test-3 -
-                                                       check $?
-diff -r test-m5 test-3
-                                                       check $?
-
-# message testing to treat stdin/stdout as file list.
-# # On MinGW, these tests will fail for now.
-# cat <<EOF | $lha c test-4.lzh
-# test-a
-# test-b
-# test-c
-# EOF
-#                                                      check $?
-# echo test-b | $lha xw=test-4 test-4.lzh
-#                                                      check $?
-# test ! -f test-4/test-a &&
-# test ! -f test-4/test-c &&
-# diff test-b test-4/test-b
-#                                                      check $?
-
-message testing to add/update files to archive.
-$lha a test-5.lzh test-c
-                                                       check $?
-$lha a test-5.lzh test-b
-                                                       check $?
-$lha a test-5.lzh test-a
-                                                       check $?
-$lha xw=test-5 test-5.lzh
-                                                       check $?
-diff -r test-1 test-5
-                                                       check $?
-mkdir test-5.2 &&
-(cd test-5.2
- echo foo > test-a
- echo bar > test-b
- echo baz > test-c
-
- $lha u ../test-5.lzh test-[abc]
-)
-                                                       check $?
-$lha xw=test-5.3 test-5.lzh
-                                                       check $?
-diff -r test-5.2 test-5.3
-                                                       check $?
-# no update old files
-(cd test-5 &&
- $lha u ../test-5.lzh test-[abc]
-)
-
-$lha xw=test-5.4 test-5.lzh
-                                                       check $?
-diff -r test-5.3 test-5.4
-                                                       check $?
-# replace old files
-(cd test-5 &&
- $lha a ../test-5.lzh test-[abc]
-)
-$lha xw=test-5.5 test-5.lzh
-                                                       check $?
-diff -r test-5 test-5.5
-                                                       check $?
+cleanup()
+{
+  if [[ x$no_cleanup = x ]]; then
+    chmod_R 755 test-tmp* 2>/dev/null
+    rm -rf test-tmp*
+  fi
+}
+
+testsuite()
+{
+    # the `FILENAME' variable should be set the each test filename.
+    FILENAME=$1 test_number=0
+
+    . $srcdir/$FILENAME
+
+    cleanup
+}
+
+# utility functions
+
+change_timestamp()
+{
+    typeset time=$1; shift
+
+    # assume that `touch' command supports POSIX's -t switch.
+
+    # -t [[CC]YY]MMDDhhmm[.ss]
+    touch -t $time "$@"
+
+    # [[CC]YY]MMDDhhmm
+    # touch $time "$@"
+}
+
+identical_timestamp()
+{
+    test "$1" -nt "$2" || test "$1" -ot "$2"
+    test $? -ne 0
+}
+
+# test start
+
+message testing $lha_cmd
+message `$lha --version 2>&1`
+
+testsuite lha-test1            # create test data. it is needed for each test
+
+if [[ $perform_number != "" ]] && [[ $perform_number != all ]]; then
+  testsuite lha-test$perform_number
+else
+  testsuite lha-test2
+  testsuite lha-test3
+  testsuite lha-test4
+  testsuite lha-test5
+  #testsuite lha-test6         # this feature was removed.
+  testsuite lha-test7
+  testsuite lha-test8
+  #testsuite lha-test9         # incomplete
+  testsuite lha-test10
+  testsuite lha-test11
+  testsuite lha-test12
+  testsuite lha-test13
+  case `$lha --version 2>&1` in
+  *djgpp* | *-pc-mingw*)
+    # No symlink support on DJGPP and MinGW
+    message testing to handle symbolic links ... skip
+    ;;
+  *)
+    testsuite lha-test14
+    ;;
+  esac
+  testsuite lha-test15
+  testsuite lha-test16
+  testsuite lha-test17
+  testsuite lha-test18
+  testsuite lha-test19
+  # followings will take a long time
+  if [[ $perform_number = all ]]; then
+    testsuite lha-test51       # extract 2G over files
+    testsuite lha-test52       # extract 4G over files
+  fi
+fi
+
+if (( $error_num != 0 )); then
+  message $error_num tests failed!
+  message test number: $error_tests
+else
+  message All tests succeeded.
+fi
 
 exit $result