Rewrite PSPP output engine.
[pspp-builds.git] / tests / command / loop.sh
index 3c824c9d8e86f7791be8bbe9ba4d52b199478eef..21d883e8ff312454a6a495dd4ba3c1f3e23c070a 100755 (executable)
@@ -5,16 +5,29 @@
 TEMPDIR=/tmp/pspp-tst-$$
 TESTFILE=$TEMPDIR/`basename $0`.sps
 
-here=`pwd`;
+# ensure that top_builddir  are absolute
+if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
+if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
+top_builddir=`cd $top_builddir; pwd`
+PSPP=$top_builddir/src/ui/terminal/pspp
 
 # ensure that top_srcdir is absolute
-cd $top_srcdir; top_srcdir=`pwd`
+top_srcdir=`cd $top_srcdir; pwd`
 
-export STAT_CONFIG_PATH=$top_srcdir/config
+STAT_CONFIG_PATH=$top_srcdir/config
+export STAT_CONFIG_PATH
+
+LANG=C
+export LANG
 
 
 cleanup()
 {
+     if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
+       echo "NOT cleaning $TEMPDIR" 
+       return ; 
+     fi
+     cd /
      rm -rf $TEMPDIR
 }
 
@@ -48,45 +61,236 @@ cd $TEMPDIR
 
 activity="create prog"
 cat > $TEMPDIR/loop.stat <<EOF
-data list /x 1 y 2 zoological 3.
+data list notable /x 1 y 2 z 3.
 begin data.
-125
-256
-397
-401
+121
+252
+393
+404
 end data.
-loop iterative_Variable=y to zoological by abs(zoological-y)/(zoological-y).
-print /x iterative_Variable.
-break.         /* Generates warning.
+
+echo 'Loop with index'.
+loop #i=x to y by z.
+print /#i.
+end loop.
+print/'--------'.
+execute.
+
+echo 'Loop with IF condition'.
+compute #j=x.
+loop if #j <= y.
+print /#j.
+compute #j = #j + z.
+end loop.
+print/'--------'.
+execute.
+
+echo 'Loop with END IF condition'.
+compute #k=x.
+loop.
+print /#k.
+compute #k = #k + z.
+end loop if #k > y.
+print/'--------'.
+execute.
+
+echo 'Loop with index and IF condition based on index'.
+loop #m=x to y by z if #m < 4.
+print /#m.
 end loop.
+print/'--------'.
+execute.
+
+echo 'Loop with index and END IF condition based on index'.
+loop #n=x to y by z.
+print /#n.
+end loop if #n >= 4.
+print/'--------'.
+execute.
+
+echo 'Loop with index and IF and END IF condition based on index'.
+loop #o=x to y by z if mod(#o,2) = 0.
+print /#o.
+end loop if #o >= 4.
+print/'--------'.
+execute.
+
+echo 'Loop with no conditions'.
+set mxloops = 2.
+compute #p = x.
+loop.
+print /#p.
+compute #p = #p + z.
+do if #p >= y.
+break.
+end if.
+end loop.
+print/'--------'.
 execute.
 EOF
 if [ $? -ne 0 ] ; then no_result ; fi
 
 activity="run program"
-$SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii $TEMPDIR/loop.stat > $TEMPDIR/stdout
+$SUPERVISOR $PSPP --testing-mode -e $TEMPDIR/stdout $TEMPDIR/loop.stat 
 if [ $? -ne 0 ] ; then no_result ; fi
 
 activity="compare stdout"
-diff -B -b $TEMPDIR/stdout  - <<EOF
-$TEMPDIR/loop.stat:10: warning: BREAK: BREAK not enclosed in DO IF structure.
+perl -pi -e 's/^\s*$//g' $TEMPDIR/stdout
+diff -b $TEMPDIR/stdout  - <<EOF
 EOF
 if [ $? -ne 0 ] ; then fail ; fi
 
 activity="compare results"
-diff -B -b $TEMPDIR/pspp.list  - <<EOF
-1.1 DATA LIST.  Reading 1 record from the command file.
-+--------+------+-------+------+
-|Variable|Record|Columns|Format|
-#========#======#=======#======#
-|X       |     1|  1-  1|F1.0  |
-|Y       |     1|  2-  2|F1.0  |
-|ZOOLOGIC|     1|  3-  3|F1.0  |
-+--------+------+-------+------+
-1     2.00 
-2     5.00 
-3     9.00 
-4      .00 
+diff -c $TEMPDIR/pspp.csv  - <<EOF
+Loop with index
+
+1.00 
+
+2.00 
+
+--------
+
+2.00 
+
+4.00 
+
+--------
+
+3.00 
+
+6.00 
+
+9.00 
+
+--------
+
+--------
+
+Loop with IF condition
+
+1.00 
+
+2.00 
+
+--------
+
+2.00 
+
+4.00 
+
+--------
+
+3.00 
+
+6.00 
+
+9.00 
+
+--------
+
+--------
+
+Loop with END IF condition
+
+1.00 
+
+2.00 
+
+--------
+
+2.00 
+
+4.00 
+
+--------
+
+3.00 
+
+6.00 
+
+9.00 
+
+--------
+
+4.00 
+
+--------
+
+Loop with index and IF condition based on index
+
+1.00 
+
+2.00 
+
+--------
+
+2.00 
+
+--------
+
+3.00 
+
+--------
+
+--------
+
+Loop with index and END IF condition based on index
+
+1.00 
+
+2.00 
+
+--------
+
+2.00 
+
+4.00 
+
+--------
+
+3.00 
+
+6.00 
+
+--------
+
+--------
+
+Loop with index and IF and END IF condition based on index
+
+--------
+
+2.00 
+
+4.00 
+
+--------
+
+--------
+
+--------
+
+Loop with no conditions
+
+1.00 
+
+--------
+
+2.00 
+
+4.00 
+
+--------
+
+3.00 
+
+6.00 
+
+--------
+
+4.00 
+
+--------
 EOF
 if [ $? -ne 0 ] ; then fail ; fi