This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta for 9e0ea7f
[perl5.git] / Porting / checkcfgvar.pl
index 34d3bd4..3ebde3a 100755 (executable)
@@ -24,11 +24,14 @@ use Getopt::Long;
 my $opt_l = 0;
 my $opt_r = 0;
 my $default;
+my $tap = 0;
+my $test;
 GetOptions (
     "help|?"   => sub { usage (0); },
     "l|list!"  => \$opt_l,
     "regen"    => \$opt_r,
     "default=s" => \$default,
+    "tap"      => \$tap,
     ) or usage (1);
 
 require 'regen/regen_lib.pl' if $opt_r;
@@ -43,17 +46,13 @@ my @CFG = (
           # We can't base our check on $], because that's the version of the
           # perl that we are running, not the version of the source tree.
           "Cross/config.sh-arm-linux",
-          "epoc/config.sh",
           "NetWare/config.wc",
           "symbian/config.sh",
           "uconfig.sh",
           "uconfig64.sh",
           "plan9/config_sh.sample",
           "win32/config.gc",
-          "win32/config.gc64",
-          "win32/config.gc64nox",
           "win32/config.vc",
-          "win32/config.vc64",
           "win32/config.ce",
           "configure.com",
           "Porting/config.sh",
@@ -84,6 +83,8 @@ my %MANIFEST;
     close $fh;
 }
 
+printf "1..%d\n", 2 * @CFG if $tap;
+
 for my $cfg (sort @CFG) {
     unless (exists $MANIFEST{$cfg}) {
        print STDERR "[skipping not-expected '$cfg']\n";
@@ -127,37 +128,53 @@ for my $cfg (sort @CFG) {
     }
     close $fh;
 
-    my $problems;
-    if ($cfg ne 'configure.com') {
-       if (join("", @{$lines[1]}) ne join("", sort @{$lines[1]})) {
-           ++$problems;
-           if ($opt_r) {
-               @{$lines[1]} = sort @{$lines[1]};
-           } elsif ($opt_l) {
-               print "$cfg\n";
-           }
-           else {
-               print "$cfg: unsorted\n";
-           }
-       }
+    ++$test;
+    my $missing;
+    if ($cfg eq 'configure.com') {
+       print "ok $test # skip $cfg doesn't need to be sorted\n"
+           if $tap;
+    } elsif (join("", @{$lines[1]}) eq join("", sort @{$lines[1]})) {
+       print "ok $test - $cfg sorted\n"
+           if $tap;
+    } elsif ($tap) {
+       print "not ok $test - $cfg is not sorted\n";
+    } elsif ($opt_r || $opt_l) {
+       # A reference to an empty array is true, hence this flags the
+       # file for later attention by --regen and --list, even if
+       # nothing is missing. Actual sort and output are done later.
+       $missing = [];
+    } else {
+       print "$cfg: unsorted\n"
     }
+
     for my $v (@MASTER_CFG) {
-       exists $cfg{$v} and next;
-       if (defined $default && $cfg ne 'configure.com') {
-           push @{$lines[1]}, "$v='$default'\n";
-           ++$problems;
+       # This only creates a reference in $missing if something is missing:
+       push @$missing, $v unless exists $cfg{$v};
+    }
+
+    ++$test;
+    if ($missing) {
+       if ($tap) {
+           print "not ok $test - $cfg missing keys @$missing\n";
        } elsif ($opt_l) {
-           # print the name once, for the first problem we encounter.
-           print "$cfg\n" unless $problems++;
-       }
-       else {
-           print "$cfg: missing '$v'\n";
+           # print the name once, however many problems
+           print "$cfg\n";
+       } elsif ($opt_r && $cfg ne 'configure.com') {
+           if (defined $default) {
+               push @{$lines[1]}, map {"$_='$default'\n"} @$missing;
+           } else {
+               print "$cfg: missing '$_', use --default to add it\n"
+                   foreach @$missing;
+           }
+
+           @{$lines[1]} = sort @{$lines[1]};
+           my $fh = open_new($cfg);
+           print $fh @{$_} foreach @lines;
+           close_and_rename($fh);
+       } else {
+           print "$cfg: missing '$_'\n" foreach @$missing;
        }
-    }
-    if ($problems && $opt_r) {
-       @{$lines[1]} = sort @{$lines[1]};
-       my $fh = open_new($cfg);
-       print $fh @{$_} foreach @lines;
-       close_and_rename($fh);
+    } elsif ($tap) {
+       print "ok $test - $cfg has no missing keys\n";
     }
 }