data-out: Pass correct width to value_str() in output_AHEX().
[pspp] / tests / data / data-out.at
index eb40bc460941591b73aef49dd604ca04d44749fe..b6d3b88e4615d4a9d03319b8fa19be0b13ab0345 100644 (file)
@@ -1,5 +1,275 @@
+dnl PSPP - a program for statistical analysis.
+dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl 
+dnl This program is free software: you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation, either version 3 of the License, or
+dnl (at your option) any later version.
+dnl 
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+dnl 
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
+dnl
 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 < 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 = <EXPECTED>) && defined (my $b = <ACTUAL>)) {
+    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 (<EXPECTED>) {
+    print "Extra lines in $ARGV[0]\n";
+    $errors++;
+    last;
+}
+while (<ACTUAL>) {
+    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([non-ASCII custom currency formats])
+AT_DATA([data-out.sps], [dnl
+SET CCA='«,¥,€,»'.
+SHOW CCA.
+DATA LIST LIST NOTABLE/x.
+PRINT/x (F8.2) x (CCA10.2).
+EXECUTE.
+BEGIN DATA.
+1
+-1
+1.5
+-1.5
+.75
+1.5e10
+-1.5e10
+END DATA.
+])
+AT_CHECK([pspp -O format=csv data-out.sps], [0], [dnl
+"data-out.sps:2: note: SHOW: CCA is «,¥,€,»."
+
+1.00   ¥1.00€ @&t@
+
+-1.00  «¥1.00€»
+
+1.50   ¥1.50€ @&t@
+
+-1.50  «¥1.50€»
+
+.75    ¥.75€ @&t@
+
+1.5E+010 ¥2E+010€ @&t@
+
+-2E+010«¥2E+010€»
+])
+AT_CLEANUP
+
 AT_SETUP([binary and hexadecimal output])
 AT_DATA([binhex-out.sps], [dnl
 SET ERRORS=NONE.
@@ -13791,11 +14061,12 @@ print outfile='month-out.out'/x(month40).
 execute.
 ])
 AT_CHECK([pspp -O format=csv month-out.sps], [1], [stdout])
-AT_CHECK([sed '/^$/d' stdout | sort | uniq -c], [0], [dnl
-     38 error: Month number 0.000000 is not between 1 and 12.
-     38 error: Month number 0.500000 is not between 1 and 12.
-     38 error: Month number 0.900000 is not between 1 and 12.
-     38 error: Month number 13.000000 is not between 1 and 12.
+AT_CHECK([[sed '/^ *\r*$/d' stdout | sort | uniq -c | sed 's/^[         ]*//']], [0],
+[dnl
+38 error: Month number 0.000000 is not between 1 and 12.
+38 error: Month number 0.500000 is not between 1 and 12.
+38 error: Month number 0.900000 is not between 1 and 12.
+38 error: Month number 13.000000 is not between 1 and 12.
 ])
 AT_CHECK([cat month-out.out], [0], [dnl
    .
@@ -14706,11 +14977,12 @@ end repeat.
 execute.
 ])
 AT_CHECK([pspp -O format=csv wkday-out.sps], [1], [stdout])
-AT_CHECK([sed '/^$/d' stdout | sort | uniq -c], [0], [dnl
-     39 error: Weekday number 0.000000 is not between 1 and 7.
-     39 error: Weekday number 0.500000 is not between 1 and 7.
-     39 error: Weekday number 0.900000 is not between 1 and 7.
-     39 error: Weekday number 8.000000 is not between 1 and 7.
+AT_CHECK([[sed '/^ *\r*$/d' stdout | sort | uniq -c | sed 's/^[         ]*//']], [0],
+[dnl
+39 error: Weekday number 0.000000 is not between 1 and 7.
+39 error: Weekday number 0.500000 is not between 1 and 7.
+39 error: Weekday number 0.900000 is not between 1 and 7.
+39 error: Weekday number 8.000000 is not between 1 and 7.
 ])
 AT_CHECK([cat wkday-out.out], [0], [dnl
   .
@@ -15417,3 +15689,22 @@ AT_CHECK([cat wkday-out.out], [0], [dnl
                                         .
 ])
 AT_CLEANUP
+
+dnl This checks for a regression where AHEX output would crash due to
+dnl dereferencing string data as a pointer, for string widths between
+dnl 5 and 8, inclusive.
+AT_SETUP([AHEX output bug])
+AT_DATA([ahex.sps], [
+DATA LIST NOTABLE /s (a8).
+BEGIN DATA.
+abcdefgh
+END DATA.
+FORMATS s (AHEX16).
+LIST.
+])
+AT_CHECK([pspp -O format=csv ahex.sps], [0], [dnl
+Table: Data List
+s
+6162636465666768
+])
+AT_CLEANUP