1b39c5158Smillert#!/perl -w 2b39c5158Smillertuse strict; 3b39c5158Smillert 4*de8cc8edSafresh1# See "TESTING" in perlhack.pod for the instructions about where test files 5*de8cc8edSafresh1# are located and which constructions should be avoided in the early tests. 6b39c5158Smillert 7b39c5158Smillert# This regression tests ensures that the rules aren't accidentally overlooked. 8b39c5158Smillert 991f110e0Safresh1BEGIN { 1091f110e0Safresh1 chdir 't'; 11b39c5158Smillert require './test.pl'; 1291f110e0Safresh1} 13b39c5158Smillert 14b39c5158Smillertplan('no_plan'); 15b39c5158Smillert 16b39c5158Smillertopen my $fh, '<', '../MANIFEST' or die "Can't open MANIFEST: $!"; 17b39c5158Smillert 185759b3d2Safresh1# Some tests in t/comp need to use require or use to get their job done: 195759b3d2Safresh1my %exceptions = ( 205759b3d2Safresh1 filter_exception => "require './test.pl'", 215759b3d2Safresh1 hints => "require './test.pl'", 22b39c5158Smillert parser => 'use DieDieDie', 235759b3d2Safresh1 parser_run => "require './test.pl'", 24b39c5158Smillert proto => 'use strict', 25b39c5158Smillert ); 26b39c5158Smillert 27b39c5158Smillertwhile (my $file = <$fh>) { 28b39c5158Smillert next unless $file =~ s!^t/!!; 29b39c5158Smillert chomp $file; 30b39c5158Smillert $file =~ s/\s+.*//; 31b39c5158Smillert next unless $file =~ m!\.t$!; 32b39c5158Smillert 33b39c5158Smillert local $/; 34b39c5158Smillert open my $t, '<', $file or die "Can't open $file: $!"; 356fb12b70Safresh1 # avoid PERL_UNICODE causing us to read non-UTF-8 files as UTF-8 366fb12b70Safresh1 binmode $t; 37b39c5158Smillert my $contents = <$t>; 38*de8cc8edSafresh1 # Don't 'use' Test::* modules under 't/' -- 39*de8cc8edSafresh1 # but exclude this file from that test. 40*de8cc8edSafresh1 unlike( 41*de8cc8edSafresh1 $contents, 42*de8cc8edSafresh1 qr/use\s+Test::(?:Simple|More)/, 43*de8cc8edSafresh1 "$file doesn't use Test::Simple or Test::More" 44*de8cc8edSafresh1 ) unless ($file =~ m|porting/test_bootstrap\.t|); 45b39c5158Smillert next unless $file =~ m!^base/! or $file =~ m!^comp!; 46b39c5158Smillert 47b39c5158Smillert # Remove only the excepted constructions for the specific files. 48b39c5158Smillert if ($file =~ m!comp/(.*)\.t! && $exceptions{$1}) { 49b39c5158Smillert my $allowed = $exceptions{$1}; 50b39c5158Smillert $contents =~ s/\Q$allowed//gs; 51b39c5158Smillert } 52b39c5158Smillert 53b39c5158Smillert # All uses of use are allowed in t/comp/use.t 54b39c5158Smillert unlike($contents, qr/^\s*use\s+/m, "$file doesn't use use") 55b39c5158Smillert unless $file eq 'comp/use.t'; 56b39c5158Smillert # All uses of require are allowed in t/comp/require.t 57b39c5158Smillert unlike($contents, qr/^\s*require\s+/m, "$file doesn't use require") 58b39c5158Smillert unless $file eq 'comp/require.t' 59b39c5158Smillert} 60898184e3Ssthen 6191f110e0Safresh1# There are regression tests using test.pl that don't want PL_sawampersand 6291f110e0Safresh1# set. Or at least that was the case until PL_sawampersand was disabled 6391f110e0Safresh1# and replaced with copy-on-write. 6491f110e0Safresh1 6591f110e0Safresh1# We still allow PL_sawampersand to be enabled with 666fb12b70Safresh1# -Accflags=-DPERL_SAWAMPERSAND, or with -DPERL_NO_COW, so its still worth 676fb12b70Safresh1# checking. 686fb12b70Safresh1# There's no portable, reliable way to check whether PL_sawampersand is 696fb12b70Safresh1# set, so instead we just "grep $`|$&|$' test.pl" 7091f110e0Safresh1 716fb12b70Safresh1{ 726fb12b70Safresh1 my $file = ''; 736fb12b70Safresh1 my $fh; 746fb12b70Safresh1 if (ok(open(my $fh, '<', 'test.pl'), "opened test.pl")) { 756fb12b70Safresh1 $file = do { local $/; <$fh> }; 766fb12b70Safresh1 $file //= ''; 776fb12b70Safresh1 } 786fb12b70Safresh1 else { 796fb12b70Safresh1 diag("error: $!"); 806fb12b70Safresh1 } 816fb12b70Safresh1 ok(length($file) > 0, "read test.pl successfully"); 826fb12b70Safresh1 ok($file !~ /\$&/, 'Nothing in test.pl mentioned $&'); 836fb12b70Safresh1 ok($file !~ /\$`/, 'Nothing in test.pl mentioned $`'); 846fb12b70Safresh1 ok($file !~ /\$'/, 'Nothing in test.pl mentioned $\''); 856fb12b70Safresh1} 86