Allow output files to overwrite input files (bug #21280). Thanks to
[pspp-builds.git] / tests / command / erase.sh
1 #!/bin/sh
2
3 # This program tests the ERASE command.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_builddir  are absolute
9 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
10 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
11 top_builddir=`cd $top_builddir; pwd`
12 PSPP=$top_builddir/src/ui/terminal/pspp
13
14 # ensure that top_srcdir is absolute
15 top_srcdir=`cd $top_srcdir; pwd`
16
17 STAT_CONFIG_PATH=$top_srcdir/config
18 export STAT_CONFIG_PATH
19
20
21 cleanup()
22 {
23      cd /
24      rm -rf $TEMPDIR
25 }
26
27
28 fail()
29 {
30     echo $activity
31     echo FAILED
32     cleanup;
33     exit 1;
34 }
35
36
37 no_result()
38 {
39     echo $activity
40     echo NO RESULT;
41     cleanup;
42     exit 2;
43 }
44
45 pass()
46 {
47     cleanup;
48     exit 0;
49 }
50
51 mkdir -p $TEMPDIR
52
53 cd $TEMPDIR
54
55 activity="create file"
56 cat > $TEMPDIR/foobar <<EOF
57 xyzzy
58 EOF
59 if [ $? -ne 0 ] ; then no_result ; fi
60
61 activity="check for file 1"
62 if [ ! -f $TEMPDIR/foobar ] ; then no_result ; fi 
63
64
65 activity="create program 1"
66 cat > $TESTFILE <<EOF
67 set safer on
68
69 erase FILE='foobar'.
70
71 EOF
72 if [ $? -ne 0 ] ; then no_result ; fi
73
74 # foobar must still exist
75 activity="check for file 2"
76 if [ ! -f $TEMPDIR/foobar ] ; then fail ; fi 
77
78 # This command must fail
79 activity="run prog 1"
80 $SUPERVISOR $PSPP --testing-mode -e /dev/null $TESTFILE 
81 if [ $? -eq 0 ] ; then fail ; fi
82
83
84 activity="create program 2"
85 cat > $TESTFILE <<EOF
86
87 erase FILE='foobar'.
88
89 EOF
90 if [ $? -ne 0 ] ; then no_result ; fi
91
92
93 activity="run prog 2"
94 $SUPERVISOR $PSPP --testing-mode $TESTFILE
95 if [ $? -ne 0 ] ; then fail ; fi
96
97 # foobar should now be gone
98 if [ -f $TEMPDIR/foobar ] ; then fail ; fi 
99
100
101 pass;