]> git.vpit.fr Git - perl/modules/re-engine-Hooks.git/blob - t/11-call-perl.t
Update VPIT::TestHelpers to 15e8aee3
[perl/modules/re-engine-Hooks.git] / t / 11-call-perl.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use blib 't/re-engine-Hooks-TestDist';
7
8 use Test::More tests => 2 * 2;
9
10 # Those tests must be ran inside eval STRING because the test distribution
11 # can hold only one callback at a time.
12
13 my @nodes;
14
15 eval <<'TEST1';
16 my $rx = do {
17  use re::engine::Hooks::TestDist 'custom' => sub { push @nodes, @_ };
18  qr/.(?:a|o).*/;
19 };
20
21 {
22  local $@;
23  eval {
24   "foo" =~ $rx;
25  };
26  is $@, '', 'calling perl code in the exec hook does not croak';
27  is_deeply \@nodes, [ qw<REG_ANY TRIE STAR END> ],
28             'calling perl code in the exec hook works correctly';
29 }
30 TEST1
31 die $@ if $@;
32
33 eval <<'TEST2';
34 my $res;
35
36 my $rx = do {
37  use re::engine::Hooks::TestDist 'custom' => sub { $res += ("durp" =~ /.urp/) };
38  qr/.(?:a|o).*/;
39 };
40
41 {
42  local $@;
43  eval {
44   "foo" =~ $rx;
45  };
46  is $@, '', 'a regexp match in the exec hook does not croak';
47  is $res, scalar(@nodes), 'a regexp match in the exec hook works correctly';
48 }
49 TEST2
50 die $@ if $@;