6 use blib 't/Sub-Op-LexicalSub';
8 use Test::More tests => 2 * ((2 + 2) * 4 + (1 + 2) * 5) + (2 + 2) + 4;
11 sub foo { ok $call_foo, 'the preexistent foo was called' }
14 sub bar () { ok $call_bar, 'the preexistent bar was called' }
26 my ($code, $params) = split /----\s*/, $_;
27 my ($names, $ret, $exp, $seq) = split /\s*#\s*/, $params;
29 my @names = split /\s*,\s*/, $names;
33 fail "@names: unable to get expected values: $@";
40 s/^\s*//, s/\s*$// for $seq;
41 @seq = split /\s*,\s*/, $seq;
42 die "calls and seq length mismatch" unless @seq == $calls;
44 @seq = ($names[0]) x $calls;
48 for my $name (@names) {
50 use Sub::Op::LexicalSub $name => sub {
52 my \$exp = shift \@exp;
53 is_deeply \\\@_, \$exp, '$name: arguments are correct';
54 my \$seq = shift \@seq;
55 is \$seq, '$name', '$name: sequence is correct';
60 $test .= "{\n$code\n}\n";
62 for my $name (grep +{ map +($_, 1), qw/foo bar/ }->{ $_ }, @names) {
63 $test .= <<" CHECK_SUB"
65 local \$call_$name = 1;
75 fail "@names: unable to evaluate test case: $@";
79 is $called, $calls, "@names: the hook was called the right number of times";
80 if ($called < $calls) {
81 fail, fail for $called + 1 .. $calls;
86 is prototype('main::foo'), undef, "foo's prototype was preserved";
87 is prototype('main::bar'), '', "bar's prototype was preserved";
88 is prototype('main::X'), '', "X's prototype was preserved";
89 ok Sub::Op::_constant_sub(do { no strict "refs"; \&{"main::X"} }),
90 'X is still a constant';
179 is X, 2, 'constant overriding';