Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert cleanly dynamic_methods.t, user_agent_socks.t, websocket.t to use subtests #1520 #1596

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions t/mojo/dynamic_methods.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ 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';
subtest "Basics" => sub {
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');
undef($t1);
undef($t2);
ok(!keys(%$dyn_methods), 'dynamic methods expired');
};

done_testing;
Loading