10 Getopt::Long::Configure ("bundling");
11 GetOptions ("e|exact!" => \$exact,
13 "v|verbose+" => \$verbose,
14 "h|help" => sub { usage (0) })
18 print "$0: compare expected and actual numeric formatting output\n";
19 print "usage: $0 [OPTION...] EXPECTED ACTUAL\n";
20 print "where EXPECTED is the file containing expected output\n";
21 print "and ACTUAL is the file containing actual output.\n";
23 print " -e, --exact: Require numbers to be exactly equal.\n";
24 print " (By default, small differences are permitted.)\n";
25 print " -s, --spss: Ignore most SPSS formatting bugs in EXPECTED.\n";
26 print " (A few differences are not compensated)\n";
27 print " -v, --verbose: Use once to summarize errors and differences.\n";
28 print " Use twice for details of differences.\n";
32 open (EXPECTED, '<', $ARGV[0]) or die "$ARGV[0]: open: $!\n";
33 open (ACTUAL, '<', $ARGV[1]) or die "$ARGV[1]: open: $!\n";
36 my ($approximate) = 0;
41 while (defined (my $a = <EXPECTED>) && defined (my $b = <ACTUAL>)) {
45 if ($a !~ /^\s*$/ && $a !~ /:/) {
51 my ($fmt, $a_out) = $a =~ /^ (.*): "(.*)"$/ or die;
52 my ($b_fmt, $b_out) = $b =~ /^ (.*): "(.*)"$/ or die;
53 die if $fmt ne $b_fmt;
54 die if $a_out eq $b_out;
57 if (increment ($a_out) eq $b_out || increment ($b_out) eq $a_out) {
63 if ($a_out =~ /0.*0/ && $a_out !~ /[1-9]/) {
66 } elsif ($a_out =~ /\*/ && $a_out !~ /^\*+$/) {
69 } elsif ($expr =~ /^-/
71 && $b_out =~ /-\d(\.\d*#*)?E[-+]\d\d\d/
75 } elsif ($expr =~ /^-/
76 && (($a_out !~ /-/ && $a_out =~ /[1-9]/ && $b_out =~ /-/)
77 || ($a_out =~ /^[0-9]+$/ && $b_out =~ /^\*+$/))) {
82 print "$.: $expr in $fmt: expected \"$a_out\", got \"$b_out\"\n"
88 print "Extra lines in $ARGV[0]\n";
93 print "Extra lines in $ARGV[1]\n";
98 print "$errors errors\n";
100 print "$approximate approximate matches\n";
103 print "$bad_round bad rounds\n";
104 print "$spss_wtf1 SPSS WTF 1\n";
105 print "$spss_wtf2 SPSS WTF 2\n";
106 print "$lost_sign lost signs\n";
111 # Returns the argument value incremented by one unit in its final
115 my ($last_digit, $i);
116 for ($i = 0; $i < length $_; $i++) {
117 my ($c) = substr ($_, $i, 1);
119 $last_digit = $i if $c =~ /[0-9]/;
121 return $_ if !defined $last_digit;
122 for ($i = $last_digit; $i >= 0; $i--) {
123 my ($c) = substr ($_, $i, 1);
125 substr ($_, $i, 1) = '0';
126 } elsif ($c =~ /[0-8]/) {
127 substr ($_, $i, 1) = chr (ord ($c) + 1);
131 $_ = "1$_" if $i < 0;