Skip to content

Commit

Permalink
test abstract methods in base classes
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 16, 2015
1 parent 7b03bcb commit cc68204
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 1 deletion.
16 changes: 16 additions & 0 deletions t/mojo/asset.t
Expand Up @@ -232,4 +232,20 @@ ok -e $path, 'file exists';
unlink $path;
ok !-e $path, 'file has been cleaned up';

# Abstract methods
eval { Mojo::Asset->add_chunk };
like $@, qr/Method "add_chunk" not implemented by subclass/, 'right error';
eval { Mojo::Asset->contains };
like $@, qr/Method "contains" not implemented by subclass/, 'right error';
eval { Mojo::Asset->get_chunk };
like $@, qr/Method "get_chunk" not implemented by subclass/, 'right error';
eval { Mojo::Asset->move_to };
like $@, qr/Method "move_to" not implemented by subclass/, 'right error';
eval { Mojo::Asset->mtime };
like $@, qr/Method "mtime" not implemented by subclass/, 'right error';
eval { Mojo::Asset->size };
like $@, qr/Method "size" not implemented by subclass/, 'right error';
eval { Mojo::Asset->slurp };
like $@, qr/Method "slurp" not implemented by subclass/, 'right error';

done_testing();
9 changes: 9 additions & 0 deletions t/mojo/content.t
Expand Up @@ -88,4 +88,13 @@ $content->parse(
"Content-Length: 18446744073709551616\x0d\x0a\x0d\x0aHello World!");
is $content->asset->size, 12, 'right size';

# Abstract methods
eval { Mojo::Content->body_contains };
like $@, qr/Method "body_contains" not implemented by subclass/, 'right error';
eval { Mojo::Content->body_size };
like $@, qr/Method "body_size" not implemented by subclass/, 'right error';
eval { Mojo::Content->get_body_chunk };
like $@, qr/Method "get_body_chunk" not implemented by subclass/,
'right error';

done_testing();
6 changes: 6 additions & 0 deletions t/mojo/cookie.t
Expand Up @@ -448,4 +448,10 @@ is $cookies->[0]->expires->epoch, 942189160, 'right expires epoch value';
is $cookies->[0]->secure, 1, 'right secure flag';
is $cookies->[1], undef, 'no more cookies';

# Abstract methods
eval { Mojo::Cookie->parse };
like $@, qr/Method "parse" not implemented by subclass/, 'right error';
eval { Mojo::Cookie->to_string };
like $@, qr/Method "to_string" not implemented by subclass/, 'right error';

done_testing();
4 changes: 4 additions & 0 deletions t/mojo/daemon.t
Expand Up @@ -271,4 +271,8 @@ ok !!Mojo::IOLoop->acceptor($id), 'acceptor has been added';
undef $daemon;
ok !Mojo::IOLoop->acceptor($id), 'acceptor has been removed';

# Abstract methods
eval { Mojo::Server->run };
like $@, qr/Method "run" not implemented by subclass/, 'right error';

done_testing();
24 changes: 24 additions & 0 deletions t/mojo/reactor_poll.t
Expand Up @@ -269,4 +269,28 @@ like $client_err, qr/^Mojo::IOLoop already running/, 'right error';
ok $server_running, 'loop is running';
ok $client_running, 'loop is running';

# Abstract methods
eval { Mojo::Reactor->again };
like $@, qr/Method "again" not implemented by subclass/, 'right error';
eval { Mojo::Reactor->io };
like $@, qr/Method "io" not implemented by subclass/, 'right error';
eval { Mojo::Reactor->is_running };
like $@, qr/Method "is_running" not implemented by subclass/, 'right error';
eval { Mojo::Reactor->one_tick };
like $@, qr/Method "one_tick" not implemented by subclass/, 'right error';
eval { Mojo::Reactor->recurring };
like $@, qr/Method "recurring" not implemented by subclass/, 'right error';
eval { Mojo::Reactor->remove };
like $@, qr/Method "remove" not implemented by subclass/, 'right error';
eval { Mojo::Reactor->reset };
like $@, qr/Method "reset" not implemented by subclass/, 'right error';
eval { Mojo::Reactor->start };
like $@, qr/Method "start" not implemented by subclass/, 'right error';
eval { Mojo::Reactor->stop };
like $@, qr/Method "stop" not implemented by subclass/, 'right error';
eval { Mojo::Reactor->timer };
like $@, qr/Method "timer" not implemented by subclass/, 'right error';
eval { Mojo::Reactor->watch };
like $@, qr/Method "watch" not implemented by subclass/, 'right error';

done_testing();
10 changes: 10 additions & 0 deletions t/mojo/request.t
Expand Up @@ -2089,4 +2089,14 @@ is $req->version, '1.1', 'right version';
is $req->url, '/#09azAZ!$%&\'()*+,-./:;=?@%5B%5C%5D%5E_%60%7B%7C%7D~',
'right URL';

# Abstract methods
eval { Mojo::Message->cookies };
like $@, qr/Method "cookies" not implemented by subclass/, 'right error';
eval { Mojo::Message->extract_start_line };
like $@, qr/Method "extract_start_line" not implemented by subclass/,
'right error';
eval { Mojo::Message->get_start_line_chunk };
like $@, qr/Method "get_start_line_chunk" not implemented by subclass/,
'right error';

done_testing();
10 changes: 10 additions & 0 deletions t/mojo/transactor.t
Expand Up @@ -859,4 +859,14 @@ is $tx->req->body, '', 'no content';
is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# Abstract methods
eval { Mojo::Transaction->client_read };
like $@, qr/Method "client_read" not implemented by subclass/, 'right error';
eval { Mojo::Transaction->client_write };
like $@, qr/Method "client_write" not implemented by subclass/, 'right error';
eval { Mojo::Transaction->server_read };
like $@, qr/Method "server_read" not implemented by subclass/, 'right error';
eval { Mojo::Transaction->server_write };
like $@, qr/Method "server_write" not implemented by subclass/, 'right error';

done_testing();
4 changes: 4 additions & 0 deletions t/mojolicious/app.t
Expand Up @@ -579,4 +579,8 @@ $t->get_ok('/foo/session')->status_is(200)
$t->get_ok('/rss.xml')->status_is(200)->content_type_is('application/rss+xml')
->content_like(qr!<\?xml version="1.0" encoding="UTF-8"\?><rss />!);

# Abstract methods
eval { Mojolicious::Plugin->register };
like $@, qr/Method "register" not implemented by subclass/, 'right error';

done_testing();
6 changes: 5 additions & 1 deletion t/mojolicious/command.t
Expand Up @@ -9,7 +9,7 @@ use File::Temp 'tempdir';
use Mojolicious::Command;

# Application
my $command = Mojolicious::Command->new;
my $command = Mojolicious::Command->new(quiet => 1);
isa_ok $command->app, 'Mojo', 'right application';
isa_ok $command->app, 'Mojolicious', 'right application';

Expand All @@ -33,4 +33,8 @@ open my $xml, '<', $command->rel_file('123.xml');
is join('', <$xml>), "seems\nto\nwork", 'right result';
chdir $cwd;

# Abstract methods
eval { Mojolicious::Command->run };
like $@, qr/Method "run" not implemented by subclass/, 'right error';

done_testing();

0 comments on commit cc68204

Please sign in to comment.