Implemented long variable names a la spss V12.
[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 > $TESTFILE << EOF
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 /OUTFILE='foo.save'.
78 get /FILE='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 /OUTFILE='foo.save'.
97 get /FILE='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 $SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii $TESTFILE
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;