dad9157b2547375321a1592249afdefd9f1c81e8
[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$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 # This test only works on systems that have a /dev/null device...
62 test -c /dev/null || no_result
63
64 # ...and that are able to make a symbolic link to it...
65 ln -s /dev/null foo.out || no_result
66
67 # ...that is still /dev/null.
68 test -c /dev/null || no_result
69
70 activity="create program 1"
71 cat > $TESTFILE <<EOF
72 DATA LIST /x 1.
73 BEGIN DATA.
74 1
75 2
76 3
77 4
78 5
79 END DATA.
80 PRINT OUTFILE='foo.out'/x.
81 PRINT OUTFILE='foo2.out'/x.
82 EXECUTE.
83 EOF
84 if [ $? -ne 0 ] ; then no_result ; fi
85
86 activity="run program 1"
87 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE
88 if [ $? -ne 0 ] ; then no_result ; fi
89
90 activity="check that foo2.out was created"
91 diff -b foo2.out - << EOF
92  1
93  2
94  3
95  4
96  5
97 EOF
98 if [ $? -ne 0 ] ; then fail ; fi
99
100 activity="check that foo.out is unchanged"
101 test -c /dev/null || fail
102
103 pass;