Added a test for the compute command.
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 17 Dec 2003 05:39:14 +0000 (05:39 +0000)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 17 Dec 2003 05:39:14 +0000 (05:39 +0000)
src/Makefile.am
tests/Makefile.am
tests/command/compute.sh [new file with mode: 0755]
tests/compute.stat [deleted file]

index 005ae68541b2cf9278cc7ca616ef4121634b4c3d..4b833261b3a4104fd2a6b6766e9cfc6c33d0aa3a 100644 (file)
@@ -8,7 +8,7 @@ pkgsysconfdir = $(sysconfdir)/@PACKAGE@
 
 bin_PROGRAMS = pspp
 
-INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/lib     \
+AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/lib  \
 -I$(top_srcdir)/intl
 
 DISTCLEANFILES = foo $(q_sources_c)
@@ -47,7 +47,7 @@ stats.c stats.h str.c str.h sysfile-info.c tab.c tab.h temporary.c    \
 title.c t-test.c val-labs.c var-labs.c var.h vars-atr.c vars-prs.c     \
 vector.c vector.h version.c version.h vfm.c vfm.h vfmP.h weight.c
 
-LDADD =        ../lib/julcal/libjulcal.a               \
+pspp_LDADD =   ../lib/julcal/libjulcal.a               \
        ../lib/misc/libmisc.a                   \
        ../lib/dcdflib/libdcdflib.a             \
        @LIBINTL@
index d064145a1281edfa686f098958c6b614db7739aa..4c9f3f647a16c599979143b1d76e68da412075f7 100644 (file)
@@ -6,6 +6,7 @@ TESTS = command/aggregate.sh \
        command/beg-data.sh \
        command/bignum.sh \
        command/count.sh \
+       command/compute.sh \
        command/descriptives.sh \
        command/file-label.sh \
        command/flip.sh \
@@ -28,7 +29,7 @@ sort.data: gengarbage$(EXTEXT)
        ./gengarbage | head -1000 > $@
 
 EXTRA_DIST = \
-compute.stat crosstabs.stat data-fmts.stat     \
+crosstabs.stat data-fmts.stat  \
 data-list.data do-if.stat do-repeat.stat       \
 expr.stat filter.stat gengarbage.c             \
 inpt-pgm.stat list.data mtch-file.stat  \
diff --git a/tests/command/compute.sh b/tests/command/compute.sh
new file mode 100755 (executable)
index 0000000..0e3655c
--- /dev/null
@@ -0,0 +1,95 @@
+#!/bin/sh
+
+# This program tests the COMPUTE command
+# (it also gives LPAD and RPAD a work out)
+
+TEMPDIR=/tmp/pspp-tst-$$
+
+here=`pwd`;
+
+# ensure that top_srcdir is absolute
+cd $top_srcdir; top_srcdir=`pwd`
+
+export STAT_CONFIG_PATH=$top_srcdir/config
+
+
+cleanup()
+{
+     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 program"
+cat > $TEMPDIR/compute.stat <<EOF
+data list /w 1-3(a).
+begin data.
+123
+456
+919
+572
+end data.
+
+string z(a6).
+compute x=number(w).
+compute y=number(w,f8).
+compute z=lpad(
+       rpad(
+               substr(string(x,f6),4,1),
+               3,'@'),
+       6,'*').
+compute y=y+1e-10.
+list.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+$here/../src/pspp --testing-mode -o raw-ascii $TEMPDIR/compute.stat
+if [ $? -ne 0 ] ; then no_result ; fi
+
+diff -B -b $TEMPDIR/pspp.list - <<EOF
+1.1 DATA LIST.  Reading 1 record from the command file.
++--------+------+-------+------+
+|Variable|Record|Columns|Format|
+#========#======#=======#======#
+|W       |     1|  1-  3|A3    |
++--------+------+-------+------+
+
+  W      Z        X        Y
+--- ------ -------- --------
+123 ***1@@   123.00   123.00 
+456 ***4@@   456.00   456.00 
+919 ***9@@   919.00   919.00 
+572 ***5@@   572.00   572.00 
+
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+
+pass;
diff --git a/tests/compute.stat b/tests/compute.stat
deleted file mode 100644 (file)
index 5538724..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-title 'Test COMPUTE expressions'.
-
-data list /w 1-3(a).
-begin data.
-123
-456
-919
-572
-end data.
-*string y z(a6).
-*compute y=ltrim(lpad(w,6,'*'),'*').
-*compute z=rtrim(rpad(w,6,'*'),'*').
-string z(a6).
-compute x=number(w).
-compute y=number(w,f8).
-compute z=lpad(rpad(substr(string(x,f6),4,1),3,'@'),6,'*').
-compute y=y+1e-10.
-if(x<=456) y=500.
-select if x<=456.
-compute #caseseq=#caseseq+1.
-list.
-list.