xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/comp/hints.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate# Tests the scoping of $^H and %^H
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gateBEGIN {
6*0Sstevel@tonic-gate    chdir 't' if -d 't';
7*0Sstevel@tonic-gate    @INC = qw(. ../lib);
8*0Sstevel@tonic-gate}
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gateBEGIN { print "1..15\n"; }
12*0Sstevel@tonic-gateBEGIN {
13*0Sstevel@tonic-gate    print "not " if exists $^H{foo};
14*0Sstevel@tonic-gate    print "ok 1 - \$^H{foo} doesn't exist initially\n";
15*0Sstevel@tonic-gate    print "not " if $^H & 0x00020000;
16*0Sstevel@tonic-gate    print "ok 2 - \$^H doesn't contain HINT_LOCALIZE_HH initially\n";
17*0Sstevel@tonic-gate}
18*0Sstevel@tonic-gate{
19*0Sstevel@tonic-gate    # simulate a pragma -- don't forget HINT_LOCALIZE_HH
20*0Sstevel@tonic-gate    BEGIN { $^H |= 0x00020000; $^H{foo} = "a"; }
21*0Sstevel@tonic-gate    BEGIN {
22*0Sstevel@tonic-gate	print "not " if $^H{foo} ne "a";
23*0Sstevel@tonic-gate	print "ok 3 - \$^H{foo} is now 'a'\n";
24*0Sstevel@tonic-gate	print "not " unless $^H & 0x00020000;
25*0Sstevel@tonic-gate	print "ok 4 - \$^H contains HINT_LOCALIZE_HH while compiling\n";
26*0Sstevel@tonic-gate    }
27*0Sstevel@tonic-gate    {
28*0Sstevel@tonic-gate	BEGIN { $^H |= 0x00020000; $^H{foo} = "b"; }
29*0Sstevel@tonic-gate	BEGIN {
30*0Sstevel@tonic-gate	    print "not " if $^H{foo} ne "b";
31*0Sstevel@tonic-gate	    print "ok 5 - \$^H{foo} is now 'b'\n";
32*0Sstevel@tonic-gate	}
33*0Sstevel@tonic-gate    }
34*0Sstevel@tonic-gate    BEGIN {
35*0Sstevel@tonic-gate	print "not " if $^H{foo} ne "a";
36*0Sstevel@tonic-gate	print "ok 6 - \$H^{foo} restored to 'a'\n";
37*0Sstevel@tonic-gate    }
38*0Sstevel@tonic-gate    # The pragma settings disappear after compilation
39*0Sstevel@tonic-gate    # (test at CHECK-time and at run-time)
40*0Sstevel@tonic-gate    CHECK {
41*0Sstevel@tonic-gate	print "not " if exists $^H{foo};
42*0Sstevel@tonic-gate	print "ok 9 - \$^H{foo} doesn't exist when compilation complete\n";
43*0Sstevel@tonic-gate	print "not " if $^H & 0x00020000;
44*0Sstevel@tonic-gate	print "ok 10 - \$^H doesn't contain HINT_LOCALIZE_HH when compilation complete\n";
45*0Sstevel@tonic-gate    }
46*0Sstevel@tonic-gate    print "not " if exists $^H{foo};
47*0Sstevel@tonic-gate    print "ok 11 - \$^H{foo} doesn't exist at runtime\n";
48*0Sstevel@tonic-gate    print "not " if $^H & 0x00020000;
49*0Sstevel@tonic-gate    print "ok 12 - \$^H doesn't contain HINT_LOCALIZE_HH at run-time\n";
50*0Sstevel@tonic-gate    # op_entereval should keep the pragmas it was compiled with
51*0Sstevel@tonic-gate    eval q*
52*0Sstevel@tonic-gate	print "not " if $^H{foo} ne "a";
53*0Sstevel@tonic-gate	print "ok 13 - \$^H{foo} is 'a' at eval-\"\" time # TODO\n";
54*0Sstevel@tonic-gate	print "not " unless $^H & 0x00020000;
55*0Sstevel@tonic-gate	print "ok 14 - \$^H contains HINT_LOCALIZE_HH at eval\"\"-time\n";
56*0Sstevel@tonic-gate    *;
57*0Sstevel@tonic-gate}
58*0Sstevel@tonic-gateBEGIN {
59*0Sstevel@tonic-gate    print "not " if exists $^H{foo};
60*0Sstevel@tonic-gate    print "ok 7 - \$^H{foo} doesn't exist while finishing compilation\n";
61*0Sstevel@tonic-gate    print "not " if $^H & 0x00020000;
62*0Sstevel@tonic-gate    print "ok 8 - \$^H doesn't contain HINT_LOCALIZE_HH while finishing compilation\n";
63*0Sstevel@tonic-gate}
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gaterequire 'test.pl';
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate# bug #27040: hints hash was being double-freed
68*0Sstevel@tonic-gatemy $result = runperl(
69*0Sstevel@tonic-gate    prog => '$^H |= 0x20000; eval q{BEGIN { $^H |= 0x20000 }}',
70*0Sstevel@tonic-gate    stderr => 1
71*0Sstevel@tonic-gate);
72*0Sstevel@tonic-gateprint "not " if length $result;
73*0Sstevel@tonic-gateprint "ok 15 - double-freeing hints hash\n";
74*0Sstevel@tonic-gateprint "# got: $result\n" if length $result;
75*0Sstevel@tonic-gate
76