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