From f1b91129c91259731320329b561896a22b97f341 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 22 Jun 2011 12:37:12 -0500 Subject: more tests --- t/basic.t | 89 ++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 23 deletions(-) diff --git a/t/basic.t b/t/basic.t index 2373218..bf775fd 100644 --- a/t/basic.t +++ b/t/basic.t @@ -12,12 +12,6 @@ use HTTP::Request::Common; use Plack::Middleware::Class::Refresh; -my $dir = Test::PMCR::setup_temp_dir('basic'); - -require Foo; -require Foo::Bar; -require Baz::Quux; - my $app = sub { return [ 200, @@ -26,22 +20,71 @@ my $app = sub { ]; }; -test_psgi - app => Plack::Middleware::Class::Refresh->wrap($app), - client => sub { - my $cb = shift; - { - my $res = $cb->(GET 'http://localhost/'); - is($res->code, 200, "right code"); - is($res->content, "Foo\nFoo::Bar\nBaz::Quux"); - } - copy(catfile(qw(t data_new basic Foo.pm)), catfile($dir, 'Foo.pm')) - || die "couldn't copy: $!"; - { - my $res = $cb->(GET 'http://localhost/'); - is($res->code, 200, "right code"); - is($res->content, "FOO\nFoo::Bar\nBaz::Quux"); - } - }; +{ + my $dir = Test::PMCR::setup_temp_dir('basic'); + + require Foo; + require Foo::Bar; + require Baz::Quux; + + test_psgi + app => Plack::Middleware::Class::Refresh->wrap($app), + client => sub { + my $cb = shift; + { + my $warnings; + local $SIG{__WARN__} = sub { $warnings .= $_[0] }; + my $res = $cb->(GET 'http://localhost/'); + is($res->code, 200, "right code"); + is($res->content, "Foo\nFoo::Bar\nBaz::Quux"); + is($warnings, undef, "no warnings when not verbose"); + } + copy(catfile(qw(t data_new basic Foo.pm)), catfile($dir, 'Foo.pm')) + || die "couldn't copy: $!"; + { + my $warnings; + local $SIG{__WARN__} = sub { $warnings .= $_[0] }; + my $res = $cb->(GET 'http://localhost/'); + is($res->code, 200, "right code"); + is($res->content, "FOO\nFoo::Bar\nBaz::Quux", "right content"); + is($warnings, undef, "no warnings when not verbose"); + } + }; +} + +Class::Refresh->unload_module($_) for 'Foo', 'Foo::Bar', 'Baz::Quux'; + +{ + my $dir = Test::PMCR::setup_temp_dir('basic'); + + require Foo; + require Foo::Bar; + require Baz::Quux; + + test_psgi + app => Plack::Middleware::Class::Refresh->wrap($app, verbose => 1), + client => sub { + my $cb = shift; + { + my $warnings; + local $SIG{__WARN__} = sub { $warnings .= $_[0] }; + my $res = $cb->(GET 'http://localhost/'); + is($res->code, 200, "right code"); + is($res->content, "Foo\nFoo::Bar\nBaz::Quux"); + is($warnings, undef, "no warnings yet"); + } + copy(catfile(qw(t data_new basic Foo.pm)), catfile($dir, 'Foo.pm')) + || die "couldn't copy: $!"; + { + my $warnings; + local $SIG{__WARN__} = sub { $warnings .= $_[0] }; + my $res = $cb->(GET 'http://localhost/'); + is($res->code, 200, "right code"); + is($res->content, "FOO\nFoo::Bar\nBaz::Quux", "right content"); + like($warnings, qr/^Class Foo has been changed, refreshing/, + "right warning"); + } + }; +} done_testing; -- cgit v1.2.3