6 use blib 't/Sub-Op-LexicalSub';
8 use Test::More tests => 2 * 15 + 3 * 2 + 2 * 28;
18 my ($code, $params) = split /----\s*/, $_;
19 my ($names, $ret, $exp, $seq) = split /\s*#\s*/, $params;
21 my @names = split /\s*,\s*/, $names;
25 fail "@names: unable to get expected values: $@";
32 s/^\s*//, s/\s*$// for $seq;
33 @seq = split /\s*,\s*/, $seq;
34 die "calls and seq length mismatch" unless @seq == $calls;
36 @seq = ($names[0]) x $calls;
40 for my $name (@names) {
42 use Sub::Op::LexicalSub $name => sub {
44 my \$exp = shift \@exp;
45 is_deeply \\\@_, \$exp, '$name: arguments are correct';
46 my \$seq = shift \@seq;
47 is \$seq, '$name', '$name: sequence is correct';
52 $test .= "{\n$code\n}\n";
53 for my $name (@names) {
54 $test .= <<" CHECK_VIVID"
56 no warnings 'uninitialized'; # Test::Builder can't get the file name
57 is *main::${name}\{CODE\}, undef, '$name: no symbol table vivification';
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 for $called + 1 .. $calls;
101 wut # () # [ ], [ 1 ], [ 2, 3 ]
105 qux # @_ # [ 1 ], [ 1 ]
107 wat 1, wat, 2, wat(3, 4), 5
109 wat # @_ # [ ], [ 3, 4 ], [ 1, 2, 3, 4, 5 ]
111 sum sum sum(1, 2), sum(3, 4)
113 sum # do { my $s = 0; $s += $_ for @_; $s } # [ 1, 2 ], [ 3, 4 ], [ 3, 7 ], [ 10 ]
125 fetch 1, do { no strict 'refs'; *{__PACKAGE__.'::fetch'}{CODE} }, 2
127 fetch # () # [ 1, undef, 2 ]
137 array # () # [ 2, 3 ]
139 our %hash = (x => 4);
147 foo, bar # () # [ 1 ], [ 2 ] # foo, bar
149 foo 1, foo(2), 3, bar(4, foo(bar, 5), 6);
151 foo, bar # @_ # [ 2 ], [ ], [ 5 ], [ 4, 5, 6 ], [ 1, 2, 3, 4, 5, 6 ] # foo, bar, foo, bar, foo