| 1 |
#!perl |
| 2 |
# rwt_head : rewrite the header part of test files in ../t |
| 3 |
# |
| 4 |
# The header terminator should be a line of '#'x25. |
| 5 |
|
| 6 |
use strict; |
| 7 |
use warnings; |
| 8 |
require './gen-head'; # for testhead() |
| 9 |
|
| 10 |
my $testdirname = '../t'; |
| 11 |
opendir TESTDIR, $testdirname; |
| 12 |
my @testfile = grep /\.t$/, readdir TESTDIR; |
| 13 |
closedir TESTDIR; |
| 14 |
|
| 15 |
# to keep the current test count and its comment |
| 16 |
my $re_test_count = qr/print "1\.\.([0-9]+)\\n"; \}/; |
| 17 |
|
| 18 |
my $req_perl = <<'REQPERL'; |
| 19 |
unless (5.008 <= $]) { |
| 20 |
print "1..0 # skipped: Perl 5.8.0 or later needed for this test\n"; |
| 21 |
print $@; |
| 22 |
exit; |
| 23 |
} |
| 24 |
REQPERL |
| 25 |
|
| 26 |
my $req_norm = <<'REQNORM'; |
| 27 |
BEGIN { |
| 28 |
eval { require Unicode::Normalize; }; |
| 29 |
if ($@) { |
| 30 |
print "1..0 # skipped: Unicode::Normalize needed for this test\n"; |
| 31 |
print $@; |
| 32 |
exit; |
| 33 |
} |
| 34 |
} |
| 35 |
REQNORM |
| 36 |
|
| 37 |
my $count_changed = 0; |
| 38 |
|
| 39 |
for my $filename (@testfile) { |
| 40 |
open my $origfh, "<$testdirname/$filename"; |
| 41 |
|
| 42 |
my $orig_header = ''; |
| 43 |
my $content = ''; |
| 44 |
my $found_separator; |
| 45 |
|
| 46 |
for my $line (<$origfh>) { |
| 47 |
if ($found_separator) { |
| 48 |
$content .= $line; |
| 49 |
} else { |
| 50 |
$orig_header .= $line; |
| 51 |
$found_separator = 1 if $line =~ /^\#{25}$/; |
| 52 |
} |
| 53 |
} |
| 54 |
close $origfh; |
| 55 |
|
| 56 |
# keep the current test count and its comment |
| 57 |
my $current_okcount = 0; |
| 58 |
my $current_comment = ''; |
| 59 |
if ($orig_header =~ /$re_test_count( #.*|)/o) { |
| 60 |
$current_okcount = $1; |
| 61 |
$current_comment = $2; |
| 62 |
} |
| 63 |
|
| 64 |
my $new_header = testhead("", $current_okcount); |
| 65 |
$new_header =~ s/($re_test_count)/$1$current_comment/o; |
| 66 |
|
| 67 |
# some changes for some test files |
| 68 |
if ($filename =~ /illegal[^p]|nonchar/) { |
| 69 |
$new_header =~ s/( *if \(\$ENV{PERL_CORE}\))/$req_perl$1/; |
| 70 |
} elsif ($filename =~ /loc/) { |
| 71 |
$new_header =~ s/(use Unicode::Collate)/${1}::Locale/; |
| 72 |
} elsif ($filename =~ /normal/) { |
| 73 |
$new_header =~ s/(use strict;)/$req_norm\n$1/; |
| 74 |
} # no else |
| 75 |
|
| 76 |
# nothing to do if no change |
| 77 |
next if $orig_header eq $new_header; |
| 78 |
|
| 79 |
# rewrite new files |
| 80 |
open my $newfh, ">$testdirname/$filename"; |
| 81 |
binmode $newfh; |
| 82 |
print $newfh "$new_header$content"; |
| 83 |
close $newfh; |
| 84 |
|
| 85 |
++my $count_changed; |
| 86 |
} |
| 87 |
|
| 88 |
warn $count_changed ? "changed $count_changed files" : "no change"; |