Rewrite PSPP output engine.
[pspp-builds.git] / tests / command / update.sh
1 #!/bin/sh
2
3 # This program tests the UPDATE procedure
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/update.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 > update.csv <<EOF
88 Table: Data List
89 A,B,C,D,INA,INB
90 0,a,A,,1,0
91 1,b,B,N,1,1
92 1,a,C,,1,0
93 2,a,D,,1,0
94 3,b,E,O,1,1
95 4,b,F,P,1,1
96 5,a,G,,1,0
97 5,a,H,,1,0
98 6,b,I,Q,1,1
99 7,b,J,R,1,1
100 7,a,K,,1,0
101 7,a,L,,1,0
102 8,a,M,,1,0
103 9,b,,S,0,1
104 EOF
105
106 # Test UPDATE.
107 dla="data list notable file='a.data' /A B C 1-3 (a)."
108 sa="save outfile='a.sys'."
109 dlb="data list notable file='b.data' /A B C 1-3 (a)."
110 sb="save outfile='b.sys'."
111 for sources in ss sa as; do
112     name="$sources"
113     activity="create $name.pspp"
114     {
115         if [ $sources = ss ]; then
116             cat <<EOF
117 set errors=terminal.
118 $dla
119 $sa
120 $dlb
121 $sb
122 update file='a.sys' /in=INA /sort
123          /file='b.sys' /in=INB /rename c=D
124          /by a.
125 EOF
126         elif [ $sources = sa ]; then
127             cat <<EOF
128 set errors=terminal.
129 $dla
130 $sa
131 $dlb
132
133 update file='a.sys' /in=INA /sort
134       /file=* /in=INB /rename c=D
135       /by a.
136 EOF
137         elif [ $sources = as ]; then
138             cat <<EOF
139 set errors=terminal.
140 $dlb
141 $sb
142 $dla
143
144 update file=* /in=INA /sort
145       /file='b.sys' /in=INB /rename c=D
146       /by a.
147 EOF
148         else
149             activity="internal error"
150             no_result
151         fi
152         echo 'list.'
153     } > $name.pspp
154     if [ $? -ne 0 ] ; then no_result ; fi
155
156     activity="run $name.pspp"
157     rm -f errors
158     $SUPERVISOR $PSPP --testing-mode --error-file=errors $name.pspp
159     if [ $? -ne 0 ] ; then no_result ; fi
160
161     activity="check $name output"
162     perl -pi -e 's/^\s*$//g' pspp.csv
163     diff -c pspp.csv update.csv
164     if [ $? -ne 0 ] ; then fail ; fi
165     diff -c -b -w - errors <<EOF
166 $name.pspp:8: warning: UPDATE: Encountered 3 sets of duplicate cases in the master file.
167 EOF
168     if [ $? -ne 0 ] ; then fail ; fi
169 done
170
171 pass;