X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frun_if_script.t;fp=t%2Frun_if_script.t;h=ede9d89b9fa514a344e8cf4b26c36b59bf46506f;hb=fd8747e504c32074e49b1514b39418c32bd22a32;hp=0000000000000000000000000000000000000000;hpb=bb07abdcc3d1d5d78fff44c2ea7cdc1daddc2ef7;p=catagits%2FWeb-Simple.git diff --git a/t/run_if_script.t b/t/run_if_script.t new file mode 100644 index 0000000..ede9d89 --- /dev/null +++ b/t/run_if_script.t @@ -0,0 +1,42 @@ +use strictures; + +use Test::More; + +{ + use Web::Simple 'RunTest'; + + package RunTest; + use Moo; + has test => is => ro => default => sub { 2 }; + sub to_psgi_app { "to_psgi_app" } + sub run { @_, "run" } +} + +is( + sub { RunTest->run_if_script } + ->(), + "to_psgi_app", + "to_psgi_app is called when run_if_script is called inside a function" +); + +is( + ( RunTest->run_if_script )[0]->test, # + 2, + "calling run_if_script on a class name instantiates it and runs it" +); + +my $rt = RunTest->new( test => 3 ); + +is_deeply( + [ $rt->run_if_script ], # + [ $rt, $rt, "run" ], + "calling run_if_script on an object runs it directly" +); + +is_deeply( + [ $rt->run_if_script( 4 ) ], # + [ $rt, $rt, 4, "run" ], + "passing arguments to run_if_script has them passed on to the run method" +); + +done_testing;