Implement GET DATA/TYPE=TXT.
[pspp-builds.git] / tests / command / get-data-txt.sh
1 #!/bin/sh
2
3 # This program tests features of GET DATA /TYPE=TXT input program that
4 # it has in common with DATA LIST, using tests drawn from
5 # data-list.sh.
6
7 TEMPDIR=/tmp/pspp-tst-$$
8 TESTFILE=$TEMPDIR/`basename $0`.sps
9
10 # ensure that top_builddir  are absolute
11 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
12 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
13 top_builddir=`cd $top_builddir; pwd`
14 PSPP=$top_builddir/src/ui/terminal/pspp
15
16 # ensure that top_srcdir is absolute
17 top_srcdir=`cd $top_srcdir; pwd`
18
19 STAT_CONFIG_PATH=$top_srcdir/config
20 export STAT_CONFIG_PATH
21
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 # Create command file.
58 activity="create program"
59 cat > $TESTFILE << EOF
60 get data /type=txt /file=inline /delimiters="|X"
61  /variables=A f7.2 B f7.2 C f7.2 D f7.2.
62 begin data.
63 1|23X45|2.03
64 2X22|34|23|
65 3|34|34X34
66 end data.
67
68 list.
69
70 get data /type=txt /file=inline /delimiters=', ' /delcase=variables 4
71  /firstcase=2 /variables=A f7.2 B f7.2 C f7.2 D f7.2.
72 begin data.
73 # This record is ignored.
74 ,1,2,3
75 ,4,,5
76 6
77 7,
78 8 9
79 0,1,,,
80 ,,,,
81 2
82
83 3
84 4
85 5
86 end data.
87 list.
88
89 get data /type=txt /file=inline /delimiters='\t' /delcase=variables 4
90  /firstcase=3 /variables=A f7.2 B f7.2 C f7.2 D f7.2.
91 begin data.
92 # These records
93 # are skipped.
94 1       2       3       4
95 1       2       3       
96 1       2               4
97 1       2               
98 1               3       4
99 1               3       
100 1                       4
101 1                       
102         2       3       4
103         2       3       
104         2               4
105         2               
106                 3       4
107                 3       
108                         4
109                         
110 end data.
111 list.
112
113 get data /type=txt /file=inline /arrangement=fixed /fixcase=3 /variables=
114         /1 start 0-19 adate
115         /2 end 0-19 adate
116         /3 count 0-2 f.
117 begin data.
118 07-22-2007
119 10-06-2007
120 321
121 07-14-1789
122 08-26-1789
123 4
124 01-01-1972
125 12-31-1999
126 682
127 end data.
128 list.
129
130 get data /type=txt /file=inline /arrangement=fixed /fixcase=2 /variables=
131         /1 x 0 f 
132            y 1 f.
133 begin data.
134 12
135
136 34
137
138 56
139
140 78
141
142 90
143
144 end data.
145 list.
146 EOF
147 if [ $? -ne 0 ] ; then no_result ; fi
148
149
150 activity="run program"
151 $SUPERVISOR $PSPP --testing-mode $TESTFILE
152 if [ $? -ne 0 ] ; then fail ; fi
153
154 activity="compare output"
155 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
156 diff -b  $TEMPDIR/pspp.list - << EOF
157        A        B        C        D
158 -------- -------- -------- --------
159     1.00    23.00    45.00     2.03
160     2.00    22.00    34.00    23.00
161     3.00    34.00    34.00    34.00
162        A        B        C        D
163 -------- -------- -------- --------
164      .       1.00     2.00     3.00
165      .       4.00      .       5.00
166     6.00     7.00      .       8.00
167     9.00      .00     1.00      .
168      .        .        .        .
169      .        .        .       2.00
170      .       3.00     4.00     5.00
171        A        B        C        D
172 -------- -------- -------- --------
173     1.00     2.00     3.00     4.00
174     1.00     2.00     3.00      .
175     1.00     2.00      .       4.00
176     1.00     2.00      .        .
177     1.00      .       3.00     4.00
178     1.00      .       3.00      .
179     1.00      .        .       4.00
180     1.00      .        .        .
181      .       2.00     3.00     4.00
182      .       2.00     3.00      .
183      .       2.00      .       4.00
184      .       2.00      .        .
185      .        .       3.00     4.00
186      .        .       3.00      .
187      .        .        .       4.00
188      .        .        .        .
189                start                  end count
190 -------------------- -------------------- -----
191           07/22/2007           10/06/2007   321
192           07/14/1789           08/26/1789     4
193           01/01/1972           12/31/1999   682
194 x y
195 - -
196 1 2
197 3 4
198 5 6
199 7 8
200 9 0
201 EOF
202 if [ $? -ne 0 ] ; then fail ; fi
203
204 pass;