56d569cb17dffc2478a5dafcba8ee51f419eb83c
[pspp-builds.git] / tests / bugs / overwrite-input-file.sh
1 #!/bin/sh
2
3 # This program tests for a bug that caused SAVE to the file currently
4 # being read with GET to truncate the save file to zero length, and
5 # similarly for IMPORT/EXPORT.
6
7
8 TEMPDIR=/tmp/pspp-tst-$$
9 TESTFILE=$TEMPDIR/`basename $0`.sps
10
11 # ensure that top_builddir  are absolute
12 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
13 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
14 top_builddir=`cd $top_builddir; pwd`
15 PSPP=$top_builddir/src/ui/terminal/pspp
16
17 # ensure that top_srcdir is absolute
18 top_srcdir=`cd $top_srcdir; pwd`
19
20 STAT_CONFIG_PATH=$top_srcdir/config
21 export STAT_CONFIG_PATH
22
23
24 cleanup()
25 {
26      cd /
27      rm -rf $TEMPDIR
28 }
29
30
31 fail()
32 {
33     echo $activity
34     echo FAILED
35     cleanup;
36     exit 1;
37 }
38
39
40 no_result()
41 {
42     echo $activity
43     echo NO RESULT;
44     cleanup;
45     exit 2;
46 }
47
48 pass()
49 {
50     cleanup;
51     exit 0;
52 }
53
54 mkdir -p $TEMPDIR
55
56 cd $TEMPDIR
57
58 activity="create program 1"
59 cat > $TESTFILE <<EOF
60 DATA LIST /X 1.
61 BEGIN DATA.
62 1
63 2
64 3
65 4
66 5
67 END DATA.
68
69 SAVE OUTFILE='foo.sav'.
70 EXPORT OUTFILE='foo.por'.
71 EOF
72 if [ $? -ne 0 ] ; then no_result ; fi
73
74
75 activity="run program 1"
76 $SUPERVISOR $PSPP --testing-mode $TESTFILE
77 if [ $? -ne 0 ] ; then no_result ; fi
78
79
80 activity="check and save copy of output files"
81 # Check that the files are nonzero length.
82 test -s foo.sav || fail
83 test -s foo.por || fail
84 # Save copies of them.
85 cp foo.sav foo.sav.backup || fail
86 cp foo.por foo.por.backup || fail
87
88
89 activity="create program 2"
90 cat > $TESTFILE <<EOF
91 GET 'foo.sav'.
92 SAVE OUTFILE='foo.sav'.
93 EOF
94 if [ $? -ne 0 ] ; then no_result ; fi
95
96
97 activity="run program 2"
98 $SUPERVISOR $PSPP --testing-mode $TESTFILE -e /dev/null
99 # This should have failed with an error message.
100 if [ $? -eq 0 ] ; then no_result ; fi
101
102
103 activity="create program 3"
104 cat > $TESTFILE <<EOF
105 IMPORT 'foo.por'.
106 EXPORT OUTFILE='foo.por'.
107 EOF
108 if [ $? -ne 0 ] ; then no_result ; fi
109
110
111 activity="run program 3"
112 $SUPERVISOR $PSPP --testing-mode $TESTFILE -e /dev/null
113 # This should have failed with an error message.
114 if [ $? -eq 0 ] ; then no_result ; fi
115
116
117 activity="compare output 1"
118 cmp foo.sav foo.sav.backup
119 if [ $? -ne 0 ] ; then fail ; fi
120
121 activity="compare output 2"
122 cmp foo.por foo.por.backup
123 if [ $? -ne 0 ] ; then fail ; fi
124
125 pass;