From cd36f412b771fe2d88d2c3d9a9809f288afa38ca Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 2 Oct 2010 10:50:32 -0700 Subject: [PATCH] LOOP: Convert tests to Autotest framework. --- tests/automake.mk | 2 +- tests/command/loop.sh | 298 --------------------------------- tests/language/control/loop.at | 248 +++++++++++++++++++++++++++ 3 files changed, 249 insertions(+), 299 deletions(-) delete mode 100755 tests/command/loop.sh create mode 100644 tests/language/control/loop.at diff --git a/tests/automake.mk b/tests/automake.mk index c080d205..4393793b 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -10,7 +10,6 @@ TESTS_ENVIRONMENT += LC_ALL=C TESTS_ENVIRONMENT += EXEEXT=$(EXEEXT) dist_TESTS = \ - tests/command/loop.sh \ tests/command/longvars.sh \ tests/command/match-files.sh \ tests/command/missing-values.sh \ @@ -365,6 +364,7 @@ TESTSUITE_AT = \ tests/language/command.at \ tests/language/control/do-if.at \ tests/language/control/do-repeat.at \ + tests/language/control/loop.at \ tests/language/data-io/add-files.at \ tests/language/data-io/data-list.at \ tests/language/data-io/data-reader.at \ diff --git a/tests/command/loop.sh b/tests/command/loop.sh deleted file mode 100755 index 71173753..00000000 --- a/tests/command/loop.sh +++ /dev/null @@ -1,298 +0,0 @@ -#!/bin/sh - -# This program tests the LOOP command - -TEMPDIR=/tmp/pspp-tst-$$ -TESTFILE=$TEMPDIR/`basename $0`.sps - -# 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$EXEEXT - -# ensure that top_srcdir is absolute -top_srcdir=`cd $top_srcdir; pwd` - -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 -} - - -fail() -{ - echo $activity - echo FAILED - cleanup; - exit 1; -} - - -no_result() -{ - echo $activity - echo NO RESULT; - cleanup; - exit 2; -} - -pass() -{ - cleanup; - exit 0; -} - -mkdir -p $TEMPDIR - -cd $TEMPDIR - -activity="create prog" -cat > $TEMPDIR/loop.stat < 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 $PSPP -o pspp.csv -e $TEMPDIR/stdout $TEMPDIR/loop.stat -if [ $? -ne 0 ] ; then no_result ; fi - -activity="compare stdout" -perl -pi -e 's/^\s*$//g' $TEMPDIR/stdout -diff -b $TEMPDIR/stdout - < y. +print/'--------'. +execute. +]) +AT_CHECK([pspp -o pspp.csv loop.sps]) +AT_CHECK([cat pspp.csv], [0], [dnl +1.00 @&t@ + +2.00 @&t@ + +-------- + +2.00 @&t@ + +4.00 @&t@ + +-------- + +3.00 @&t@ + +6.00 @&t@ + +9.00 @&t@ + +-------- + +4.00 @&t@ + +-------- +]) +AT_CLEANUP + +AT_SETUP([LOOP with index and IF based on index]) +AT_DATA([loop.sps], [dnl +LOOP_DATA +loop #m=x to y by z if #m < 4. +print /#m. +end loop. +print/'--------'. +execute. +]) +AT_CHECK([pspp -o pspp.csv loop.sps]) +AT_CHECK([cat pspp.csv], [0], [dnl +1.00 @&t@ + +2.00 @&t@ + +-------- + +2.00 @&t@ + +-------- + +3.00 @&t@ + +-------- + +-------- +]) +AT_CLEANUP + +AT_SETUP([LOOP with index and END IF based on index]) +AT_DATA([loop.sps], [dnl +LOOP_DATA +loop #n=x to y by z. +print /#n. +end loop if #n >= 4. +print/'--------'. +execute. +]) +AT_CHECK([pspp -o pspp.csv loop.sps]) +AT_CHECK([cat pspp.csv], [0], [dnl +1.00 @&t@ + +2.00 @&t@ + +-------- + +2.00 @&t@ + +4.00 @&t@ + +-------- + +3.00 @&t@ + +6.00 @&t@ + +-------- + +-------- +]) +AT_CLEANUP + +AT_SETUP([LOOP with index and IF and END IF based on index]) +AT_DATA([loop.sps], [dnl +LOOP_DATA +loop #o=x to y by z if mod(#o,2) = 0. +print /#o. +end loop if #o >= 4. +print/'--------'. +execute. +]) +AT_CHECK([pspp -o pspp.csv loop.sps]) +AT_CHECK([cat pspp.csv], [0], [dnl +-------- + +2.00 @&t@ + +4.00 @&t@ + +-------- + +-------- + +-------- +]) +AT_CLEANUP + +AT_SETUP([LOOP with no conditions]) +AT_DATA([loop.sps], [dnl +LOOP_DATA +set mxloops = 2. +compute #p = x. +loop. +print /#p. +compute #p = #p + z. +do if #p >= y. +break. +end if. +end loop. +print/'--------'. +execute. +]) +AT_CHECK([pspp -o pspp.csv loop.sps]) +AT_CHECK([cat pspp.csv], [0], [dnl +1.00 @&t@ + +-------- + +2.00 @&t@ + +4.00 @&t@ + +-------- + +3.00 @&t@ + +6.00 @&t@ + +-------- + +4.00 @&t@ + +-------- +]) +AT_CLEANUP -- 2.30.2