Skip to content

Commit a66d559

Browse files
committed
Small refactoring in --test
1 parent c5e4ca5 commit a66d559

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

lib/Zonemaster/CLI.pm

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -630,27 +630,21 @@ sub run {
630630
# Actually run tests!
631631
eval {
632632
if ( $self->test and @{ $self->test } > 0 ) {
633-
my $zone = Zonemaster::Engine->zone( $domain );
634633
foreach my $t ( @{ $self->test } ) {
635634
# The case does not matter
636635
$t = lc( $t );
637-
# Fully qualified module and test case (e.g. Example/example12)
638-
if (my ($module, $method) = $t =~ m#^ ( [a-z]+ ) / ( [a-z]+[0-9]{2} ) $#ix) {
636+
# Fully qualified module and test case (e.g. Example/example12), or just a test case (e.g. example12). Note the different capturing order.
637+
my ( $module, $method );
638+
if ( ( ($module, $method) = $t =~ m#^ ( [a-z]+ ) / ( [a-z]+[0-9]{2} ) $#ix )
639+
or
640+
( ($method, $module) = $t =~ m#^ ( ( [a-z]+ ) [0-9]{2} ) $#ix ) )
641+
{
639642
if ( not grep( /^$method$/, @{ Zonemaster::Engine::Profile->effective->get( 'test_cases' ) } ) ) {
640643
say $fh_diag __x( "Notice: Engine does not have test case '$method' enabled in the profile. Forcing...");
641644
Zonemaster::Engine::Profile->effective->set( 'test_cases', [ "$method" ] );
642645
}
643646

644-
Zonemaster::Engine->test_method( $module, $method, $zone );
645-
}
646-
# Just a test case (e.g. example12). Note the different capturing order.
647-
elsif (($method, $module) = $t =~ m#^ ( ( [a-z]+ ) [0-9]{2} ) $#ix) {
648-
if ( not grep( /^$method$/, @{ Zonemaster::Engine::Profile->effective->get( 'test_cases' ) } ) ) {
649-
say $fh_diag __x( "Notice: Engine does not have test case '$method' enabled in the profile. Forcing...");
650-
Zonemaster::Engine::Profile->effective->set( 'test_cases', [ "$method" ] );
651-
}
652-
653-
Zonemaster::Engine->test_method( $module, $method, $zone );
647+
Zonemaster::Engine->test_method( $module, $method, $domain );
654648
}
655649
# Just a module name (e.g. Example) or something invalid.
656650
# TODO: in case of invalid input, print a proper error message

0 commit comments

Comments
 (0)