Get rid of Package::Stash \o/
[dbsrgits/DBIx-Class.git] / t / 36double_destroy.t
CommitLineData
c40b5744 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3use strict;
4use warnings;
5
6use Test::More;
7use File::Temp ();
8
9use DBICTest::Util 'tmpdir';
10use DBIx::Class::_Util 'scope_guard';
11
12use DBICTest;
13
14open(my $stderr_copy, '>&', *STDERR) or die "Unable to dup STDERR: $!";
15my $tf = File::Temp->new( UNLINK => 1, DIR => tmpdir() );
16
17my $output;
18
19# ensure Devel::StackTrace-refcapture-like effects are countered
20{
21 my $s = DBICTest::Schema->connect('dbi:SQLite::memory:');
22 my $g = $s->txn_scope_guard;
23
24 my @arg_capture;
25 {
26 local $SIG{__WARN__} = sub {
27 package DB;
28 my $frnum;
29 while (my @f = CORE::caller(++$frnum) ) {
30 push @arg_capture, @DB::args;
31 }
32 };
33
34 undef $g;
35 1;
36 }
37
38 my $guard = scope_guard {
39 close STDERR;
40 open(STDERR, '>&', $stderr_copy);
41 $output = do { local (@ARGV, $/) = $tf; <> };
42 close $tf;
43 unlink $tf;
44 undef $tf;
45 close $stderr_copy;
46 };
47
48 close STDERR;
49 open(STDERR, '>&', $tf) or die "Unable to reopen STDERR: $!";
50
51 # this should emit on stderr
52 @arg_capture = ();
53}
54
55like(
56 $output,
57 qr/\QPreventing *MULTIPLE* DESTROY() invocations on DBIx::Class::Storage::TxnScopeGuard/,
58 'Proper warning emitted on STDERR'
59);
60
61done_testing;