Rewrite PSPP output engine.
[pspp-builds.git] / tests / command / file-label.sh
1 #!/bin/sh
2
3 # This program tests the FILE LABEL and  DOCUMENT, and ADD 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 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 LANG=C
21 export LANG
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 activity="create program"
62 cat > $TESTFILE << EOF
63
64 /* Set up a dummy active file in memory.
65 data list /X 1 Y 2.
66 begin data.
67 16
68 27
69 38
70 49
71 50
72 end data.
73
74 /* Add value labels for some further testing of value labels.
75 value labels x y 1 'first label' 2 'second label' 3 'third label'.
76 add value labels x 1 'first label mark two'.
77
78 /* Add a file label and a few documents.
79 file label This is a test file label.
80 document First line of a document
81 Second line of a document
82 The last line should end with a period: .
83
84
85 /* Display the documents.
86 display documents.
87 display file label.
88
89 ADD DOCUMENT 'Line one' 'Line two'.
90
91 /* Save the active file then get it and display the documents again.
92 save /OUTFILE='foo.save'.
93 get /FILE='foo.save'.
94 display documents.
95 display file label.
96
97 /* There is an interesting interaction that occurs if the 'execute'
98 /* command below.  What happens is that an error message is output
99 /* at the next 'save' command that 'foo.save' is already open for
100 /* input.  This is because the 'get' hasn't been executed yet and
101 /* therefore PSPP would be reading from and writing to the same
102 /* file at once, which is obviously a Bad Thing.  But 'execute'
103 /* here clears up that potential problem.
104 execute.
105
106 /* Add another (shorter) document and try again.
107 document There should be another document now.
108 display documents.
109
110 /* Save and get.
111 save /OUTFILE='foo.save'.
112 get /FILE='foo.save'.
113 display documents.
114 display file label.
115
116 /* Done.
117
118 EOF
119 if [ $? -ne 0 ] ; then no_result ; fi
120
121 activity="run program"
122 $SUPERVISOR $PSPP --testing-mode $TESTFILE
123 if [ $? -ne 0 ] ; then no_result ; fi
124
125 # We need to filter out the dates/times
126 activity="date filter"
127 sed 's/(Entered [^)]*)/(Entered <date>)/' $TEMPDIR/pspp.csv > $TEMPDIR/pspp.filtered
128 if [ $? -ne 0 ] ; then no_result ; fi
129
130
131 activity="compare results"
132 diff -c $TEMPDIR/pspp.filtered - <<EOF
133 Table: Reading 1 record from INLINE.
134 Variable,Record,Columns,Format
135 X,1,1-  1,F1.0
136 Y,1,2-  2,F1.0
137
138 Documents in the active file:
139
140 document First line of a document
141
142 Second line of a document
143
144 The last line should end with a period: .
145
146 (Entered <date>)
147
148 File label:
149
150 This is a test file label
151
152 Documents in the active file:
153
154 document First line of a document
155
156 Second line of a document
157
158 The last line should end with a period: .
159
160 (Entered <date>)
161
162 Line one
163
164 Line two
165
166 (Entered <date>)
167
168 File label:
169
170 This is a test file label
171
172 Documents in the active file:
173
174 document First line of a document
175
176 Second line of a document
177
178 The last line should end with a period: .
179
180 (Entered <date>)
181
182 Line one
183
184 Line two
185
186 (Entered <date>)
187
188 document There should be another document now.
189
190 (Entered <date>)
191
192 Documents in the active file:
193
194 document First line of a document
195
196 Second line of a document
197
198 The last line should end with a period: .
199
200 (Entered <date>)
201
202 Line one
203
204 Line two
205
206 (Entered <date>)
207
208 document There should be another document now.
209
210 (Entered <date>)
211
212 File label:
213
214 This is a test file label
215 EOF
216 if [ $? -ne 0 ] ; then fail ; fi
217
218
219 pass;