File: description.t

package info (click to toggle)
libeval-closure-perl 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, stretch
  • size: 196 kB
  • ctags: 12
  • sloc: perl: 559; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Fatal;

use Eval::Closure;

my $source = <<'SOURCE';
sub {
    Carp::confess("foo")
}
SOURCE

{
    my $code = eval_closure(
        source => $source,
    );

    like(
        exception { $code->() },
        qr/^foo at \(eval \d+\) line \d+/,
        "no location info if context isn't passed"
    );
}

{
    my $code = eval_closure(
        source      => $source,
        description => 'accessor foo (defined at Class.pm line 282)',
    );

    like(
        exception { $code->() },
        qr/^foo at accessor foo \(defined at Class\.pm line 282\) line 2/,
        "description is set"
    );
}

{
    my $code = eval_closure(
        source      => $source,
        line        => 100,
        description => 'accessor foo (defined at Class.pm line 282)',
    );

    like(
        exception { $code->() },
        qr/^foo at accessor foo \(defined at Class\.pm line 282\) line 101/,
        "description is set"
    );
}
done_testing;