t/95-portability-files.t
t/99-kwalitee.t
t/lib/Variable/Magic/TestDestroyRequired.pm
+t/lib/Variable/Magic/TestGlobalDestruction.pm
t/lib/Variable/Magic/TestScopeEnd.pm
t/lib/Variable/Magic/TestThreads.pm
t/lib/Variable/Magic/TestValue.pm
use Variable::Magic qw<wizard cast dispell getdata>;
+use lib 't/lib';
+use Variable::Magic::TestGlobalDestruction;
+
my $c = 0;
{
BEGIN { require Variable::Magic::TestDestroyRequired; }
];
is $@, '', 'wizard destruction at the end of BEGIN-time require doesn\'t panic';
-
-if ((defined $ENV{PERL_DESTRUCT_LEVEL} and $ENV{PERL_DESTRUCT_LEVEL} >= 3)
- or eval "use Perl::Destruct::Level level => 3; 1") {
- diag 'Test global destruction';
-}
--- /dev/null
+package Variable::Magic::TestGlobalDestruction;
+
+use strict;
+use warnings;
+
+# Silence possible 'used only once' warnings from Test::Builder
+our $TODO;
+local $TODO;
+
+sub _diag {
+ require Test::More;
+ Test::More::diag(@_);
+}
+
+sub import {
+ shift;
+ my %args = @_;
+ my $level = $args{level} || 1;
+
+ my $env_level = int($ENV{PERL_DESTRUCT_LEVEL} || 0);
+ if ($env_level >= $level) {
+ my $is_debugging = do {
+ local $@;
+ eval {
+ require Config;
+ grep /-DDEBUGGING\b/, @Config::Config{qw<ccflags cppflags optimize>};
+ }
+ };
+ require Test::More;
+ if ($is_debugging) {
+ _diag("Global destruction level $env_level set by PERL_DESTRUCT_LEVEL (debugging perl)");
+ return;
+ } else {
+ _diag("PERL_DESTRUCT_LEVEL is set to $env_level, but this perl doesn't seem to have debugging enabled");
+ }
+ }
+
+ my $has_perl_destruct_level = do {
+ local $@;
+ eval {
+ require Perl::Destruct::Level;
+ Perl::Destruct::Level->import(level => $level);
+ 1;
+ }
+ };
+ if ($has_perl_destruct_level) {
+ _diag("Global destruction level $level set by Perl::Destruct::Level");
+ return;
+ }
+}
+
+1;