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