Checkin of new directory structure.
[pspp-builds.git] / tests / command / file-label.sh
1 #!/bin/sh
2
3 # This program tests the FILE LABEL and  DOCUMENT commands
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
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
13 # ensure that top_srcdir is absolute
14 top_srcdir=`cd $top_srcdir; pwd`
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19
20 cleanup()
21 {
22      cd /
23      rm -rf $TEMPDIR
24 }
25
26
27 fail()
28 {
29     echo $activity
30     echo FAILED
31     cleanup;
32     exit 1;
33 }
34
35
36 no_result()
37 {
38     echo $activity
39     echo NO RESULT;
40     cleanup;
41     exit 2;
42 }
43
44 pass()
45 {
46     cleanup;
47     exit 0;
48 }
49
50 mkdir -p $TEMPDIR
51
52 cd $TEMPDIR
53
54 activity="create program"
55 cat > $TESTFILE << EOF
56
57 /* Set up a dummy active file in memory.
58 data list /X 1 Y 2.
59 begin data.
60 16
61 27
62 38
63 49
64 50
65 end data.
66
67 /* Add value labels for some further testing of value labels.
68 value labels x y 1 'first label' 2 'second label' 3 'third label'.
69 add value labels x 1 'first label mark two'.
70
71 /* Add a file label and a few documents.
72 file label This is a test file label.
73 document First line of a document
74 This is the second very long line of a document in an attempt to overflow the input buffer with a really long line
75 Note that the last line should end with a period: .
76
77 /* Display the documents.
78 display documents.
79 display file label.     /* undocumented feature of PSPP
80
81 /* Save the active file then get it and display the documents again.
82 save /OUTFILE='foo.save'.
83 get /FILE='foo.save'.
84 display documents.
85 display file label.     /* undocumented feature of PSPP
86
87 /* There is an interesting interaction that occurs if the 'execute'
88 /* command below.  What happens is that an error message is output
89 /* at the next 'save' command that 'foo.save' is already open for
90 /* input.  This is because the 'get' hasn't been executed yet and
91 /* therefore PSPP would be reading from and writing to the same
92 /* file at once, which is obviously a Bad Thing.  But 'execute'
93 /* here clears up that potential problem.
94 execute.
95
96 /* Add another (shorter) document and try again.
97 document There should be another document now.
98 display documents.
99
100 /* Save and get.
101 save /OUTFILE='foo.save'.
102 get /FILE='foo.save'.
103 display documents.
104 display file label.     /* undocumented feature of PSPP
105
106 /* Done.
107
108 EOF
109 if [ $? -ne 0 ] ; then no_result ; fi
110
111 activity="run program"
112 $SUPERVISOR $top_builddir/src/pspp --testing-mode -o raw-ascii $TESTFILE
113 if [ $? -ne 0 ] ; then no_result ; fi
114
115 # We need to filter out the dates/times
116 activity="date filter"
117 grep -v 'Document entered' $TEMPDIR/pspp.list > $TEMPDIR/pspp.filtered
118 if [ $? -ne 0 ] ; then no_result ; fi
119
120
121 activity="compare results"
122 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.filtered
123 diff -b  $TEMPDIR/pspp.filtered - <<EOF
124 1.1 DATA LIST.  Reading 1 record from INLINE.
125 +--------+------+-------+------+
126 |Variable|Record|Columns|Format|
127 #========#======#=======#======#
128 |X       |     1|  1-  1|F1.0  |
129 |Y       |     1|  2-  2|F1.0  |
130 +--------+------+-------+------+
131 Documents in the active file:
132    First line of a document
133    This is the second very long line of a document in an attempt to overflow the
134    Note that the last line should end with a period: .
135 File label:
136 This is a test file label
137 Documents in the active file:
138    First line of a document
139    This is the second very long line of a document in an attempt to overflow the
140    Note that the last line should end with a period: .
141 File label:
142 This is a test file label
143 Documents in the active file:
144    First line of a document
145    This is the second very long line of a document in an attempt to overflow the
146    Note that the last line should end with a period: .
147    There should be another document now.
148 Documents in the active file:
149    First line of a document
150    This is the second very long line of a document in an attempt to overflow the
151    Note that the last line should end with a period: .
152    There should be another document now.
153 File label:
154 This is a test file label
155 EOF
156 if [ $? -ne 0 ] ; then fail ; fi
157
158
159 pass;