New test for bug #21117.
[pspp-builds.git] / tests / bugs / unwritable-dir.sh
1 #!/bin/sh
2
3 # This program tests for a bug which crashed pspp when output drivers
4 # tried to create output files in an unwritable directory.
5
6 TEMPDIR=/tmp/pspp-tst-$$
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      chmod u+w $TEMPDIR
25      rm -rf $TEMPDIR
26 }
27
28
29 fail()
30 {
31     echo $activity
32     echo FAILED
33     cleanup;
34     exit 1;
35 }
36
37
38 no_result()
39 {
40     echo $activity
41     echo NO RESULT;
42     cleanup;
43     exit 2;
44 }
45
46 pass()
47 {
48     cleanup;
49     exit 0;
50 }
51
52 mkdir -p $TEMPDIR
53
54 cd $TEMPDIR
55
56 activity="create test syntax"
57 cat > test.pspp <<EOF
58 * By including at least one command in the input, we can ensure that PSPP
59   also doesn't crash trying to create pspp.jnl in an unwritable directory.
60
61 * By outputting a chart, we can check that charts are safe too.
62
63 data list /x 1.
64 begin data.
65 1
66 2
67 3
68 end data.
69 frequencies x/histogram.
70 EOF
71 if [ $? -ne 0 ] ; then no_result ; fi
72
73 # Mark our directory unwritable.
74 chmod u-w $TEMPDIR
75
76 # Iterate over the various drivers we support.  We could use all of these
77 # on a single PSPP invocation, except that charts are only supported for
78 # a single driver at a time, and we'd prefer to test chart support for
79 # all of our driver types.
80 for driver in list-ascii list-ps html; do
81     # PSPP will fail to create the output file.  Currently this doesn't cause
82     # PSPP's exit status to be nonzero, although this is arguably incorrect.
83     # At any rate, PSPP should not crash.
84     activity="run pspp with $driver driver"
85     $SUPERVISOR $PSPP -o $driver test.pspp >/dev/null 2>&1
86     if [ $? -ne 0 ] ; then fail ; fi
87 done
88
89 pass;