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)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|