This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_hv_placeholders_get() actually takes a const HV *hv.
[perl5.git] / lib / strict.t
1 #!./perl 
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     $ENV{PERL5LIB} = '../lib';
7     require './test.pl';
8 }
9
10 $| = 1;
11
12 my $Is_VMS = $^O eq 'VMS';
13 my $Is_MSWin32 = $^O eq 'MSWin32';
14 my $Is_NetWare = $^O eq 'NetWare';
15 my $i = 0 ;
16
17 my @prgs = () ;
18
19 foreach (sort glob($^O eq 'MacOS' ? ":lib:strict:*" : "lib/strict/*")) {
20
21     next if -d || /(~|\.orig|,v)$/;
22
23     open F, "<$_" or die "Cannot open $_: $!\n" ;
24     while (<F>) {
25         last if /^__END__/ ;
26     }
27
28     {
29         local $/ = undef;
30         @prgs = (@prgs, split "\n########\n", <F>) ;
31     }
32     close F or die "Could not close: $!" ;
33 }
34
35 undef $/;
36
37 print "1.." . (@prgs + 4) . "\n";
38  
39  
40 for (@prgs){
41     my $switch = "";
42     my @temps = () ;
43     if (s/^\s*-\w+//){
44         $switch = $&;
45     }
46     my($prog,$expected) = split(/\nEXPECT\n/, $_);
47     if ( $prog =~ /--FILE--/) {
48         my(@files) = split(/\n--FILE--\s*([^\s\n]*)\s*\n/, $prog) ;
49         shift @files ;
50         die "Internal error test $i didn't split into pairs, got " . 
51                 scalar(@files) . "[" . join("%%%%", @files) ."]\n"
52             if @files % 2 ;
53         while (@files > 2) {
54             my $filename = shift @files ;
55             my $code = shift @files ;
56             $code =~ s|\./abc|:abc|g if $^O eq 'MacOS';
57             push @temps, $filename ;
58             open F, ">$filename" or die "Cannot open $filename: $!\n" ;
59             print F $code ;
60             close F or die "Could not close: $!" ;
61         }
62         shift @files ;
63         $prog = shift @files ;
64         $prog =~ s|\./abc|:abc|g if $^O eq 'MacOS';
65     }
66     my $tmpfile = tempfile();
67     open TEST, ">$tmpfile" or die "Could not open: $!";
68     print TEST $prog,"\n";
69     close TEST or die "Could not close: $!";
70     my $results = $Is_MSWin32 ?
71                       `.\\perl -I../lib $switch $tmpfile 2>&1` :
72                   $^O eq 'NetWare' ?
73                       `perl -I../lib $switch $tmpfile 2>&1` :
74                   $^O eq 'MacOS' ?
75                       `$^X -I::lib -MMac::err=unix $switch $tmpfile` :
76                   `$^X $switch $tmpfile 2>&1`;
77     my $status = $?;
78     $results =~ s/\n+$//;
79     # allow expected output to be written as if $prog is on STDIN
80     $results =~ s/tmp\d+[A-Z][A-Z]?/-/g;
81     $results =~ s/\n%[A-Z]+-[SIWEF]-.*$// if $Is_VMS;  # clip off DCL status msg
82     $expected =~ s/\n+$//;
83     $expected =~ s|(\./)?abc\.pm|:abc.pm|g if $^O eq 'MacOS';
84     $expected =~ s|./abc|:abc|g if $^O eq 'MacOS';
85     my $prefix = ($results =~ s/^PREFIX\n//) ;
86     my $TODO = $prog =~ m/^#\s*TODO:/;
87     if ( $results =~ s/^SKIPPED\n//) {
88         print "$results\n" ;
89     }
90     elsif (($prefix and $results !~ /^\Q$expected/) or
91            (!$prefix and $results ne $expected)){
92         if (! $TODO) {
93             print STDERR "PROG: $switch\n$prog\n";
94             print STDERR "EXPECTED:\n$expected\n";
95             print STDERR "GOT:\n$results\n";
96         }
97         print "not ";
98     }
99     print "ok " . ++$i . ($TODO ? " # TODO" : "") . "\n";
100     foreach (@temps) 
101         { unlink $_ if $_ } 
102 }
103
104 eval qq(use strict 'garbage');
105 print +($@ =~ /^Unknown 'strict' tag\(s\) 'garbage'/)
106         ? "ok ".++$i."\n" : "not ok ".++$i."\t# $@";
107
108 eval qq(no strict 'garbage');
109 print +($@ =~ /^Unknown 'strict' tag\(s\) 'garbage'/)
110         ? "ok ".++$i."\n" : "not ok ".++$i."\t# $@";
111
112 eval qq(use strict qw(foo bar));
113 print +($@ =~ /^Unknown 'strict' tag\(s\) 'foo bar'/)
114         ? "ok ".++$i."\n" : "not ok ".++$i."\t# $@";
115
116 eval qq(no strict qw(foo bar));
117 print +($@ =~ /^Unknown 'strict' tag\(s\) 'foo bar'/)
118         ? "ok ".++$i."\n" : "not ok ".++$i."\t# $@";