Allow output files to overwrite input files (bug #21280). Thanks to
[pspp-builds.git] / tests / bugs / overwrite-special-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
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      cd /
26      rm -rf $TEMPDIR
27 }
28
29
30 fail()
31 {
32     echo $activity
33     echo FAILED
34     cleanup;
35     exit 1;
36 }
37
38
39 no_result()
40 {
41     echo $activity
42     echo NO RESULT;
43     cleanup;
44     exit 2;
45 }
46
47 pass()
48 {
49     cleanup;
50     exit 0;
51 }
52
53 mkdir -p $TEMPDIR
54
55 cd $TEMPDIR
56
57 # This test only works on systems that have a /dev/null device...
58 test -c /dev/null || no_result
59
60 # ...and that are able to make a symbolic link to it...
61 ln -s /dev/null foo.out || no_result
62
63 # ...that is still /dev/null.
64 test -c /dev/null || no_result
65
66 activity="create program 1"
67 cat > $TESTFILE <<EOF
68 DATA LIST /x 1.
69 BEGIN DATA.
70 1
71 2
72 3
73 4
74 5
75 END DATA.
76 PRINT OUTFILE='foo.out'/x.
77 PRINT OUTFILE='foo2.out'/x.
78 EXECUTE.
79 EOF
80 if [ $? -ne 0 ] ; then no_result ; fi
81
82 activity="run program 1"
83 $SUPERVISOR $PSPP --testing-mode $TESTFILE
84 if [ $? -ne 0 ] ; then no_result ; fi
85
86 activity="check that foo2.out was created"
87 diff -b -B foo2.out - << EOF
88  1
89  2
90  3
91  4
92  5
93 EOF
94 if [ $? -ne 0 ] ; then fail ; fi
95
96 activity="check that foo.out is unchanged"
97 test -c /dev/null || fail
98
99 pass;