a4783bbcb5ee2bcbedc44194532b41aadd078653
[pspp-builds.git] / tests / command / print.sh
1 #!/bin/sh
2
3 # This program tests the PRINT transformation
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 STAT_CONFIG_PATH=$top_srcdir/config
14 export STAT_CONFIG_PATH
15
16
17 cleanup()
18 {
19      cd /
20      rm -rf $TEMPDIR
21 }
22
23
24 fail()
25 {
26     echo $activity
27     echo FAILED
28     cleanup;
29     exit 1;
30 }
31
32
33 no_result()
34 {
35     echo $activity
36     echo NO RESULT;
37     cleanup;
38     exit 2;
39 }
40
41 pass()
42 {
43     cleanup;
44     exit 0;
45 }
46
47 mkdir -p $TEMPDIR
48
49 cd $TEMPDIR
50
51 # Copy this file --- it's shared with another test
52 activity="create data"
53 cp $top_srcdir/tests/data-list.data $TEMPDIR
54 if [ $? -ne 0 ] ; then no_result ; fi
55
56
57 activity="create program"
58 cat > $TEMPDIR/print.stat << foobar
59 title 'Test PRINT transformation'.
60
61 data list free table file='$TEMPDIR/data-list.data'/A B C D.
62 print outfile="foo" table/A(f8.2) '/' B(e8.2) '/' C(n10) '/'.
63 print space a.
64 print outfile="foo" /a b c d.
65 list.
66
67 data list list table file='$TEMPDIR/data-list.data'/A B C D.
68 print table/A B C D.
69 list.
70
71 foobar
72 if [ $? -ne 0 ] ; then no_result ; fi
73
74
75 activity="run program"
76 $SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii --testing-mode $TEMPDIR/print.stat > $TEMPDIR/errs
77 # Note   vv   --- there are errors in input.  Therefore, the  command must FAIL
78 if [ $? -eq 0 ] ; then fail ; fi
79
80 activity="compare error messages"
81 diff -w $TEMPDIR/errs - <<EOF
82 $TEMPDIR/data-list.data:1: error: (columns 1-5, field type F8.0) Field does not form a valid floating-point constant.
83 $TEMPDIR/data-list.data:1: warning: LIST: The expression on PRINT SPACE evaluated to the system-missing value.
84 $TEMPDIR/data-list.data:2: error: (columns 1-8, field type F8.0) Field does not form a valid floating-point constant.
85 $TEMPDIR/data-list.data:4: warning: LIST: The expression on PRINT SPACE evaluated to the system-missing value.
86 $TEMPDIR/data-list.data:4: error: (columns 3-12, field type F8.0) Field does not form a valid floating-point constant.
87 $TEMPDIR/data-list.data:6: warning: LIST: The expression on PRINT SPACE evaluated to the system-missing value.
88 $TEMPDIR/data-list.data:1: error: (columns 1-5, field type F8.0) Field does not form a valid floating-point constant.
89 $TEMPDIR/data-list.data:2: error: (columns 1-8, field type F8.0) Field does not form a valid floating-point constant.
90 $TEMPDIR/data-list.data:2: warning: LIST: Missing value(s) for all variables from C onward.  These will be filled with the system-missing value or blanks, as appropriate.
91 $TEMPDIR/data-list.data:3: warning: LIST: Missing value(s) for all variables from B onward.  These will be filled with the system-missing value or blanks, as appropriate.
92 $TEMPDIR/data-list.data:4: error: (columns 3-12, field type F8.0) Field does not form a valid floating-point constant.
93 $TEMPDIR/data-list.data:4: warning: LIST: Missing value(s) for all variables from C onward.  These will be filled with the system-missing value or blanks, as appropriate.
94 $TEMPDIR/data-list.data:5: warning: LIST: Missing value(s) for all variables from C onward.  These will be filled with the system-missing value or blanks, as appropriate.
95 $TEMPDIR/data-list.data:6: warning: LIST: Missing value(s) for all variables from B onward.  These will be filled with the system-missing value or blanks, as appropriate.
96 EOF
97 if [ $? -ne 0 ] ; then fail ; fi
98
99
100 activity="compare output"
101 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
102 diff -b  $TEMPDIR/pspp.list - << EOF
103 1.1 DATA LIST.  Reading free-form data from "$TEMPDIR/data-list.data".
104 +--------+------+
105 |Variable|Format|
106 #========#======#
107 |A       |F8.0  |
108 |B       |F8.0  |
109 |C       |F8.0  |
110 |D       |F8.0  |
111 +--------+------+
112 2.1 PRINT.  Writing 1 record to "foo".
113 +--------+------+-------+------+
114 |Variable|Record|Columns|Format|
115 #========#======#=======#======#
116 |A       |     1|  1-  8|F8.2  |
117 |"/"     |     1|  9-  9|A1    |
118 |B       |     1| 10- 17|E8.2  |
119 |"/"     |     1| 18- 18|A1    |
120 |C       |     1| 19- 28|N10.0 |
121 |"/"     |     1| 29- 29|A1    |
122 +--------+------+-------+------+
123        A        B        C        D
124 -------- -------- -------- --------
125      .       2.00     3.00     4.00 
126      .       6.00     7.00     8.00 
127      .      10.00    11.00    12.00 
128 3.1 DATA LIST.  Reading free-form data from "$TEMPDIR/data-list.data".
129 +--------+------+
130 |Variable|Format|
131 #========#======#
132 |A       |F8.0  |
133 |B       |F8.0  |
134 |C       |F8.0  |
135 |D       |F8.0  |
136 +--------+------+
137 4.1 PRINT.  Writing 1 record.
138 +--------+------+-------+------+
139 |Variable|Record|Columns|Format|
140 #========#======#=======#======#
141 |A       |     1|  1-  8|F8.2  |
142 |B       |     1| 10- 17|F8.2  |
143 |C       |     1| 19- 26|F8.2  |
144 |D       |     1| 28- 35|F8.2  |
145 +--------+------+-------+------+
146      .       2.00     3.00     4.00 
147        A        B        C        D
148 -------- -------- -------- --------
149      .       2.00     3.00     4.00 
150      .       6.00      .        .   
151      .       6.00      .        .   
152     7.00      .        .        .   
153     7.00      .        .        .   
154     8.00      .        .        .   
155     8.00      .        .        .   
156    10.00    11.00      .        .   
157    10.00    11.00      .        .   
158    12.00      .        .        .   
159    12.00      .        .        .   
160 EOF
161 if [ $? -ne 0 ] ; then fail ; fi
162
163
164 activity="compare print out"
165 diff $TEMPDIR/foo - << EOF
166      .  /2.00E+00/0000000003/
167      .       2.00     3.00     4.00 
168      .  /6.00E+00/0000000007/
169      .       6.00     7.00     8.00 
170      .  /1.00E+01/0000000011/
171      .      10.00    11.00    12.00 
172 EOF
173 if [ $? -ne 0 ] ; then fail ; fi
174
175 pass;