File: Info.t

package info (click to toggle)
libtest-simple-perl 1.302075-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,844 kB
  • ctags: 628
  • sloc: perl: 10,369; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,367 bytes parent folder | download
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
use strict;
use warnings;

use Test2::Tools::Tiny;

use Test2::Event::Info;
use Test2::Util::Trace;
use Test2::API qw/intercept/;

my @got;

my $info = Test2::Event::Info->new(
    trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__]),
    renderer => sub { @got = @_; 'foo' },
);

is($info->summary, 'foo', "summary is just rendering");
is_deeply(\@got, ['text'], "got text");

is($info->summary('blah'), 'foo', "summary is just rendering (arg)");
is_deeply(\@got, ['blah'], "got arg");

{
    package An::Info::Thingy;
    sub render { shift; @got = @_; 'foo' }
}

$info = Test2::Event::Info->new(
    trace => Test2::Util::Trace->new(frame => [__PACKAGE__, __FILE__, __LINE__]),
    renderer => bless({}, 'An::Info::Thingy'),
);

is($info->summary, 'foo', "summary is just rendering");
is_deeply(\@got, ['text'], "got text");

is($info->summary('blah'), 'foo', "summary is just rendering (arg)");
is_deeply(\@got, ['blah'], "got arg");

eval { Test2::Event::Info->new(trace => Test2::Util::Trace->new(frame => ['Foo', 'foo.pl', 42])) };
like(
    $@,
    qr/'renderer' is a required attribute at foo\.pl line 42/,
    "Got expected error"
);

# For #727
$info = intercept { ok(0, 'xxx', sub { 'xxx-yyy' }); }->[-1];
ok($info->isa('Test2::Event::Info'), "Got an Info event");
is($info->render, 'xxx-yyy', "Got rendered info");

done_testing;