From 79444e781d34a13fc4fdf25818d2905b0a96a1c4 Mon Sep 17 00:00:00 2001 From: Michal Schwarz Date: Tue, 2 Aug 2022 14:25:24 +0200 Subject: [PATCH] Convert t/mojo/dynamic_methods.t to use subtests --- t/mojo/dynamic_methods.t | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/t/mojo/dynamic_methods.t b/t/mojo/dynamic_methods.t index 5af74c80c7..2a9ab288ba 100644 --- a/t/mojo/dynamic_methods.t +++ b/t/mojo/dynamic_methods.t @@ -23,21 +23,25 @@ sub BUILD_DYNAMIC { package main; -# Basics my ($t1, $t2) = (Mojo::TestDynamic->new, Mojo::TestDynamic->new); -Mojo::DynamicMethods::register 'Mojo::TestDynamic', $t1->hashref, 'foo', sub { }; -my $foo = \&Mojo::TestDynamic::_Dynamic::foo; -my ($called_foo, $dyn_methods); -Mojo::DynamicMethods::register 'Mojo::TestDynamic', $t1->hashref, 'foo', sub { $called_foo++; $dyn_methods = $_[1] }; -is $foo, \&Mojo::TestDynamic::_Dynamic::foo, 'foo not reinstalled'; -ok !Mojo::TestDynamic->can('foo'), 'dynamic method is hidden'; -ok eval { $t1->foo; 1 }, 'foo called ok'; -cmp_ok $called_foo, '==', 1, 'called dynamic method'; -ok !eval { $t2->foo; 1 }, 'error calling foo on wrong object'; - -# Garbage collection -undef($t1); -undef($t2); -ok(!keys(%$dyn_methods), 'dynamic methods expired'); +my ($dyn_methods); + +subtest 'Basics' => sub { + Mojo::DynamicMethods::register 'Mojo::TestDynamic', $t1->hashref, 'foo', sub { }; + my $foo = \&Mojo::TestDynamic::_Dynamic::foo; + my ($called_foo, $dyn_methods); + Mojo::DynamicMethods::register 'Mojo::TestDynamic', $t1->hashref, 'foo', sub { $called_foo++; $dyn_methods = $_[1] }; + is $foo, \&Mojo::TestDynamic::_Dynamic::foo, 'foo not reinstalled'; + ok !Mojo::TestDynamic->can('foo'), 'dynamic method is hidden'; + ok eval { $t1->foo; 1 }, 'foo called ok'; + cmp_ok $called_foo, '==', 1, 'called dynamic method'; + ok !eval { $t2->foo; 1 }, 'error calling foo on wrong object'; +}; + +subtest 'Garbage collection' => sub { + undef($t1); + undef($t2); + ok(!keys(%$dyn_methods), 'dynamic methods expired'); +}; done_testing;