eb77926602c2e971f2f71e54d796f3f40d962860
[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
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 activity="compare results"
116 diff -b -B $TEMPDIR/pspp.filtered - <<EOF
117 1.1 DATA LIST.  Reading 1 record from the command file.
118 +--------+------+-------+------+
119 |Variable|Record|Columns|Format|
120 #========#======#=======#======#
121 |X       |     1|  1-  1|F1.0  |
122 |Y       |     1|  2-  2|F1.0  |
123 +--------+------+-------+------+
124
125 Documents in the active file:
126
127    First line of a document
128    This is the second very long line of a document in an attempt to overflow 
129    Note that the last line should end with a period: .
130
131 File label:
132 This is a test file label
133
134 Documents in the active file:
135
136    First line of a document
137    This is the second very long line of a document in an attempt to overflow 
138    Note that the last line should end with a period: .
139
140 File label:
141 This is a test file label
142
143 Documents in the active file:
144
145    First line of a document
146    This is the second very long line of a document in an attempt to overflow 
147    Note that the last line should end with a period: .
148  
149    There should be another document now.
150
151 Documents in the active file:
152
153    First line of a document
154    This is the second very long line of a document in an attempt to overflow 
155    Note that the last line should end with a period: .
156  
157    There should be another document now.
158
159 File label:
160 This is a test file label
161 EOF
162 if [ $? -ne 0 ] ; then fail ; fi
163
164
165 pass;