File: stream.t

package info (click to toggle)
libplack-middleware-test-stashwarnings-perl 0.08-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 180 kB
  • sloc: perl: 1,474; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,390 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use strict;
use warnings;
use Plack::Test;
use Test::More;
use HTTP::Request::Common;

use Plack::Builder;
use Plack::Request;

use Storable 'thaw';

my $app = sub {
    my $req = Plack::Request->new(shift);
    my $name = $req->param('name');
    return sub {
        my $responder = shift;
        my $writer = $responder->([200, ["Content-Type", "text/plain"]]);

        $writer->write("Hello ");
        $writer->write("$name");
        $writer->write("!");
        $writer->close;
    };
};

my $t = builder {
    enable "Test::StashWarnings";
    $app;
};

test_psgi $t, sub {
    my $cb = shift;

    my $res = $cb->(GET "/__test_warnings");
    is_deeply thaw($res->content), [];
    is $res->content_type, 'application/x-storable';

    $res = $cb->(GET "/?name=foo");
    like $res->content, qr/Hello foo!/;
    is $res->content_type, 'text/plain';

    $res = $cb->(GET "/__test_warnings");
    is_deeply thaw($res->content), [], 'no warnings';
    is $res->content_type, 'application/x-storable';

    $res = $cb->(GET "/");
    like $res->content, qr/Hello !/;
    is $res->content_type, 'text/plain';

    $res = $cb->(GET "/__test_warnings");
    my @warnings = @{ thaw($res->content) };
    is @warnings, 1, "one warning";
    like $warnings[0], qr/Use of uninitialized value (?:\$name )?in string/;
    is $res->content_type, 'application/x-storable';
};

done_testing;