Move a number of tests to xt, restructure extra lists
[dbsrgits/DBIx-Class.git] / xt / extra / internals / quote_sub.t
CommitLineData
7f9a3f70 1use warnings;
2use strict;
3
4use Test::More;
5use Test::Warn;
6
7use DBIx::Class::_Util 'quote_sub';
8
9my $q = do {
10 no strict 'vars';
11 quote_sub '$x = $x . "buh"; $x += 42';
12};
13
14warnings_exist {
15 is $q->(), 42, 'Expected result after uninit and string/num conversion'
16} [
17 qr/Use of uninitialized value/i,
18 qr/isn't numeric in addition/,
19], 'Expected warnings, strict did not leak inside the qsub'
20 or do {
21 require B::Deparse;
22 diag( B::Deparse->new->coderef2text( Sub::Quote::unquote_sub($q) ) )
23 }
24;
25
26my $no_nothing_q = do {
27 no strict;
28 no warnings;
29 quote_sub <<'EOC';
c480ff4a 30 BEGIN { warn "-->${^WARNING_BITS}<--\n" };
7f9a3f70 31 my $n = "Test::Warn::warnings_exist";
32 warn "-->@{[ *{$n}{CODE} ]}<--\n";
7f9a3f70 33EOC
34};
35
36my $we_cref = Test::Warn->can('warnings_exist');
37
38warnings_exist { $no_nothing_q->() } [
c480ff4a 39 qr/^\-\-\>\0+\<\-\-$/m,
7f9a3f70 40 qr/^\Q-->$we_cref<--\E$/m,
7f9a3f70 41], 'Expected warnings, strict did not leak inside the qsub'
42 or do {
43 require B::Deparse;
44 diag( B::Deparse->new->coderef2text( Sub::Quote::unquote_sub($no_nothing_q) ) )
45 }
46;
47
48done_testing;