- exists $cfg{$v} and next;
- if ($opt_l) {
- # print the name once, for the first problem we encounter.
- print "$cfg\n" unless $problems++;
- }
- else {
- print "$cfg: missing '$v'\n";
+ # 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, 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;