From 8626dba4b37d9b07d10888daf8cef3a26e5b114c Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 14 Oct 2010 21:01:56 -0700 Subject: [PATCH] data-out: Convert tests for numeric output formats to Autotest framework. --- tests/automake.mk | 12 +- tests/data/data-out.at | 218 ++++++++++++++++++ tests/{formats => data}/inexactify.c | 0 tests/{formats => data}/num-out-cmp.pl | 0 .../{formats => data}/num-out.expected.cmp.gz | Bin tests/formats/num-out-compare.pl | 133 ----------- tests/formats/num-out-decmp.pl | 28 --- tests/formats/num-out.pl | 41 ---- tests/formats/num-out.sh | 79 ------- 9 files changed, 222 insertions(+), 289 deletions(-) rename tests/{formats => data}/inexactify.c (100%) rename tests/{formats => data}/num-out-cmp.pl (100%) rename tests/{formats => data}/num-out.expected.cmp.gz (100%) delete mode 100644 tests/formats/num-out-compare.pl delete mode 100644 tests/formats/num-out-decmp.pl delete mode 100644 tests/formats/num-out.pl delete mode 100755 tests/formats/num-out.sh diff --git a/tests/automake.mk b/tests/automake.mk index fc58b3cb..0ee684d4 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/formats/num-out.sh \ tests/formats/time-in.sh \ tests/formats/360.sh @@ -19,7 +18,7 @@ TESTS = $(dist_TESTS) $(nodist_TESTS) check_PROGRAMS += \ $(nodist_TESTS) \ tests/data/datasheet-test \ - tests/formats/inexactify \ + tests/data/inexactify \ tests/libpspp/abt-test \ tests/libpspp/bt-test \ tests/libpspp/heap-test \ @@ -188,7 +187,7 @@ tests_libpspp_sparse_xarray_test_SOURCES = \ tests_libpspp_sparse_xarray_test_LDADD = gl/libgl.la $(LIBINTL) tests_libpspp_sparse_xarray_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10 -tests_formats_inexactify_SOURCES = tests/formats/inexactify.c +tests_data_inexactify_SOURCES = tests/data/inexactify.c noinst_PROGRAMS += tests/dissect-sysfile tests_dissect_sysfile_SOURCES = \ @@ -215,13 +214,10 @@ EXTRA_DIST += \ tests/data/binhex-out.expected.gz \ tests/data/legacy-in.expected.cmp.gz \ tests/data/num-in.expected.gz \ + tests/data/num-out-cmp.pl \ + tests/data/num-out.expected.cmp.gz \ tests/data/v13.sav \ tests/data/v14.sav \ - tests/formats/num-out.expected.cmp.gz \ - tests/formats/num-out-cmp.pl \ - tests/formats/num-out-compare.pl \ - tests/formats/num-out-decmp.pl \ - tests/formats/num-out.pl \ tests/language/data-io/Book1.gnm.unzipped CLEANFILES += *.save pspp.* foo* diff --git a/tests/data/data-out.at b/tests/data/data-out.at index eb40bc46..9a41a3b5 100644 --- a/tests/data/data-out.at +++ b/tests/data/data-out.at @@ -1,5 +1,223 @@ AT_BANNER([data output (data-out)]) +AT_SETUP([numeric format output]) +AT_DATA([num-out.pl], +[[use strict; +use warnings 'all'; + +my @values = qw(0 2 9.5 27 271 999.95 2718 9999.995 27182 271828 +2718281 2**39 2**333 2**-21 -2 -9.5 -27 -271 -999.95 -2718 -9999.995 +-27182 -271828 -2718281 -2**39 -2**333 -2**-21 -0 3.125 31.25 314.125 +3141.5 31415.875 314159.25 3141592.625 31415926.5 271828182.25 +3214567890.5 31415926535.875 -3.125 -31.375 -314.125 -3141.5 +-31415.875 -314159.25 -3141592.625 -31415926.5 -271828182.25 +-3214567890.5 -31415926535.875); + +print "SET CCA=',,,'.\n"; +print "SET CCB='-,[[[,]]],-'.\n"; +print "SET CCC='((,[,],))'.\n"; +print "SET CCD=',XXX,,-'.\n"; +print "SET CCE=',,YYY,-'.\n"; +print "INPUT PROGRAM.\n"; +print "STRING EXPR(A16).\n"; +print map ("COMPUTE NUM=$_.\nCOMPUTE EXPR='$_'.\nEND CASE.\n", @values); +print "END FILE.\n"; +print "END INPUT PROGRAM.\n"; + +print "PRINT OUTFILE='output.txt'/EXPR.\n"; +for my $format qw (F COMMA DOT DOLLAR PCT E CCA CCB CCC CCD CCE N Z) { + for my $d (0...16) { + my ($min_w); + if ($format ne 'E') { + $min_w = $d + 1; + $min_w++ if $format eq 'DOLLAR' || $format eq 'PCT'; + $min_w = 2 if $min_w == 1 && ($format =~ /^CC/); + } else { + $min_w = $d + 7; + } + for my $w ($min_w...40) { + my ($f) = "$format$w.$d"; + print "PRINT OUTFILE='output.txt'/'$f: \"' NUM($f) '\"'.\n"; + } + } + print "PRINT SPACE OUTFILE='output.txt'.\n"; +} +print "EXECUTE.\n"; +]]) +AT_CHECK([$PERL num-out.pl > num-out.sps]) +AT_CHECK([pspp -O format=csv num-out.sps]) +AT_CHECK([inexactify$EXEEXT < output.txt > output.inexact]) +AT_CHECK([gzip -cd < $top_srcdir/tests/data/num-out.expected.cmp.gz > expout.cmp]) +AT_DATA([num-out-decmp.pl], +[[use strict; +use warnings 'all'; + +my (@line); +while (<>) { + if (my ($n) = /^\*(\d+)$/) { + for (1...$n) { + $line[1]++; + $line[3] = " $line[3]"; + print ' ', join ('', @line), "\n"; + } + } elsif (my ($suffix) = /^\$(.*)$/) { + for my $c (split ('', $suffix)) { + $line[1]++; + $line[4] .= $c; + print ' ', join ('', @line), "\n"; + } + } elsif (my ($prefix) = /^\^(.*)$/) { + for my $c (split ('', $prefix)) { + $line[1]++; + $line[4] = "$c$line[4]"; + print ' ', join ('', @line), "\n"; + } + } else { + @line = /^([A-Z]+)(\d+)([^"]+")( *)([^%"]*)(%?")$/; + print " $_"; + } +} +]]) +AT_CHECK([$PERL num-out-decmp.pl < expout.cmp > expout.exact]) +AT_CHECK([[inexactify < expout.exact > expout.inexact]]) +AT_DATA([num-out-compare.pl], +[[#! /usr/bin/perl -w + +use strict; +use warnings 'all'; +use Getopt::Long; + +my $exact = 0; +my $spss = 0; +my $verbose = 0; +Getopt::Long::Configure ("bundling"); +GetOptions ("e|exact!" => \$exact, + "s|spss!" => \$spss, + "v|verbose+" => \$verbose, + "h|help" => sub { usage (0) }) + or usage (1); + +sub usage { + print "$0: compare expected and actual numeric formatting output\n"; + print "usage: $0 [OPTION...] EXPECTED ACTUAL\n"; + print "where EXPECTED is the file containing expected output\n"; + print "and ACTUAL is the file containing actual output.\n"; + print "Options:\n"; + print " -e, --exact: Require numbers to be exactly equal.\n"; + print " (By default, small differences are permitted.)\n"; + print " -s, --spss: Ignore most SPSS formatting bugs in EXPECTED.\n"; + print " (A few differences are not compensated)\n"; + print " -v, --verbose: Use once to summarize errors and differences.\n"; + print " Use twice for details of differences.\n"; + exit (@_); +} + +open (EXPECTED, '<', $ARGV[0]) or die "$ARGV[0]: open: $!\n"; +open (ACTUAL, '<', $ARGV[1]) or die "$ARGV[1]: open: $!\n"; +my ($expr); +my ($bad_round) = 0; +my ($approximate) = 0; +my ($spss_wtf1) = 0; +my ($spss_wtf2) = 0; +my ($lost_sign) = 0; +my ($errors) = 0; +while (defined (my $a = ) && defined (my $b = )) { + chomp $a; + chomp $b; + if ($a eq $b) { + if ($a !~ /^\s*$/ && $a !~ /:/) { + $expr = $a; + $expr =~ s/\s*$//; + $expr =~ s/^\s*//; + } + } else { + my ($fmt, $a_out) = $a =~ /^ (.*): "(.*)"$/ or die; + my ($b_fmt, $b_out) = $b =~ /^ (.*): "(.*)"$/ or die; + die if $fmt ne $b_fmt; + die if $a_out eq $b_out; + + if (!$exact) { + if (increment ($a_out) eq $b_out || increment ($b_out) eq $a_out) { + $approximate++; + next; + } + } + if ($spss) { + if ($a_out =~ /0.*0/ && $a_out !~ /[1-9]/) { + $bad_round++; + next; + } elsif ($a_out =~ /\*/ && $a_out !~ /^\*+$/) { + $spss_wtf1++; + next; + } elsif ($expr =~ /^-/ + && $a_out =~ /^\*+$/ + && $b_out =~ /-\d(\.\d*#*)?E[-+]\d\d\d/ + && $fmt =~ /^E/) { + $spss_wtf2++; + next; + } elsif ($expr =~ /^-/ + && (($a_out !~ /-/ && $a_out =~ /[1-9]/ && $b_out =~ /-/) + || ($a_out =~ /^[0-9]+$/ && $b_out =~ /^\*+$/))) { + $lost_sign++; + next; + } + } + print "$.: $expr in $fmt: expected \"$a_out\", got \"$b_out\"\n" + if $verbose > 1; + $errors++; + } +} +while () { + print "Extra lines in $ARGV[0]\n"; + $errors++; + last; +} +while () { + print "Extra lines in $ARGV[1]\n"; + $errors++; + last; +} +if ($verbose) { + print "$errors errors\n"; + if (!$exact) { + print "$approximate approximate matches\n"; + } + if ($spss) { + print "$bad_round bad rounds\n"; + print "$spss_wtf1 SPSS WTF 1\n"; + print "$spss_wtf2 SPSS WTF 2\n"; + print "$lost_sign lost signs\n"; + } +} +exit ($errors > 0); + +# Returns the argument value incremented by one unit in its final +# decimal place. +sub increment { + local ($_) = @_; + my ($last_digit, $i); + for ($i = 0; $i < length $_; $i++) { + my ($c) = substr ($_, $i, 1); + last if ($c eq 'E'); + $last_digit = $i if $c =~ /[0-9]/; + } + return $_ if !defined $last_digit; + for ($i = $last_digit; $i >= 0; $i--) { + my ($c) = substr ($_, $i, 1); + if ($c eq '9') { + substr ($_, $i, 1) = '0'; + } elsif ($c =~ /[0-8]/) { + substr ($_, $i, 1) = chr (ord ($c) + 1); + last; + } + } + $_ = "1$_" if $i < 0; + return $_; +} +]]) +AT_CHECK([$PERL num-out-compare.pl $PSPP_NUM_OUT_COMPARE_FLAGS expout.inexact output.inexact]) +AT_CLEANUP + AT_SETUP([binary and hexadecimal output]) AT_DATA([binhex-out.sps], [dnl SET ERRORS=NONE. diff --git a/tests/formats/inexactify.c b/tests/data/inexactify.c similarity index 100% rename from tests/formats/inexactify.c rename to tests/data/inexactify.c diff --git a/tests/formats/num-out-cmp.pl b/tests/data/num-out-cmp.pl similarity index 100% rename from tests/formats/num-out-cmp.pl rename to tests/data/num-out-cmp.pl diff --git a/tests/formats/num-out.expected.cmp.gz b/tests/data/num-out.expected.cmp.gz similarity index 100% rename from tests/formats/num-out.expected.cmp.gz rename to tests/data/num-out.expected.cmp.gz diff --git a/tests/formats/num-out-compare.pl b/tests/formats/num-out-compare.pl deleted file mode 100644 index be3c6239..00000000 --- a/tests/formats/num-out-compare.pl +++ /dev/null @@ -1,133 +0,0 @@ -#! /usr/bin/perl -w - -use strict; -use warnings 'all'; -use Getopt::Long; - -my $exact = 0; -my $spss = 0; -my $verbose = 0; -Getopt::Long::Configure ("bundling"); -GetOptions ("e|exact!" => \$exact, - "s|spss!" => \$spss, - "v|verbose+" => \$verbose, - "h|help" => sub { usage (0) }) - or usage (1); - -sub usage { - print "$0: compare expected and actual numeric formatting output\n"; - print "usage: $0 [OPTION...] EXPECTED ACTUAL\n"; - print "where EXPECTED is the file containing expected output\n"; - print "and ACTUAL is the file containing actual output.\n"; - print "Options:\n"; - print " -e, --exact: Require numbers to be exactly equal.\n"; - print " (By default, small differences are permitted.)\n"; - print " -s, --spss: Ignore most SPSS formatting bugs in EXPECTED.\n"; - print " (A few differences are not compensated)\n"; - print " -v, --verbose: Use once to summarize errors and differences.\n"; - print " Use twice for details of differences.\n"; - exit (@_); -} - -open (EXPECTED, '<', $ARGV[0]) or die "$ARGV[0]: open: $!\n"; -open (ACTUAL, '<', $ARGV[1]) or die "$ARGV[1]: open: $!\n"; -my ($expr); -my ($bad_round) = 0; -my ($approximate) = 0; -my ($spss_wtf1) = 0; -my ($spss_wtf2) = 0; -my ($lost_sign) = 0; -my ($errors) = 0; -while (defined (my $a = ) && defined (my $b = )) { - chomp $a; - chomp $b; - if ($a eq $b) { - if ($a !~ /^\s*$/ && $a !~ /:/) { - $expr = $a; - $expr =~ s/\s*$//; - $expr =~ s/^\s*//; - } - } else { - my ($fmt, $a_out) = $a =~ /^ (.*): "(.*)"$/ or die; - my ($b_fmt, $b_out) = $b =~ /^ (.*): "(.*)"$/ or die; - die if $fmt ne $b_fmt; - die if $a_out eq $b_out; - - if (!$exact) { - if (increment ($a_out) eq $b_out || increment ($b_out) eq $a_out) { - $approximate++; - next; - } - } - if ($spss) { - if ($a_out =~ /0.*0/ && $a_out !~ /[1-9]/) { - $bad_round++; - next; - } elsif ($a_out =~ /\*/ && $a_out !~ /^\*+$/) { - $spss_wtf1++; - next; - } elsif ($expr =~ /^-/ - && $a_out =~ /^\*+$/ - && $b_out =~ /-\d(\.\d*#*)?E[-+]\d\d\d/ - && $fmt =~ /^E/) { - $spss_wtf2++; - next; - } elsif ($expr =~ /^-/ - && (($a_out !~ /-/ && $a_out =~ /[1-9]/ && $b_out =~ /-/) - || ($a_out =~ /^[0-9]+$/ && $b_out =~ /^\*+$/))) { - $lost_sign++; - next; - } - } - print "$.: $expr in $fmt: expected \"$a_out\", got \"$b_out\"\n" - if $verbose > 1; - $errors++; - } -} -while () { - print "Extra lines in $ARGV[0]\n"; - $errors++; - last; -} -while () { - print "Extra lines in $ARGV[1]\n"; - $errors++; - last; -} -if ($verbose) { - print "$errors errors\n"; - if (!$exact) { - print "$approximate approximate matches\n"; - } - if ($spss) { - print "$bad_round bad rounds\n"; - print "$spss_wtf1 SPSS WTF 1\n"; - print "$spss_wtf2 SPSS WTF 2\n"; - print "$lost_sign lost signs\n"; - } -} -exit ($errors > 0); - -# Returns the argument value incremented by one unit in its final -# decimal place. -sub increment { - local ($_) = @_; - my ($last_digit, $i); - for ($i = 0; $i < length $_; $i++) { - my ($c) = substr ($_, $i, 1); - last if ($c eq 'E'); - $last_digit = $i if $c =~ /[0-9]/; - } - return $_ if !defined $last_digit; - for ($i = $last_digit; $i >= 0; $i--) { - my ($c) = substr ($_, $i, 1); - if ($c eq '9') { - substr ($_, $i, 1) = '0'; - } elsif ($c =~ /[0-8]/) { - substr ($_, $i, 1) = chr (ord ($c) + 1); - last; - } - } - $_ = "1$_" if $i < 0; - return $_; -} diff --git a/tests/formats/num-out-decmp.pl b/tests/formats/num-out-decmp.pl deleted file mode 100644 index 11007c00..00000000 --- a/tests/formats/num-out-decmp.pl +++ /dev/null @@ -1,28 +0,0 @@ -use strict; -use warnings 'all'; - -my (@line); -while (<>) { - if (my ($n) = /^\*(\d+)$/) { - for (1...$n) { - $line[1]++; - $line[3] = " $line[3]"; - print ' ', join ('', @line), "\n"; - } - } elsif (my ($suffix) = /^\$(.*)$/) { - for my $c (split ('', $suffix)) { - $line[1]++; - $line[4] .= $c; - print ' ', join ('', @line), "\n"; - } - } elsif (my ($prefix) = /^\^(.*)$/) { - for my $c (split ('', $prefix)) { - $line[1]++; - $line[4] = "$c$line[4]"; - print ' ', join ('', @line), "\n"; - } - } else { - @line = /^([A-Z]+)(\d+)([^"]+")( *)([^%"]*)(%?")$/; - print " $_"; - } -} diff --git a/tests/formats/num-out.pl b/tests/formats/num-out.pl deleted file mode 100644 index 86da406b..00000000 --- a/tests/formats/num-out.pl +++ /dev/null @@ -1,41 +0,0 @@ -use strict; -use warnings 'all'; - -my @values = qw(0 2 9.5 27 271 999.95 2718 9999.995 27182 271828 -2718281 2**39 2**333 2**-21 -2 -9.5 -27 -271 -999.95 -2718 -9999.995 --27182 -271828 -2718281 -2**39 -2**333 -2**-21 -0 3.125 31.25 314.125 -3141.5 31415.875 314159.25 3141592.625 31415926.5 271828182.25 -3214567890.5 31415926535.875 -3.125 -31.375 -314.125 -3141.5 --31415.875 -314159.25 -3141592.625 -31415926.5 -271828182.25 --3214567890.5 -31415926535.875); - -print "SET CCA=',,,'.\n"; -print "SET CCB='-,[[[,]]],-'.\n"; -print "SET CCC='((,[,],))'.\n"; -print "SET CCD=',XXX,,-'.\n"; -print "SET CCE=',,YYY,-'.\n"; -print "INPUT PROGRAM.\n"; -print "STRING EXPR(A16).\n"; -print map ("COMPUTE NUM=$_.\nCOMPUTE EXPR='$_'.\nEND CASE.\n", @values); -print "END FILE.\n"; -print "END INPUT PROGRAM.\n"; - -print "PRINT OUTFILE='output.txt'/EXPR.\n"; -for my $format qw (F COMMA DOT DOLLAR PCT E CCA CCB CCC CCD CCE N Z) { - for my $d (0...16) { - my ($min_w); - if ($format ne 'E') { - $min_w = $d + 1; - $min_w++ if $format eq 'DOLLAR' || $format eq 'PCT'; - $min_w = 2 if $min_w == 1 && ($format =~ /^CC/); - } else { - $min_w = $d + 7; - } - for my $w ($min_w...40) { - my ($f) = "$format$w.$d"; - print "PRINT OUTFILE='output.txt'/'$f: \"' NUM($f) '\"'.\n"; - } - } - print "PRINT SPACE OUTFILE='output.txt'.\n"; -} -print "EXECUTE.\n"; diff --git a/tests/formats/num-out.sh b/tests/formats/num-out.sh deleted file mode 100755 index 2d0932f7..00000000 --- a/tests/formats/num-out.sh +++ /dev/null @@ -1,79 +0,0 @@ -#! /bin/sh - -TEMPDIR=/tmp/pspp-tst-$$ -mkdir -p $TEMPDIR -trap 'cd /; rm -rf $TEMPDIR' 0 - -# 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 -: ${PERL:=perl} - -# ensure that top_srcdir is absolute -top_srcdir=`cd $top_srcdir; pwd` - -STAT_CONFIG_PATH=$top_srcdir/config -export STAT_CONFIG_PATH - -fail() -{ - echo $activity - echo FAILED - exit 1; -} - - -no_result() -{ - echo $activity - echo NO RESULT; - exit 2; -} - -pass() -{ - exit 0; -} - -cd $TEMPDIR - -activity="generate pspp syntax" -$PERL $top_srcdir/tests/formats/num-out.pl > num-out.pspp -if [ $? -ne 0 ] ; then no_result ; fi -echo -n . - -activity="run program" -$SUPERVISOR $PSPP -o pspp.csv num-out.pspp -if [ $? -ne 0 ] ; then no_result ; fi -echo -n . - -activity="inexactify results" -$top_builddir/tests/formats/inexactify$EXEEXT < output.txt > output.inexact -if [ $? -ne 0 ] ; then no_result ; fi -echo -n . - -activity="gunzip expected results" -gzip -cd < $top_srcdir/tests/formats/num-out.expected.cmp.gz > expected.txt.cmp -if [ $? -ne 0 ] ; then no_result ; fi -echo -n . - -activity="decompress expected results" -$PERL $top_srcdir/tests/formats/num-out-decmp.pl < expected.txt.cmp > expected.txt -if [ $? -ne 0 ] ; then no_result ; fi -echo -n . - -activity="inexactify expected results" -$top_builddir/tests/formats/inexactify$EXEEXT < expected.txt > expected.inexact -if [ $? -ne 0 ] ; then no_result ; fi -echo -n . - -activity="compare output" -$PERL $top_srcdir/tests/formats/num-out-compare.pl \ - $PSPP_NUM_OUT_COMPARE_FLAGS expected.inexact output.inexact -if [ $? -ne 0 ] ; then fail ; fi - -echo . - -pass -- 2.30.2