AUTORECODE: Use Autotest for test suite.
[pspp] / tests / command / add-files.sh
1 #!/bin/sh
2
3 # This program tests the ADD FILES procedure
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/add-files.pspp
7
8
9 # ensure that top_builddir  are absolute
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
12 top_builddir=`cd $top_builddir; pwd`
13 PSPP=$top_builddir/src/ui/terminal/pspp
14
15 # ensure that top_srcdir is absolute
16 top_srcdir=`cd $top_srcdir; pwd`
17
18
19 STAT_CONFIG_PATH=$top_srcdir/config
20 export STAT_CONFIG_PATH
21
22 cleanup()
23 {
24      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
25         echo "NOT cleaning $TEMPDIR" 
26         return ; 
27      fi
28     cd /
29     rm -rf $TEMPDIR
30 }
31
32
33 fail()
34 {
35     echo $activity
36     echo FAILED
37     cleanup;
38     exit 1;
39 }
40
41
42 no_result()
43 {
44     echo $activity
45     echo NO RESULT;
46     cleanup;
47     exit 2;
48 }
49
50 pass()
51 {
52     cleanup;
53     exit 0;
54 }
55
56 mkdir -p $TEMPDIR
57
58 cd $TEMPDIR
59
60 activity="data create"
61 cat > a.data <<EOF
62 1aB
63 8aM
64 3aE
65 5aG
66 0aA
67 5aH
68 6aI
69 7aJ
70 2aD
71 7aK
72 1aC
73 7aL
74 4aF
75 EOF
76 if [ $? -ne 0 ] ; then no_result ; fi
77 cat > b.data <<EOF
78 1bN
79 3bO
80 4bP
81 6bQ
82 7bR
83 9bS
84 EOF
85 if [ $? -ne 0 ] ; then no_result ; fi
86
87 cat > concatenate.csv <<EOF
88 Table: Data List
89 A,B,C,D,INA,INB
90 1,a,B,,1,0
91 8,a,M,,1,0
92 3,a,E,,1,0
93 5,a,G,,1,0
94 0,a,A,,1,0
95 5,a,H,,1,0
96 6,a,I,,1,0
97 7,a,J,,1,0
98 2,a,D,,1,0
99 7,a,K,,1,0
100 1,a,C,,1,0
101 7,a,L,,1,0
102 4,a,F,,1,0
103 1,b,,N,0,1
104 3,b,,O,0,1
105 4,b,,P,0,1
106 6,b,,Q,0,1
107 7,b,,R,0,1
108 9,b,,S,0,1
109 EOF
110
111 cat > interleave.csv <<EOF
112 Table: Data List
113 A,B,C,D,INA,INB,FIRST,LAST
114 0,a,A,,1,0,1,1
115 1,a,B,,1,0,1,0
116 1,a,C,,1,0,0,0
117 1,b,,N,0,1,0,1
118 2,a,D,,1,0,1,1
119 3,a,E,,1,0,1,0
120 3,b,,O,0,1,0,1
121 4,a,F,,1,0,1,0
122 4,b,,P,0,1,0,1
123 5,a,G,,1,0,1,0
124 5,a,H,,1,0,0,1
125 6,a,I,,1,0,1,0
126 6,b,,Q,0,1,0,1
127 7,a,J,,1,0,1,0
128 7,a,K,,1,0,0,0
129 7,a,L,,1,0,0,0
130 7,b,,R,0,1,0,1
131 8,a,M,,1,0,1,1
132 9,b,,S,0,1,1,1
133 EOF
134
135 # Test ADD FILES.
136 dla="data list notable file='a.data' /A B C 1-3 (a)."
137 sa="save outfile='a.sys'."
138 dlb="data list notable file='b.data' /A B C 1-3 (a)."
139 sb="save outfile='b.sys'."
140 for type in interleave concatenate; do
141     if test $type = interleave; then
142         by="/by a /first=FIRST /last=LAST"
143         sort="/sort"
144     else
145         by=
146         sort=
147     fi
148     for sources in ss sa as; do
149         name="$type-$sources"
150         activity="create $name.pspp"
151         {
152             if [ $sources = ss ]; then
153                 cat <<EOF
154 $dla
155 $sa
156 $dlb
157 $sb
158 add files file='a.sys' /in=INA $sort
159          /file='b.sys' /in=INB /rename c=D
160          $by.
161 EOF
162             elif [ $sources = sa ]; then
163                 cat <<EOF
164 $dla
165 $sa
166 $dlb
167 add files file='a.sys' /in=INA $sort
168          /file=* /in=INB /rename c=D
169          $by.
170 EOF
171             elif [ $sources = as ]; then
172                 cat <<EOF
173 $dlb
174 $sb
175 $dla
176 add files file=* /in=INA $sort
177             /file='b.sys' /in=INB /rename c=D
178             $by.
179 EOF
180             else
181                 activity="internal error"
182                 no_result
183             fi
184             echo 'list.'
185         } > $name.pspp
186         if [ $? -ne 0 ] ; then no_result ; fi
187
188         activity="run $name.pspp"
189         $SUPERVISOR $PSPP -o pspp.csv $name.pspp 
190         if [ $? -ne 0 ] ; then no_result ; fi
191
192         activity="check $name output"
193         perl -pi -e 's/^\s*$//g' pspp.csv
194         perl -pi -e 's/^\s*$//g' $type.csv
195         diff -u -b -w pspp.csv $type.csv
196         if [ $? -ne 0 ] ; then fail ; fi
197     done
198 done
199
200 pass;