Fix server startup so it works with postgres 8.2
[pspp-builds.git] / tests / command / get-data-psql.sh
1 #!/bin/sh
2
3 # This program tests the psql import feature.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_srcdir and top_builddir  are absolute
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 top_srcdir=`cd $top_srcdir; pwd`
12 top_builddir=`cd $top_builddir; pwd`
13
14 PSPP=$top_builddir/src/ui/terminal/pspp
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19 LANG=C
20 export LANG
21
22 port=6543
23 dbase=pspptest
24 PG_CONFIG=pg_config
25 pgpath=`$PG_CONFIG | awk '/BINDIR/{print $3}'`
26
27 cleanup()
28 {
29     if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
30         echo "NOT cleaning $TEMPDIR"
31         return ; 
32     fi
33     PGHOST=$TEMPDIR $pgpath/pg_ctl -D $TEMPDIR/cluster  stop -w -o "-k $TEMPDIR -h ''"   > /dev/null 2>&1
34     rm -rf $TEMPDIR
35 }
36
37
38 fail()
39 {
40     echo $activity
41     echo FAILED
42     cleanup;
43     exit 1;
44 }
45
46
47 no_result()
48 {
49     echo $activity
50     echo NO RESULT;
51     cleanup;
52     exit 2;
53 }
54
55 pass()
56 {
57     cleanup;
58     exit 0;
59 }
60
61 if [ ! -x $pgpath/initdb ] ; then
62   echo 'No Postgres server was found, so the postgres database interface cannot be tested.'  
63   cleanup;
64   exit 77;
65 fi
66
67 mkdir -p $TEMPDIR
68
69 cd $TEMPDIR
70
71 activity="create cluster"
72 $pgpath/initdb  -D $TEMPDIR/cluster -A trust > /dev/null
73 if [ $? -ne 0 ] ; then no_result ; fi
74
75
76 activity="run server"
77 PGHOST=$TEMPDIR PGPORT=$port $pgpath/pg_ctl -D $TEMPDIR/cluster  start -w -o "-k $TEMPDIR" > /dev/null
78 if [ $? -ne 0 ] ; then no_result ; fi
79
80
81 activity="create database"
82 createdb  -h $TEMPDIR  -p $port $dbase > /dev/null 2> /dev/null
83
84
85 activity="populate database"
86 psql  -h $TEMPDIR -p $port  $dbase > /dev/null << EOF
87 CREATE TABLE thing (
88  bool    bool                      ,
89  bytea   bytea                     ,
90  char    char                      ,
91  int8    int8                      ,
92  int2    int2                      ,
93  int4    int4                      ,
94  numeric       numeric(50,6)       ,
95  text    text                      ,
96  oid     oid                       ,
97  float4  float4                    ,
98  float8  float8                    ,
99  money   money                     ,
100  pbchar  bpchar                    ,
101  varchar varchar                   ,
102  date    date                      ,
103  time    time                      ,
104  timestamp     timestamp           ,
105  timestamptz   timestamptz         ,
106  interval      interval            ,
107  timetz        timetz              
108 );
109
110 INSERT INTO thing VALUES (
111  false,
112  '0',
113  'a',
114  '0',
115  0,
116  0,
117  -256.098,
118  'this-long-text',
119  0,
120  0,
121  0,
122  '0.01',
123  'a',
124  'A',
125  '1-Jan-2000',
126  '00:00',
127  'January 8 04:05:06 1999',
128  'January 8 04:05:06 1999 PST',
129  '1 minutes',
130  '10:09 UTC+4'
131 );
132
133 INSERT INTO thing VALUES (
134  null,
135  null,
136  null,
137  null,
138  null,
139  null,
140  null,
141  null,
142  null,
143  null,
144  null,
145  null,
146  null,
147  null,
148  null,
149  null,
150  null,
151  null,
152  null,
153  null
154 );
155
156 INSERT INTO thing VALUES (
157  true,
158  '1',
159  'b',
160  '1',
161  1,
162  1,
163  65535.00001,
164  'that-long-text',
165  1,
166  1,
167  1,
168  '1.23',
169  'b',
170  'B',
171  '10-Jan-1963',
172  '01:05:02',
173  '10-Jan-1963 23:58:00',
174  '10-Jan-1963 23:58:00 CET',
175  '2 year 1 month 12 days 1 hours 3 minutes 4 seconds',
176  '01:05:02 UTC-7'
177 );
178 EOF
179 if [ $? -ne 0 ] ; then fail ; fi
180
181 activity="create program"
182 cat > $TESTFILE <<EOF
183 GET DATA /TYPE=psql 
184         /CONNECT="host=$TEMPDIR port=$port dbname=$dbase"
185         /UNENCRYPTED
186         /SQL="select * from thing".
187
188 DISPLAY DICTIONARY.
189
190 LIST.
191 EOF
192 if [ $? -ne 0 ] ; then no_result ; fi
193
194
195 activity="run program"
196 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
197 if [ $? -ne 0 ] ; then no_result ; fi
198
199 activity="compare output"
200 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
201 diff -b  $TEMPDIR/pspp.list - << 'EOF'
202 1.1 DISPLAY.  
203 +---------------+-------------------------------------------+--------+
204 |Variable       |Description                                |Position|
205 #===============#===========================================#========#
206 |bool           |Format: F8.2                               |       1|
207 |               |Measure: Scale                             |        |
208 |               |Display Alignment: Right                   |        |
209 |               |Display Width: 8                           |        |
210 +---------------+-------------------------------------------+--------+
211 |bytea          |Format: AHEX2                              |       2|
212 |               |Measure: Nominal                           |        |
213 |               |Display Alignment: Left                    |        |
214 |               |Display Width: 1                           |        |
215 +---------------+-------------------------------------------+--------+
216 |char           |Format: A8                                 |       3|
217 |               |Measure: Nominal                           |        |
218 |               |Display Alignment: Left                    |        |
219 |               |Display Width: 8                           |        |
220 +---------------+-------------------------------------------+--------+
221 |int8           |Format: F8.2                               |       4|
222 |               |Measure: Scale                             |        |
223 |               |Display Alignment: Right                   |        |
224 |               |Display Width: 8                           |        |
225 +---------------+-------------------------------------------+--------+
226 |int2           |Format: F8.2                               |       5|
227 |               |Measure: Scale                             |        |
228 |               |Display Alignment: Right                   |        |
229 |               |Display Width: 8                           |        |
230 +---------------+-------------------------------------------+--------+
231 |int4           |Format: F8.2                               |       6|
232 |               |Measure: Scale                             |        |
233 |               |Display Alignment: Right                   |        |
234 |               |Display Width: 8                           |        |
235 +---------------+-------------------------------------------+--------+
236 |numeric        |Format: E40.6                              |       7|
237 |               |Measure: Scale                             |        |
238 |               |Display Alignment: Right                   |        |
239 |               |Display Width: 8                           |        |
240 +---------------+-------------------------------------------+--------+
241 |text           |Format: A16                                |       8|
242 |               |Measure: Nominal                           |        |
243 |               |Display Alignment: Left                    |        |
244 |               |Display Width: 16                          |        |
245 +---------------+-------------------------------------------+--------+
246 |oid            |Format: F8.2                               |       9|
247 |               |Measure: Scale                             |        |
248 |               |Display Alignment: Right                   |        |
249 |               |Display Width: 8                           |        |
250 +---------------+-------------------------------------------+--------+
251 |float4         |Format: F8.2                               |      10|
252 |               |Measure: Scale                             |        |
253 |               |Display Alignment: Right                   |        |
254 |               |Display Width: 8                           |        |
255 +---------------+-------------------------------------------+--------+
256 |float8         |Format: F8.2                               |      11|
257 |               |Measure: Scale                             |        |
258 |               |Display Alignment: Right                   |        |
259 |               |Display Width: 8                           |        |
260 +---------------+-------------------------------------------+--------+
261 |money          |Format: DOLLAR8.2                          |      12|
262 |               |Measure: Scale                             |        |
263 |               |Display Alignment: Right                   |        |
264 |               |Display Width: 8                           |        |
265 +---------------+-------------------------------------------+--------+
266 |pbchar         |Format: A8                                 |      13|
267 |               |Measure: Nominal                           |        |
268 |               |Display Alignment: Left                    |        |
269 |               |Display Width: 8                           |        |
270 +---------------+-------------------------------------------+--------+
271 |varchar        |Format: A8                                 |      14|
272 |               |Measure: Nominal                           |        |
273 |               |Display Alignment: Left                    |        |
274 |               |Display Width: 8                           |        |
275 +---------------+-------------------------------------------+--------+
276 |date           |Format: DATE11                             |      15|
277 |               |Measure: Scale                             |        |
278 |               |Display Alignment: Right                   |        |
279 |               |Display Width: 8                           |        |
280 +---------------+-------------------------------------------+--------+
281 |time           |Format: TIME11.0                           |      16|
282 |               |Measure: Scale                             |        |
283 |               |Display Alignment: Right                   |        |
284 |               |Display Width: 8                           |        |
285 +---------------+-------------------------------------------+--------+
286 |timestamp      |Format: DATETIME22.0                       |      17|
287 |               |Measure: Scale                             |        |
288 |               |Display Alignment: Right                   |        |
289 |               |Display Width: 8                           |        |
290 +---------------+-------------------------------------------+--------+
291 |timestamptz    |Format: DATETIME22.0                       |      18|
292 |               |Measure: Scale                             |        |
293 |               |Display Alignment: Right                   |        |
294 |               |Display Width: 8                           |        |
295 +---------------+-------------------------------------------+--------+
296 |interval       |Format: DTIME13.0                          |      19|
297 |               |Measure: Scale                             |        |
298 |               |Display Alignment: Right                   |        |
299 |               |Display Width: 8                           |        |
300 +---------------+-------------------------------------------+--------+
301 |interval_months|Format: F3.0                               |      20|
302 |               |Measure: Scale                             |        |
303 |               |Display Alignment: Right                   |        |
304 |               |Display Width: 8                           |        |
305 +---------------+-------------------------------------------+--------+
306 |timetz         |Format: TIME11.0                           |      21|
307 |               |Measure: Scale                             |        |
308 |               |Display Alignment: Right                   |        |
309 |               |Display Width: 8                           |        |
310 +---------------+-------------------------------------------+--------+
311 |timetz_zone    |Format: F8.2                               |      22|
312 |               |Measure: Scale                             |        |
313 |               |Display Alignment: Right                   |        |
314 |               |Display Width: 8                           |        |
315 +---------------+-------------------------------------------+--------+
316     bool bytea     char     int8     int2     int4                                  numeric             text      oid   float4   float8    money   pbchar  varchar        date        time              timestamp            timestamptz      interval interval_months      timetz timetz_zone
317 -------- ----- -------- -------- -------- -------- ---------------------------------------- ---------------- -------- -------- -------- -------- -------- -------- ----------- ----------- ---------------------- ---------------------- ------------- --------------- ----------- -----------
318      .00    30 a             .00      .00      .00                           -2.560980E+002 this-long-text        .00      .00      .00     $.01 a        A        01-JAN-2000     0:00:00   08-JAN-1999 04:05:06   08-JAN-1999 12:05:06    0 00:01:00               0    10:09:00        4.00 
319      .      20               .        .        .                                .                                 .        .        .        .                               .           .                      .                      .             .               .           .         .   
320     1.00    31 b            1.00     1.00     1.00                            6.553500E+004 that-long-text        .00     1.00     1.00    $1.23 b        B        10-JAN-1963     1:05:02   10-JAN-1963 23:58:00   10-JAN-1963 22:58:00   12 01:03:04              25     1:05:02       -7.00 
321 EOF
322 if [ $? -ne 0 ] ; then fail ; fi
323
324 pass;