neilwatson has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,

What is wrong with this code?

use Test::More; sub _test_bug_exists { my $args = shift; my $bug = get_bug( $args->{bug} ); subtest 'Lookup existing bug' => sub # this is line 241 { is( $bug->{response}, "$c->{bug_tracker}/$args->{bug}", "URL correct?" ); is( $bug->{subject}, "Variables not expanded inside array", "Subject correct?" ); } } String found where operator expected at ./cfbot.pl line 241, near "sub +test 'Lookup existing bug'" (Do you need to predeclare subtest?) syntax error at ./cfbot.pl line 241, near "subtest 'Lookup existing bu +g'" Global symbol "$bug" requires explicit package name at ./cfbot.pl line + 244. syntax error at ./cfbot.pl line 245, near "}" Illegal declaration of subroutine main::_test_bug_not_found at ./cfbot +.pl line 248.

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: subtest error using test::more
by Corion (Patriarch) on Jun 24, 2015 at 20:52 UTC

    The problem must be somewhere else because the code as you posted it compiles just fine:

    use Test::More; sub _test_bug_exists { my $args = shift; my $bug = get_bug( $args->{bug} ); subtest 'Lookup existing bug' => sub # this is line 241 { is( $bug->{response}, "$c->{bug_tracker}/$args->{bug}", "URL correct?" ); is( $bug->{subject}, "Variables not expanded inside array", "Subject correct?" ); } }
    > perl -wc tmp.pl Name "main::c" used only once: possible typo at tmp.pl line 10. tmp.pl syntax OK
Re: subtest error using test::more
by toolic (Bishop) on Jun 24, 2015 at 20:59 UTC
    I get that message if I comment out this line:
    use Test::More;

    Are you sure you have that exact line in your code?

      Turns out the code was calling Test::More using eval. One I used a normal use statement the error went away.

      Neil Watson
      watson-wilson.ca