[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test-xalloc-die buglet
From: |
Jim Meyering |
Subject: |
Re: test-xalloc-die buglet |
Date: |
Tue, 17 Nov 2009 20:23:20 +0100 |
Eric Blake wrote:
...
> test ! -s $tmpout || { (exit 1); exit 1; }
>
> Hmm, I'm really starting to like the idea of a common init script, so we can
> just do "Exit 1" instead of "{ (exit 1); exit 1; }".
Exactly.
The next question is whether to automatically create a temporary directory
for each test. Of course, it would be deleted automatically.
I'm debating whether to do it in two steps or one.
Here's most of step1's init.sh, assuming a two-step approach:
1) make each script use init.sh, convert all exit to Exit, and remove
now-unnecessary rm -rf $tmpfiles stmts.
2) change init.sh to create tmpdir, and cd into it before the test is
run, and then clean up via trap.
The tmpdir-creation could be handled by the function in build-aux/mkdtemp.
AFAIK, it is portable enough, though if used as a function, rather
than exec'd, it will need some work to be more name-space friendly
and use clobber variables with names like $n.
Here's the beginnings of init.sh:
Namespace matters. Notice $_tmpfiles.
Not sure if it's worth adding underscores to _exit and _compare.
What do you think?
-------------------------
# source this file; set up for tests
# Copyright (C) 2009 Free Software Foundation, Inc.
... copyright elided...
# We use a trap below for cleanup. This requires us to go through
# hoops to get the right exit status transported through the signal.
# So use `Exit STATUS' instead of `exit STATUS' inside of the tests.
# Turn off errexit here so that we don't trip the bug with OSF1/Tru64
# sh inside this function.
Exit ()
{
set +e
(exit $1)
exit $1
}
# This pair of trap statements ensures that $tmpfiles are removed
# upon interrupt and upon exit.
_tmpfiles=""
trap '__st=$?; rm -fr $_tmpfiles; exit $__st' 0
trap '__st=$?; Exit $__st' 1 2 3 15
if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
compare() { diff -u "$@"; }
elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
compare() { cmp -s "$@"; }
else
compare() { cmp "$@"; }
fi