1#!perl -w 2BEGIN { 3 # Hush the used only once warning. 4 no warnings 'once'; 5 $XS::APItest::WARNINGS_ON_BOOTSTRAP = 1; 6} 7 8use strict; 9use warnings; 10use Test::More tests => 103; 11 12# Doing this longhand cut&paste makes it clear 13# BEGIN and INIT are FIFO, CHECK and END are LIFO 14BEGIN { 15 print "# First BEGIN\n"; 16 is($XS::APItest::BEGIN_called, undef, "BEGIN not yet called"); 17 is($XS::APItest::BEGIN_called_PP, undef, "BEGIN not yet called"); 18 is($XS::APItest::UNITCHECK_called, undef, "UNITCHECK not yet called"); 19 is($XS::APItest::UNITCHECK_called_PP, undef, "UNITCHECK not called"); 20 is($XS::APItest::CHECK_called, undef, "CHECK not called"); 21 is($XS::APItest::CHECK_called_PP, undef, "CHECK not called"); 22 is($XS::APItest::INIT_called, undef, "INIT not called"); 23 is($XS::APItest::INIT_called_PP, undef, "INIT not called"); 24 is($XS::APItest::END_called, undef, "END not yet called"); 25 is($XS::APItest::END_called_PP, undef, "END not yet called"); 26} 27 28CHECK { 29 print "# First CHECK\n"; 30 is($XS::APItest::BEGIN_called, undef, "BEGIN not yet called"); 31 is($XS::APItest::BEGIN_called_PP, undef, "BEGIN not yet called"); 32 is($XS::APItest::UNITCHECK_called, undef, "UNITCHECK not yet called"); 33 is($XS::APItest::UNITCHECK_called_PP, undef, "UNITCHECK not called"); 34 is($XS::APItest::CHECK_called, undef, "CHECK not called (too late)"); 35 is($XS::APItest::CHECK_called_PP, undef, "CHECK not called (too late)"); 36 is($XS::APItest::INIT_called, undef, "INIT not called"); 37 is($XS::APItest::INIT_called_PP, undef, "INIT not called"); 38 is($XS::APItest::END_called, undef, "END not yet called"); 39 is($XS::APItest::END_called_PP, undef, "END not yet called"); 40} 41 42INIT { 43 print "# First INIT\n"; 44 is($XS::APItest::BEGIN_called, undef, "BEGIN not yet called"); 45 is($XS::APItest::BEGIN_called_PP, undef, "BEGIN not yet called"); 46 is($XS::APItest::UNITCHECK_called, undef, "UNITCHECK not yet called"); 47 is($XS::APItest::UNITCHECK_called_PP, undef, "UNITCHECK not called"); 48 is($XS::APItest::CHECK_called, undef, "CHECK not called (too late)"); 49 is($XS::APItest::CHECK_called_PP, undef, "CHECK not called (too late)"); 50 is($XS::APItest::INIT_called, undef, "INIT not called"); 51 is($XS::APItest::INIT_called_PP, undef, "INIT not called"); 52 is($XS::APItest::END_called, undef, "END not yet called"); 53 is($XS::APItest::END_called_PP, undef, "END not yet called"); 54} 55 56END { 57 print "# First END\n"; 58 is($XS::APItest::BEGIN_called, 1, "BEGIN called"); 59 is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called"); 60 is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called"); 61 is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called"); 62 is($XS::APItest::CHECK_called, undef, "CHECK not called (too late)"); 63 is($XS::APItest::CHECK_called_PP, undef, "CHECK not called (too late)"); 64 is($XS::APItest::INIT_called, undef, "INIT not called (too late)"); 65 is($XS::APItest::INIT_called_PP, undef, "INIT not called (too late)"); 66 is($XS::APItest::END_called, 1, "END called"); 67 is($XS::APItest::END_called_PP, 1, "END called"); 68} 69 70print "# First body\n"; 71is($XS::APItest::BEGIN_called, undef, "BEGIN not yet called"); 72is($XS::APItest::BEGIN_called_PP, undef, "BEGIN not yet called"); 73is($XS::APItest::UNITCHECK_called, undef, "UNITCHECK not yet called"); 74is($XS::APItest::UNITCHECK_called_PP, undef, "UNITCHECK not called"); 75is($XS::APItest::CHECK_called, undef, "CHECK not called (too late)"); 76is($XS::APItest::CHECK_called_PP, undef, "CHECK not called (too late)"); 77is($XS::APItest::INIT_called, undef, "INIT not called (too late)"); 78is($XS::APItest::INIT_called_PP, undef, "INIT not called (too late)"); 79is($XS::APItest::END_called, undef, "END not yet called"); 80is($XS::APItest::END_called_PP, undef, "END not yet called"); 81 82{ 83 my @trap; 84 local $SIG{__WARN__} = sub { push @trap, join "!", @_ }; 85 require XS::APItest; 86 87 @trap = sort @trap; 88 is(scalar @trap, 2, "There were 2 warnings"); 89 like($trap[0], qr "^Too late to run CHECK block"); 90 like($trap[1], qr "^Too late to run INIT block"); 91} 92 93print "# Second body\n"; 94is($XS::APItest::BEGIN_called, 1, "BEGIN called"); 95is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called"); 96is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called");; 97is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called"); 98is($XS::APItest::CHECK_called, undef, "CHECK not called (too late)"); 99is($XS::APItest::CHECK_called_PP, undef, "CHECK not called (too late)"); 100is($XS::APItest::INIT_called, undef, "INIT not called (too late)"); 101is($XS::APItest::INIT_called_PP, undef, "INIT not called (too late)"); 102is($XS::APItest::END_called, undef, "END not yet called"); 103is($XS::APItest::END_called_PP, undef, "END not yet called"); 104 105BEGIN { 106 print "# Second BEGIN\n"; 107 is($XS::APItest::BEGIN_called, undef, "BEGIN not yet called"); 108 is($XS::APItest::BEGIN_called_PP, undef, "BEGIN not yet called"); 109 is($XS::APItest::UNITCHECK_called, undef, "UNITCHECK not yet called"); 110 is($XS::APItest::UNITCHECK_called_PP, undef, "UNITCHECK not called"); 111 is($XS::APItest::CHECK_called, undef, "CHECK not called"); 112 is($XS::APItest::CHECK_called_PP, undef, "CHECK not called"); 113 is($XS::APItest::INIT_called, undef, "INIT not called"); 114 is($XS::APItest::INIT_called_PP, undef, "INIT not called"); 115 is($XS::APItest::END_called, undef, "END not yet called"); 116 is($XS::APItest::END_called_PP, undef, "END not yet called"); 117} 118 119CHECK { 120 print "# Second CHECK\n"; 121 is($XS::APItest::BEGIN_called, undef, "BEGIN not yet called"); 122 is($XS::APItest::BEGIN_called_PP, undef, "BEGIN not yet called"); 123 is($XS::APItest::UNITCHECK_called, undef, "UNITCHECK not yet called"); 124 is($XS::APItest::UNITCHECK_called_PP, undef, "UNITCHECK not yet called"); 125 is($XS::APItest::CHECK_called, undef, "CHECK not called"); 126 is($XS::APItest::CHECK_called_PP, undef, "CHECK not called"); 127 is($XS::APItest::INIT_called, undef, "INIT not called"); 128 is($XS::APItest::INIT_called_PP, undef, "INIT not called"); 129 is($XS::APItest::END_called, undef, "END not yet called"); 130 is($XS::APItest::END_called_PP, undef, "END not yet called"); 131} 132 133INIT { 134 print "# Second INIT\n"; 135 is($XS::APItest::BEGIN_called, undef, "BEGIN not yet called"); 136 is($XS::APItest::BEGIN_called_PP, undef, "BEGIN not yet called"); 137 is($XS::APItest::UNITCHECK_called, undef, "UNITCHECK not yet called"); 138 is($XS::APItest::UNITCHECK_called_PP, undef, "UNITCHECK not yet called"); 139 is($XS::APItest::CHECK_called, undef, "CHECK not called (too late)"); 140 is($XS::APItest::CHECK_called_PP, undef, "CHECK not called (too late)"); 141 is($XS::APItest::INIT_called, undef, "INIT not called (too late)"); 142 is($XS::APItest::INIT_called_PP, undef, "INIT not called (too late)"); 143 is($XS::APItest::END_called, undef, "END not yet called"); 144 is($XS::APItest::END_called_PP, undef, "END not yet called"); 145} 146 147END { 148 print "# Second END\n"; 149 is($XS::APItest::BEGIN_called, 1, "BEGIN called"); 150 is($XS::APItest::BEGIN_called_PP, 1, "BEGIN called"); 151 is($XS::APItest::UNITCHECK_called, 1, "UNITCHECK called"); 152 is($XS::APItest::UNITCHECK_called_PP, 1, "UNITCHECK called"); 153 is($XS::APItest::CHECK_called, undef, "CHECK not called (too late)"); 154 is($XS::APItest::CHECK_called_PP, undef, "CHECK not called (too late)"); 155 is($XS::APItest::INIT_called, undef, "INIT not called (too late)"); 156 is($XS::APItest::INIT_called_PP, undef, "INIT not called (too late)"); 157 is($XS::APItest::END_called, 1, "END called"); 158 is($XS::APItest::END_called_PP, 1, "END called"); 159} 160