Commit | Line | Data |
c40b5744 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | use File::Temp (); |
8 | |
9 | use DBICTest::Util 'tmpdir'; |
10 | use DBIx::Class::_Util 'scope_guard'; |
11 | |
12 | use DBICTest; |
13 | |
14 | open(my $stderr_copy, '>&', *STDERR) or die "Unable to dup STDERR: $!"; |
15 | my $tf = File::Temp->new( UNLINK => 1, DIR => tmpdir() ); |
16 | |
17 | my $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 | |
55 | like( |
56 | $output, |
57 | qr/\QPreventing *MULTIPLE* DESTROY() invocations on DBIx::Class::Storage::TxnScopeGuard/, |
58 | 'Proper warning emitted on STDERR' |
59 | ); |
60 | |
61 | done_testing; |