Merge commit 'origin/stable'
[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.out <<EOF
88 A B C D INA INB
89 - - - - --- ---
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 perl -pi -e 's/^\s*$//g' update.out
106
107 # Test UPDATE.
108 dla="data list notable file='a.data' /A B C 1-3 (a)."
109 sa="save outfile='a.sys'."
110 dlb="data list notable file='b.data' /A B C 1-3 (a)."
111 sb="save outfile='b.sys'."
112 for sources in ss sa as; do
113     name="$sources"
114     activity="create $name.pspp"
115     {
116         if [ $sources = ss ]; then
117             cat <<EOF
118 set errors=terminal.
119 $dla
120 $sa
121 $dlb
122 $sb
123 update file='a.sys' /in=INA /sort
124          /file='b.sys' /in=INB /rename c=D
125          /by a.
126 EOF
127         elif [ $sources = sa ]; then
128             cat <<EOF
129 set errors=terminal.
130 $dla
131 $sa
132 $dlb
133
134 update file='a.sys' /in=INA /sort
135       /file=* /in=INB /rename c=D
136       /by a.
137 EOF
138         elif [ $sources = as ]; then
139             cat <<EOF
140 set errors=terminal.
141 $dlb
142 $sb
143 $dla
144
145 update file=* /in=INA /sort
146       /file='b.sys' /in=INB /rename c=D
147       /by a.
148 EOF
149         else
150             activity="internal error"
151             no_result
152         fi
153         echo 'list.'
154     } > $name.pspp
155     if [ $? -ne 0 ] ; then no_result ; fi
156
157     activity="run $name.pspp"
158     rm -f errors
159     $SUPERVISOR $PSPP --testing-mode --error-file=errors $name.pspp
160     if [ $? -ne 0 ] ; then no_result ; fi
161
162     activity="check $name output"
163     perl -pi -e 's/^\s*$//g' pspp.list
164     diff -c -b -w pspp.list update.out
165     if [ $? -ne 0 ] ; then fail ; fi
166     diff -c -b -w - errors <<EOF
167 $name.pspp:8: warning: UPDATE: Encountered 3 sets of duplicate cases in the master file.
168 EOF
169     if [ $? -ne 0 ] ; then fail ; fi
170 done
171
172 pass;