?? posix2.tests
字號:
#! /bin/sh# posix-2.sh - Simple identification tests for POSIX.2 features# commonly missing or incorrectly implemented.# Time-stamp: <96/04/10 16:43:48 gildea># By Stephen Gildea <gildea@x.org> March 1995## Copyright (c) 1995 Stephen Gildea# Permission is hereby granted to deal in this Software without restriction.# THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.## MODIFIED BY chet@po.cwru.edu to make part of the bash test suite.# last change: Wed Jun 19 12:24:24 EDT 1996## some of the tests:## shell functions (do we care?)# var=${var:-val}# unset# set --# IFS parsing## not exiting with -e and failed "if", the way Ultrix does (Ultrix 4.2?)# "$@" expands to zero arguments if passed zero arguments# $SHELL -c 'echo $1' bad good# test -x# positional parameters greater than 9# arithmetic expansion $(( ... ))# getopts# For some tests we must run a sub-shell; $TESTSHELL says what to use.# If set, TESTSHELL must be an absolute pathname.# For example, on HP-UX 9, /bin/posix/sh is the supposedly-compliant shell.TESTSHELL=${THIS_SH:-$PWD/../bash}# these tests create temp files with names $TMPDIR/conf*: ${TMPDIR:=/tmp}exitval=0numtests=0echo "Testing for POSIX.2 conformance"newtest(){ numtests=$(($numtests + 1))}testfail(){ echo "$1 test failed" exitval=$(($exitval + 1))}newtestempty=""test "${empty:-ok}" = ok || testfail "empty var colon"newtesttest "${empty-bad}" = "" || testfail "got \"${empty-bad}\": empty var nocolon"newtesttest "${unsetvar-ok}" = ok || testfail "unset var"newtestunset emptytest "${empty-ok}" = ok || testfail "unset"newtestset -- -Ztest "x$1" = x-Z || testfail '\"set -- arg\"'# this should empty the argument listnewtestset --test $# = 0 || testfail "still $# args: \"set --\""# IFS parsing:newtestnames=one/good/threesaved_ifs="$IFS"IFS=/set $names losetest "$2" = good || testfail "got \"$2\": IFS parsing"IFS="$saved_ifs"# "$@" with 0 arguments should expand to 0 argumentsnewtestcat > $TMPDIR/conftest1 << EOF$TMPDIR/conftest2 "\$@"EOFcat > $TMPDIR/conftest2 << "EOF"#! /bin/shecho $#EOFchmod +x $TMPDIR/conftest1 $TMPDIR/conftest2numargs=$($TESTSHELL $TMPDIR/conftest1)if [ "$?" != 0 ]; then testfail 'running $@'else test "$numargs" = 0 || testfail '"$@" got '"$numargs args: expansion w 0 args"firm -f $TMPDIR/conftest1 $TMPDIR/conftest2newtestval=$("$TESTSHELL" -c 'echo $1' csh good)test "$val" = good || testfail "got \"$val\": sh -c"newtest# do these tests in a sub-shell because failure will exitval=$("$TESTSHELL" -c 'echo ${10}' 0 1 2 3 4 5 6 7 8 9 ten 11 2> /dev/null)test "$val" = ten || testfail "accessing more than 9 positional params"a=abc_def_ghiexport anewtest; val=`"$TESTSHELL" -c 'echo "${a%_*}"' 2> /dev/null`test "$val" = abc_def || testfail "parameter % op"newtest; val=`"$TESTSHELL" -c 'echo "${a%%_*}"' 2> /dev/null`test "$val" = abc || testfail "parameter %% op"newtest; val=`"$TESTSHELL" -c 'echo "${a#*_}"' 2> /dev/null`test "$val" = def_ghi || testfail "parameter # op"newtest; val=`"$TESTSHELL" -c 'echo "${a##*_}"' 2> /dev/null`test "$val" = ghi || testfail "parameter ## op"newtest"$TESTSHELL" -c 'export a=value' 2> /dev/null || testfail "export with value"newtesta=5; test "$(( ($a+1)/2 ))" = 3 || testfail "arithmetic expansion"# does "test" support the -x switch?newtesttouch $TMPDIR/conftestchmod -x $TMPDIR/conftesttest -x $TMPDIR/conftest && testfail "negative test -x"chmod +x $TMPDIR/conftesttest -x $TMPDIR/conftest || testfail "positive test -x"rm -f $TMPDIR/conftestnewtesttest "$OPTIND" = 1 || testfail "OPTIND initial value"newtestgetopts a: store -a aoptvalif [ "$OPTIND" != 3 ] || [ "$store" != a ] || [ "$OPTARG" != aoptval ]; then testfail "getopts"fi# if I change the default quoting style for variable values, these# next four must changenewtestSQUOTE="'"val1=$(set | sed -n 's:^SQUOTE=::p')if [ "$val1" != "''\\'''" ]; then testfail "variable quoting 1"finewtestVTILDE='~'val1=$(set | sed -n 's:^VTILDE=::p')if [ "$val1" != "'~'" ]; then testfail "variable quoting 2"finewtestVHASH=ab#cdval1=$(set | sed -n 's:^VHASH=::p')if [ "$val1" != "ab#cd" ]; then testfail "variable quoting 3"finewtestVHASH2=#abcdval1=$(set | sed -n 's:^VHASH2=::p')if [ "$val1" != "'#abcd'" ]; then testfail "variable quoting 4"fiif [ $exitval = 0 ]; then echo "All tests passed"else echo "$exitval of $numtests tests failed"fiexit $exitval
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -