Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Test::More subtest parameters

by space_monk (Chaplain)
on Apr 17, 2013 at 11:43 UTC ( #1029123=note: print w/ replies, xml ) Need Help??


in reply to Re: Test::More subtest parameters
in thread Test::More subtest parameters

Thanks for the reply...

Your subtest is simply an anonymous routine which does not take any parameters. To properly illustrate what I wanted perhaps the code below will clarify....

my $xml; sub my_subtest { like( $xml, qr/xml version=/, "XML Document"); # more tests on XML document text here.... } $xml = MyPackage::method1(); subtest 'Checking XML from method1' => \&my_subtest; $xml = MyPackage::method2(); subtest 'Checking XML from method2...' => \&my_subtest;
I would like to pass $xml as a variable (plus other test parameters) to the subtest. I think the original fudge poster was close as it looks as though having a "fudge wrapper" is the only way this can be achieved. I did wonder if there was a more direct method or whether subtest passed on additional params to "my_subtest".
If any of my proposed solutions have minor errors, it's because I don't waste my genius on trivial matters. :-P


Comment on Re^2: Test::More subtest parameters
Download Code
Re^3: Test::More subtest parameters
by choroba (Canon) on Apr 17, 2013 at 12:17 UTC
    Anonymous subs to the rescue:
    #!/usr/bin/perl use warnings; use strict; { package MyPackage; sub method1 { '<?xml version="1.0"?>' } sub method2 { '[?xml version="2.0"?][a][/a]' } } use Test::More; sub my_subtest { like( shift, qr/xml version=/, "XML Document"); # more tests on XML document text here.... } for my $method (qw/method1 method2/) { subtest "Checking $method" => sub { my_subtest(MyPackage->$method) + }; }
    Update: Unfortunately, I am not able to use a sub returning a sub as in
    sub new_test { my ($test, $method) = @_; return sub { $test->(MyPackage->$method) }; } for my $method (qw/method1 method2/) { subtest "Checking $method", new_test(\&my_subtest, $method); }

    I am getting

    Type of arg 2 to Test::More::subtest must be sub {} (not subroutine en +try)
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029123]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2015-07-06 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls