56cbd3b380c7f130cee1f619bb04bab31f94621d
[pspp-builds.git] / tests / command / get-data-txt-examples.sh
1 #!/bin/sh
2
3 # This program tests the examples for GET DATA/TYPE=TXT given in the
4 # PSPP manual.
5
6 TEMPDIR=/tmp/pspp-tst-$$
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 passwd.data"
58 cat > passwd.data <<'EOF'
59 root:$1$nyeSP5gD$pDq/:0:0:,,,:/root:/bin/bash
60 blp:$1$BrP/pFg4$g7OG:1000:1000:Ben Pfaff,,,:/home/blp:/bin/bash
61 john:$1$JBuq/Fioq$g4A:1001:1001:John Darrington,,,:/home/john:/bin/bash
62 jhs:$1$D3li4hPL$88X1:1002:1002:Jason Stover,,,:/home/jhs:/bin/csh
63 EOF
64 if [ $? -ne 0 ] ; then no_result ; fi
65
66 activity="create cars.data"
67 cat > cars.data <<'EOF'
68 model   year    mileage price   type    age
69 Civic   2002    29883   15900   Si      2
70 Civic   2003    13415   15900   EX      1
71 Civic   1992    107000  3800    n/a     12
72 Accord  2002    26613   17900   EX      1
73 EOF
74 if [ $? -ne 0 ] ; then no_result ; fi
75
76 activity="create pets.data"
77 cat > pets.data <<'EOF'
78 "Pet Name", "Age", "Color", "Date Received", "Price", "Needs Walking", "Type"
79 , (Years), , , (Dollars), ,
80 "Rover", 4.5, Brown, "12 Feb 2004", 80, True, "Dog"
81 "Charlie", , Gold, "5 Apr 2007", 12.3, False, "Fish"
82 "Molly", 2, Black, "12 Dec 2006", 25, False, "Cat"
83 "Gilly", , White, "10 Apr 2007", 10, False, "Guinea Pig"
84 EOF
85 if [ $? -ne 0 ] ; then no_result ; fi
86
87 activity="create test.pspp"
88 cat > test.pspp <<'EOF'
89 GET DATA /TYPE=TXT /FILE='passwd.data' /DELIMITERS=':'
90         /VARIABLES=username A20
91                    password A40
92                    uid F10
93                    gid F10
94                    gecos A40
95                    home A40
96                    shell A40.
97 LIST.
98
99 GET DATA /TYPE=TXT /FILE='cars.data' /DELIMITERS=' ' /FIRSTCASE=2
100         /VARIABLES=model A8
101                    year F4
102                    mileage F6
103                    price F5
104                    type A4
105                    age F2.
106 LIST.
107
108 GET DATA /TYPE=TXT /FILE='cars.data' /ARRANGEMENT=FIXED /FIRSTCASE=2
109         /VARIABLES=model 0-7 A
110                    year 8-15 F
111                    mileage 16-23 F
112                    price 24-31 F
113                    type 32-39 A
114                    age 40-47 F.
115 LIST.
116
117 GET DATA /TYPE=TXT /FILE='pets.data' /DELIMITERS=', ' /QUALIFIER='"'
118         /FIRSTCASE=3
119         /VARIABLES=name A10
120                    age F3.1
121                    color A5
122                    received EDATE10
123                    price F5.2
124                    needs_walking a5
125                    type a10.
126 LIST.
127 EOF
128 if [ $? -ne 0 ] ; then no_result ; fi
129
130 activity="run test"
131 $SUPERVISOR $PSPP --testing-mode test.pspp
132 if [ $? -ne 0 ] ; then no_result ; fi
133
134 activity="compare test results"
135 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
136 diff -b  $TEMPDIR/pspp.list - <<'EOF'
137             username                                 password        uid        gid                                    gecos                                     home                                    shell
138 -------------------- ---------------------------------------- ---------- ---------- ---------------------------------------- ---------------------------------------- ----------------------------------------
139 root                 $1$nyeSP5gD$pDq/                                  0          0 ,,,                                      /root                                    /bin/bash
140 blp                  $1$BrP/pFg4$g7OG                               1000       1000 Ben Pfaff,,,                             /home/blp                                /bin/bash
141 john                 $1$JBuq/Fioq$g4A                               1001       1001 John Darrington,,,                       /home/john                               /bin/bash
142 jhs                  $1$D3li4hPL$88X1                               1002       1002 Jason Stover,,,                          /home/jhs                                /bin/csh
143    model year mileage price type age
144 -------- ---- ------- ----- ---- ---
145 Civic    2002   29883 15900 Si     2
146 Civic    2003   13415 15900 EX     1
147 Civic    1992  107000  3800 n/a   12
148 Accord   2002   26613 17900 EX     1
149    model     year  mileage    price     type      age
150 -------- -------- -------- -------- -------- --------
151 Civic        2002    29883    15900 Si              2
152 Civic        2003    13415    15900 EX              1
153 Civic        1992   107000     3800 n/a            12
154 Accord       2002    26613    17900 EX              1
155       name  age color   received  price needs_walking       type
156 ---------- ---- ----- ---------- ------ ------------- ----------
157 Rover       4.5 Brown 12.02.2004  80.00         True  Dog
158 Charlie      .  Gold  05.04.2007  12.30         False Fish
159 Molly       2.0 Black 12.12.2006  25.00         False Cat
160 Gilly        .  White 10.04.2007  10.00         False Guinea Pig
161 EOF
162 if [ $? -ne 0 ] ; then fail ; fi
163
164
165
166 pass