mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-14 00:37:41 -04:00
Use 'trap' builtin to clean up temporaries in test scripts
Some of the test scripts create temporary files, which we remove at the end. Except that we usually forgot to remove them on some exit paths. To avoid this problem in future, this modifies the scripts to use the shell's trap 0 functionality to automatically remove the temporaries on any exit. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
9a50d82c4e
commit
2ca83614e7
3 changed files with 10 additions and 16 deletions
|
@ -10,9 +10,9 @@ for x; do
|
||||||
CHECKS="$CHECKS $x"
|
CHECKS="$CHECKS $x"
|
||||||
done
|
done
|
||||||
|
|
||||||
LOG="tmp.log.$$"
|
LOG=tmp.log.$$
|
||||||
|
|
||||||
rm -f $LOG
|
rm -f $LOG
|
||||||
|
trap "rm -f $LOG" 0
|
||||||
|
|
||||||
verbose_run_log "$LOG" $VALGRIND "$DTC" -o /dev/null "$@"
|
verbose_run_log "$LOG" $VALGRIND "$DTC" -o /dev/null "$@"
|
||||||
ret="$?"
|
ret="$?"
|
||||||
|
@ -28,6 +28,4 @@ for c in $CHECKS; do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
rm -f $LOG
|
|
||||||
|
|
||||||
PASS
|
PASS
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
. ./tests.sh
|
. ./tests.sh
|
||||||
|
|
||||||
LOG="tmp.log.$$"
|
LOG=tmp.log.$$
|
||||||
EXPECT="tmp.expect.$$"
|
EXPECT=tmp.expect.$$
|
||||||
|
rm -f $LOG $EXPECT
|
||||||
rm -f $LOG
|
trap "rm -f $LOG $EXPECT" 0
|
||||||
|
|
||||||
expect="$1"
|
expect="$1"
|
||||||
echo "$expect" >$EXPECT
|
echo "$expect" >$EXPECT
|
||||||
|
@ -26,8 +26,6 @@ fi
|
||||||
diff $EXPECT $LOG
|
diff $EXPECT $LOG
|
||||||
ret="$?"
|
ret="$?"
|
||||||
|
|
||||||
rm -f $LOG $EXPECT
|
|
||||||
|
|
||||||
if [ "$ret" -eq 0 ]; then
|
if [ "$ret" -eq 0 ]; then
|
||||||
PASS
|
PASS
|
||||||
else
|
else
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
|
|
||||||
. ./tests.sh
|
. ./tests.sh
|
||||||
|
|
||||||
LOG="tmp.log.$$"
|
LOG=tmp.log.$$
|
||||||
EXPECT="tmp.expect.$$"
|
EXPECT=tmp.expect.$$
|
||||||
|
rm -f $LOG $EXPECT
|
||||||
rm -f $LOG
|
trap "rm -f $LOG $EXPECT" 0
|
||||||
|
|
||||||
expect="$1"
|
expect="$1"
|
||||||
echo "$expect" >$EXPECT
|
echo "$expect" >$EXPECT
|
||||||
|
@ -46,8 +46,6 @@ fi
|
||||||
diff $EXPECT $LOG
|
diff $EXPECT $LOG
|
||||||
ret="$?"
|
ret="$?"
|
||||||
|
|
||||||
rm -f $LOG $EXPECT
|
|
||||||
|
|
||||||
if [ "$ret" -eq 0 ]; then
|
if [ "$ret" -eq 0 ]; then
|
||||||
PASS
|
PASS
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue