From: Eric Blake Date: Fri, 20 May 2011 14:57:54 +0000 (-0600) Subject: test-perror: rewrite to use init script X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98c78cdfd3685675c0ebdd157778656877b2eec4;p=pspp test-perror: rewrite to use init script Make the test simpler, and also check for correct exit status. * modules/perror-tests (Files): Add init.sh. * tests/test-perror.sh: Use temporary directory. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index f42002cbf6..30bccca375 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-05-20 Eric Blake + + test-perror: rewrite to use init script + * modules/perror-tests (Files): Add init.sh. + * tests/test-perror.sh: Use temporary directory. + 2011-05-20 Jim Meyering maint: replace misused "a" with "an" diff --git a/modules/perror-tests b/modules/perror-tests index 867f920260..bad23fd9c6 100644 --- a/modules/perror-tests +++ b/modules/perror-tests @@ -1,4 +1,5 @@ Files: +tests/init.sh tests/signature.h tests/test-perror.c tests/test-perror.sh diff --git a/tests/test-perror.sh b/tests/test-perror.sh index f2c8fdc336..28027ea58e 100755 --- a/tests/test-perror.sh +++ b/tests/test-perror.sh @@ -1,27 +1,24 @@ #!/bin/sh - -tmpfiles="" -trap 'rm -fr $tmpfiles' 1 2 3 15 +: ${srcdir=.} +. "$srcdir/init.sh"; path_prepend_ . # Test NULL prefix. Result should not contain a number. -tmpfiles="$tmpfiles t-perror.tmp" -./test-perror${EXEEXT} 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror.tmp -if grep '[0-9]' t-perror.tmp > /dev/null; then - rm -fr $tmpfiles; exit 1 -fi +test-perror 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror.tmp +grep '[0-9]' t-perror.tmp > /dev/null \ + && fail_ "result should not contain a number" # Test empty prefix. Result should be the same. -tmpfiles="$tmpfiles t-perror1.tmp" -./test-perror${EXEEXT} '' 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror1.tmp -diff t-perror.tmp t-perror1.tmp -test $? = 0 || { rm -fr $tmpfiles; exit 1; } +test-perror '' 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror1.tmp +diff t-perror.tmp t-perror1.tmp \ + || fail_ "empty prefix should behave like NULL argument" # Test non-empty prefix. -tmpfiles="$tmpfiles t-perror2.tmp t-perror3.tmp" -./test-perror${EXEEXT} 'foo' 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror3.tmp +test-perror foo 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror3.tmp sed -e 's/^/foo: /' < t-perror.tmp > t-perror2.tmp -diff t-perror2.tmp t-perror3.tmp -test $? = 0 || { rm -fr $tmpfiles; exit 1; } +diff t-perror2.tmp t-perror3.tmp || fail_ "prefix applied incorrectly" + +# Test exit status. +test-perror >out 2>/dev/null || fail_ "unexpected exit status" +test -s out && fail_ "unexpected output" -rm -fr $tmpfiles exit 0