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