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