cbb29b42cf68a178ba443f80e4d91c5855fb71f7
[pspp] / tests / bugs / overwrite-input-file.sh
1 #!/bin/sh
2
3 # This program tests that simultaneous input and output to a single
4 # file properly coexist, with the output atomically replacing the
5 # input if successful.
6
7 TEMPDIR=/tmp/pspp-tst-$$
8 TESTFILE=$TEMPDIR/`basename $0`.sps
9
10 # ensure that top_builddir  are absolute
11 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
12 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
13 top_builddir=`cd $top_builddir; pwd`
14 PSPP=$top_builddir/src/ui/terminal/pspp$EXEEXT
15
16 # ensure that top_srcdir is absolute
17 top_srcdir=`cd $top_srcdir; pwd`
18
19 STAT_CONFIG_PATH=$top_srcdir/config
20 export STAT_CONFIG_PATH
21
22
23 cleanup()
24 {
25      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
26         echo "NOT cleaning $TEMPDIR" 
27         return ; 
28      fi
29      cd /
30      rm -rf $TEMPDIR
31 }
32
33
34 fail()
35 {
36     echo $activity
37     echo FAILED
38     cleanup;
39     exit 1;
40 }
41
42
43 no_result()
44 {
45     echo $activity
46     echo NO RESULT;
47     cleanup;
48     exit 2;
49 }
50
51 pass()
52 {
53     cleanup;
54     exit 0;
55 }
56
57 mkdir -p $TEMPDIR
58
59 cd $TEMPDIR
60
61 activity="create data file"
62 cat > foo.data <<EOF
63 1
64 2
65 3
66 4
67 5
68 EOF
69 if [ $? -ne 0 ] ; then no_result ; fi
70
71 activity="create program 1"
72 cat > $TESTFILE <<EOF
73 DATA LIST FILE='foo.data' /X 1.
74 SAVE OUTFILE='foo.sav'.
75 EXPORT OUTFILE='foo.por'.
76 EOF
77 if [ $? -ne 0 ] ; then no_result ; fi
78
79 activity="run program 1"
80 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE
81 if [ $? -ne 0 ] ; then no_result ; fi
82
83 activity="check and save copy of output files"
84 # Check that the files are nonzero length.
85 test -s foo.data || fail
86 test -s foo.sav || fail
87 test -s foo.por || fail
88 # Save copies of them.
89 cp foo.data foo.data.backup || fail
90 cp foo.sav foo.sav.backup || fail
91 cp foo.por foo.por.backup || fail
92
93
94 activity="create program 2"
95 cat > $TESTFILE <<EOF
96 GET 'foo.sav'.
97 COMPUTE Y = X + 1.
98 XSAVE OUTFILE='foo.sav'.
99 XEXPORT OUTFILE='foo.por'.
100 PRINT OUTFILE='foo.data'.
101 HOST kill -TERM \$PPID
102 EOF
103 if [ $? -ne 0 ] ; then no_result ; fi
104
105 activity="run program 2"
106 { $SUPERVISOR $PSPP -o pspp.csv $TESTFILE -e /dev/null; } >/dev/null 2>&1
107 # PSPP should have terminated with a signal.  POSIX requires that the exit
108 # status of a process terminated by a signal be greater than 128.
109 if [ $? -le 128 ] ; then no_result ; fi
110
111 activity="check for remaining temporary files"
112 if test -e *.tmp*; then fail; fi
113
114 activity="compare output 1"
115 cmp foo.sav foo.sav.backup
116 if [ $? -ne 0 ] ; then fail ; fi
117
118 activity="compare output 2"
119 cmp foo.por foo.por.backup
120 if [ $? -ne 0 ] ; then fail ; fi
121
122 activity="compare output 3"
123 cmp foo.data foo.data.backup
124 if [ $? -ne 0 ] ; then fail ; fi
125
126
127 activity="create program 3"
128 cat > $TESTFILE <<EOF
129 DATA LIST NOTABLE LIST FILE='foo.data'/X.
130 COMPUTE Y = X + 1.
131 PRINT OUTFILE='foo.data'/X Y.
132 EXECUTE.
133
134 GET 'foo.sav'.
135 COMPUTE Y = X + 2.
136 SAVE OUTFILE='foo.sav'.
137
138 IMPORT 'foo.por'.
139 COMPUTE Y = X + 3.
140 EXPORT OUTFILE='foo.por'.
141 EOF
142 if [ $? -ne 0 ] ; then no_result ; fi
143
144 activity="run program 3"
145 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE -e /dev/null
146 if [ $? -ne 0 ] ; then no_result ; fi
147
148 activity="check for remaining temporary files"
149 if test -e *.tmp*; then fail; fi
150
151 activity="create program 4"
152 cat > $TESTFILE <<EOF
153 DATA LIST LIST NOTABLE FILE='foo.data'/X Y.
154 LIST.
155
156 GET 'foo.sav'.
157 LIST.
158
159 IMPORT 'foo.por'.
160 LIST.
161 EOF
162 if [ $? -ne 0 ] ; then no_result ; fi
163
164 activity="run program 4"
165 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE -e /dev/null
166 if [ $? -ne 0 ] ; then no_result ; fi
167
168 activity="compare output"
169 diff -c pspp.csv - << EOF
170 Table: Data List
171 X,Y
172 1.00,2.00
173 2.00,3.00
174 3.00,4.00
175 4.00,5.00
176 5.00,6.00
177
178 Table: Data List
179 X,Y
180 1,3.00
181 2,4.00
182 3,5.00
183 4,6.00
184 5,7.00
185
186 Table: Data List
187 X,Y
188 1,4.00
189 2,5.00
190 3,6.00
191 4,7.00
192 5,8.00
193 EOF
194 if [ $? -ne 0 ] ; then fail ; fi
195
196
197 pass;