Checkin of new directory structure.
[pspp-builds.git] / tests / expressions / expressions.sh
index 4ddb5537a0e608ac34a462a2feaa1f954ab2020a..b21fb8e1f492fac76cc57a9e496953a8258a0825 100755 (executable)
@@ -4,18 +4,22 @@
 
 TEMPDIR=/tmp/pspp-tst-$$
 
-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`
 
 # 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
 
 
 cleanup()
 {
+     cd /
      rm -rf $TEMPDIR
-     :
 }
 
 
@@ -665,6 +669,7 @@ number("123", f3.0) => 123.00
 number(" 123", f3.0) => 12.00
 number("123", f3.1) => 12.30
 number("   ", f3.1) => sysmis
+number("123", a8) => error
 number("123", cca1.2) => error # CCA is not an input format
 
 ltrim('   abc') => "abc"
@@ -1273,6 +1278,20 @@ SYSMIS($SYSMIS) => true
 SYSMIS(1 + $SYSMIS) => true
 
 # FIXME: out-of-range and nearly out-of-range values on dates
+
+# Tests correctness of generic optimizations in optimize_tree().
+(X = 10.00); x + 0 => 10.00
+(X = -3.00); x - 0 => -3.00
+(X = 5.00); 0 + x => 5.00
+(X = 10.00); x * 1 => 10.00
+(X = -3.00); 1 * x => -3.00
+(X = 5.00); x / 1 => 5.00
+(X = 10.00); 0 * x => 0.00
+(X = -3.00); x * 0 => 0.00
+(X = 5.00); 0 / x => 0.00
+(X = 5.00); mod(0, x) => 0.00
+(X = 5.00); x ** 1 => 5.00
+(X = 5.00); x ** 2 => 25.00
 EOF
 if [ $? -ne 0 ] ; then no_result ; fi
 
@@ -1282,14 +1301,14 @@ set mxerr 1000.' > $TEMPDIR/expr-opt.stat
 sed < $TEMPDIR/expr-list >> $TEMPDIR/expr-opt.stat \
        -e 's#^\(\(.*\); \)*\(.*\) => .*$#DEBUG EVALUATE\2/\3.#'
 if [ $? -ne 0 ] ; then no_result ; fi
-cp $TEMPDIR/expr-opt.stat ~/foo
 
 activity="run optimizing program"
-$SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii \
+$SUPERVISOR $top_builddir/src/pspp --testing-mode -o raw-ascii \
         $TEMPDIR/expr-opt.stat >$TEMPDIR/expr-opt.err 2> $TEMPDIR/expr-opt.out
 
 activity="compare optimizing output"
-diff -B -b $TEMPDIR/expr-list $TEMPDIR/expr-opt.out
+perl -pi -e 's/^\s*$//g' $TEMPDIR/expr-list $TEMPDIR/expr-opt.out
+diff -b $TEMPDIR/expr-list $TEMPDIR/expr-opt.out
 if [ $? -ne 0 ] ; then fail ; fi
 
 activity="create non-optimizing input"
@@ -1300,11 +1319,12 @@ sed < $TEMPDIR/expr-list >> $TEMPDIR/expr-noopt.stat \
 if [ $? -ne 0 ] ; then no_result ; fi
 
 activity="run non-optimizing program"
-$SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii \
+$SUPERVISOR $top_builddir/src/pspp --testing-mode -o raw-ascii \
        $TEMPDIR/expr-noopt.stat >$TEMPDIR/expr-noopt.err 2> $TEMPDIR/expr-noopt.out
 
 activity="compare non-optimizing output"
-diff -B -b $TEMPDIR/expr-list $TEMPDIR/expr-noopt.out
+perl -pi -e 's/^\s*$//g' $TEMPDIR/expr-list $TEMPDIR/expr-noopt.out
+diff -b $TEMPDIR/expr-list $TEMPDIR/expr-noopt.out
 if [ $? -ne 0 ] ; then fail ; fi
 
 activity="create optimizing postfix input"
@@ -1315,7 +1335,7 @@ sed < $TEMPDIR/expr-list >> $TEMPDIR/expr-opt-pos.stat \
 if [ $? -ne 0 ] ; then no_result ; fi
 
 activity="run optimizing postfix program"
-$SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii \
+$SUPERVISOR $top_builddir/src/pspp --testing-mode -o raw-ascii \
         $TEMPDIR/expr-opt-pos.stat >$TEMPDIR/expr-opt-pos.err 2> $TEMPDIR/expr-opt-pos.out
 if [ $? -eq 0 ] ; then no_result ; fi
 
@@ -1327,7 +1347,7 @@ sed < $TEMPDIR/expr-list >> $TEMPDIR/expr-noopt-pos.stat \
 if [ $? -ne 0 ] ; then no_result ; fi
 
 activity="run non-optimizing postfix program"
-$SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii \
+$SUPERVISOR $top_builddir/src/pspp --testing-mode -o raw-ascii \
        $TEMPDIR/expr-noopt-pos.stat >$TEMPDIR/expr-noopt-pos.err 2> $TEMPDIR/expr-noopt-pos.out
 if [ $? -eq 0 ] ; then no_result ; fi