+my $vm_tse_file = 't/lib/Variable/Magic/TestScopeEnd.pm';
+
+eval "use Variable::Magic::TestScopeEnd";
+like $@, expect('turnip', $vm_tse_file, "\nBEGIN(?s:.*)"),
+ 'die in BEGIN in require in eval string triggers hints hash destructor';
+
+eval q{BEGIN {
+ Variable::Magic::TestScopeEnd::hook {
+ pass 'in hints hash destructor 2';
+ };
+ die "tomato";
+}};
+
+like $@, expect('tomato', undef, "\nBEGIN.*"),
+ 'die in BEGIN in eval triggers hints hash destructor';
+
+sub run_perl {
+ my $code = shift;
+
+ my ($SystemRoot, $PATH) = @ENV{qw<SystemRoot PATH>};
+ local %ENV;
+ $ENV{SystemRoot} = $SystemRoot if $^O eq 'MSWin32' and defined $SystemRoot;
+ $ENV{PATH} = $PATH if $^O eq 'cygwin' and defined $PATH;
+
+ system { $^X } $^X, '-T', map("-I$_", @INC), '-e', $code;
+}
+
+my $has_capture_tiny = do {
+ local $@;
+ eval 'use Capture::Tiny 0.08 (); 1'
+};
+if ($has_capture_tiny) {
+ my $output = Capture::Tiny::capture_merged(sub { run_perl <<' CODE' });
+print STDOUT "pants\n";
+print STDERR "trousers\n";
+ CODE
+ unless (defined $output and $output =~ /pants/ and $output =~ /trousers/) {
+ $has_capture_tiny = 0;
+ }
+}
+if ($has_capture_tiny) {
+ defined and diag "Using Capture::Tiny $_" for $Capture::Tiny::VERSION;
+}
+
+SKIP:
+{
+ my $count = 1;
+
+ skip 'No working Capture::Tiny is installed'=> $count unless $has_capture_tiny;
+
+ my $output = Capture::Tiny::capture_merged(sub { run_perl <<' CODE' });
+use Variable::Magic qw<wizard cast>; { BEGIN { $^H |= 0x020000; cast %^H, wizard free => sub { die q[cucumber] } } }
+ CODE
+ skip 'Test code didn\'t run properly' => $count unless defined $output;
+ like $output, expect('cucumber', '-e', "\nExecution(?s:.*)"),
+ 'die in free callback at compile time and not in eval string';
+ --$count;
+}
+
+# Uvar
+
+SKIP:
+{
+ my $count = 1;
+
+ skip 'No nice uvar magic for this perl' => $count unless VMG_UVAR;
+ skip 'No working Capture::Tiny is installed'=> $count unless $has_capture_tiny;
+
+ my $output = Capture::Tiny::capture_merged(sub { run_perl <<' CODE' });
+use Variable::Magic qw<wizard cast>; BEGIN { cast %::, wizard fetch => sub { die q[salsify] } } hlagh()
+ CODE
+ skip 'Test code didn\'t run properly' => $count unless defined $output;
+ my $suffix = "\nExecution(?s:.*)";
+ if ("$]" >= 5.017) {
+ $suffix = "(?:\nsalsify at -e line \\d+.){16}" . $suffix;
+ } elsif ("$]" >= 5.011_005) {
+ $suffix = "(?:\nsalsify at -e line \\d+.){12}" . $suffix;
+ } elsif ("$]" >= 5.011) {
+ $suffix = "(?:\nsalsify at -e line \\d+.){3}" . $suffix;
+ }
+ like $output, expect('salsify', '-e', $suffix),
+ 'die in free callback at compile time and not in eval string';
+ --$count;
+}