X-Git-Url: http://git.sourceforge.jp/view?p=lha%2Flha.git;a=blobdiff_plain;f=tests%2Flha-test.in;h=e9826ece2f4a551c7cd4c6dc68792f5ab2b9abc2;hp=5c10b7fbaf2045591ced86b664b58c3e88d33cef;hb=5160e711712d95b1cc155509aabb3cd02112c957;hpb=8f09dfb7668d1237feb6d0e55ec71b3e4c284f24 diff --git a/tests/lha-test.in b/tests/lha-test.in index 5c10b7f..e9826ec 100644 --- a/tests/lha-test.in +++ b/tests/lha-test.in @@ -1,99 +1,185 @@ #!/bin/bash +print_usage() +{ + cat </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 + : ${lha_dir=@top_builddir@/src} -: ${lha=$(cd $lha_dir && pwd)/lha} +: ${lha_cmd=$(cd $lha_dir && pwd)/lha} : ${srcdir=@srcdir@} +: ${builddir=$(cd @builddir@ && pwd)} -trap "rm -rf test-*" 0 1 2 3 15 +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 -declare -i test_number=0 +typeset -i i # for loop +typeset -i test_number=0 error_num=0 +error_tests="" -exec > test.log +# fd 1: for logging +# fd 2: output screen +# fd 5: for logging +exec 5>test.log >&5 -message() { +lha=exec_lha +exec_lha() +{ + echo "$ lha $@" >&5 # for logging (stdout(fd 1) may be redirected) + $lha_cmd "$@" +} + +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 } -seq() { - awk 'BEGIN { - for (i = 0; i < '$1'; i++) print i - }' +# 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 } cleanup() { - rm -rf test-tmp* + 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 } -# create test data +# utility functions -message testing $lha -message testing to create/list/extract lha archive. +change_timestamp() +{ + typeset time=$1; shift -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 $? - -# followings are test data for remaining tests. -test -f test-1.lzh && -test -f test-a && -test -f test-b && -test -f test-c && -test -d test-1 && -test -f test-1/test-a && -test -f test-1/test-b && -test -f test-1/test-c - check $? - - -. $srcdir/lha-test2; cleanup -. $srcdir/lha-test3; cleanup -. $srcdir/lha-test4; cleanup -. $srcdir/lha-test5; cleanup -# . $srcdir/lha-test6; cleanup # this feature was removed. -. $srcdir/lha-test7; cleanup -. $srcdir/lha-test8; cleanup -case `$lha --version 2>&1` in -*pc-cygwin*|*pc-mingw*) - message testing extracting to existent files ... skip;; -*) -# . $srcdir/lha-test9; cleanup + # 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 ;; -esac -. $srcdir/lha-test10; cleanup + *) + 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