Created
November 3, 2017 12:22
-
-
Save anonymous/2447fab3e1588c8450c04c4a21a3eba1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
# The Lite application | |
package Lite; | |
use Mojolicious::Lite; | |
get '/addr' => \&main::app_addr; | |
# The Full application | |
package Full; | |
use Mojo::Base 'Mojolicious'; | |
sub startup { | |
my $r = shift->routes; | |
$r->get( '/addr', \&main::app_addr ); | |
}; | |
package main; | |
use Data::Dumper; | |
# The sub which returns application address | |
sub app_addr { | |
my $c = shift; | |
$c->render( text => $c->app."" ); | |
} | |
use Test::More; | |
use Test::Mojo; | |
my $r = app->routes; | |
$r->any('/l1')->detour( 'Lite' ); | |
$r->any('/l2')->detour( 'Lite' ); | |
$r->any('/f1')->detour( 'Full' ); | |
$r->any('/f2')->detour( 'Full' ); | |
my $t = Test::Mojo->new; | |
my $t2 = Test::Mojo->new(Lite::app); | |
my $addr1 = $t->get_ok('/l1/addr')->tx->res->body; | |
my $addr2 = $t2->get_ok('/l2/addr')->tx->res->body; | |
ok $addr1 ne $addr2, "Different instances"; | |
$addr1 = $t->get_ok('/f1/addr')->tx->res->body; | |
$addr2 = $t->get_ok('/f2/addr')->tx->res->body; | |
ok $addr1 ne $addr2, "Different instances"; | |
done_testing; | |
__END__ | |
$ perl -Ilib t/mojolicious/lite_vs_full.t | |
ok 1 - GET /l1/addr | |
ok 2 - GET /l2/addr | |
not ok 3 - Different instances | |
# Failed test 'Different instances' | |
# at t/mojolicious/nested2.t line 38. | |
ok 4 - GET /f1/addr | |
ok 5 - GET /f2/addr | |
ok 6 - Different instances | |
1..6 | |
# Looks like you failed 1 test of 6. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment