6 use blib 't/Sub-Op-LexicalSub';
8 use Test::More tests => 2 * ((1 + 2) * 4 + (1 + 1) * 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";
66 fail "@names: unable to evaluate test case: $@";
70 is $called, $calls, "@names: the hook was called the right number of times";
71 if ($called < $calls) {
72 fail, fail for $called + 1 .. $calls;
77 is prototype('main::foo'), undef, "foo's prototype was preserved";
78 is prototype('main::bar'), '', "bar's prototype was preserved";
79 is prototype('main::X'), '', "X's prototype was preserved";
80 ok Sub::Op::_constant_sub(do { no strict "refs"; \&{"main::X"} }),
81 'X is still a constant';
170 is X, 2, 'constant overriding';