6 use blib 't/Sub-Op-LexicalSub';
8 use Test::More tests => (1 + 3) * 16 + (1 + 2 * 3) * 2 + 2 * 29;
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 ok !exists &main::${name}, '$name: not stubbed';
58 ok !defined &main::${name}, '$name: body not defined';
59 is *main::${name}\{CODE\}, undef, '$name: empty symbol table entry';
68 fail "@names: unable to evaluate test case: $@";
72 is $called, $calls, "@names: the hook was called the right number of times";
73 if ($called < $calls) {
74 fail, fail for $called + 1 .. $calls;
103 wut # () # [ ], [ 1 ], [ 2, 3 ]
107 qux # @_ # [ 1 ], [ 1 ]
109 wat 1, wat, 2, wat(3, 4), 5
111 wat # @_ # [ ], [ 3, 4 ], [ 1, 2, 3, 4, 5 ]
113 sum sum sum(1, 2), sum(3, 4)
115 sum # do { my $s = 0; $s += $_ for @_; $s } # [ 1, 2 ], [ 3, 4 ], [ 3, 7 ], [ 10 ]
127 fetch 1, do { no strict 'refs'; *{__PACKAGE__.'::fetch'}{CODE} }, 2
129 fetch # () # [ 1, undef, 2 ]
133 $cb = do { no strict 'refs'; \&{__PACKAGE__.'::cvref'} };
135 $err = $@ =~ /^Undefined subroutine &main::cvref/ ? undef : $@;
139 cvref # () # [ undef ]
149 array # () # [ 2, 3 ]
151 our %hash = (x => 4);
159 foo, bar # () # [ 1 ], [ 2 ] # foo, bar
161 foo 1, foo(2), 3, bar(4, foo(bar, 5), 6);
163 foo, bar # @_ # [ 2 ], [ ], [ 5 ], [ 4, 5, 6 ], [ 1, 2, 3, 4, 5, 6 ] # foo, bar, foo, bar, foo