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