summaryrefslogtreecommitdiffstats
path: root/t/11-line-differences.t
blob: 4dd362532bd60623d0385bfb8c920de864699476 (plain) (blame)
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
60
61
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Requires 'Test::Output';

use Eval::Closure;

{
    my $code = eval_closure(
        source      => 'sub { warn "foo" }',
        description => 'bar',
    );
    { local $TODO = $] < 5.010 ? "line numbers from #line are slightly different" : undef;
    stderr_is { $code->() } "foo at bar line 1.\n", "got the right line";
    }
}

{
    my $code = eval_closure(
        source      => <<'SOURCE',
    sub {

        warn "foo";

    }
SOURCE
        description => 'bar',
    );
    { local $TODO = $] < 5.010 ? "line numbers from #line are slightly different" : undef;
    stderr_is { $code->() } "foo at bar line 1.\n", "got the right line";
    }
}

{
    my $code = eval_closure(
        source      => <<'SOURCE',

    sub {
        warn "foo";
    }
SOURCE
        description => 'bar',
    );
    { local $TODO = $] < 5.010 ? "line numbers from #line are slightly different" : undef;
    stderr_is { $code->() } "foo at bar line 1.\n", "got the right line";
    }
}

{
    my $code = eval_closure(
        source      => '$sub',
        environment => { '$sub' => \sub { warn "foo" } },
        description => 'bar',
    );
    { local $TODO = $] < 5.010 ? "#line can't adjust line numbers inside non-evaled subs" : undef;
    stderr_is { $code->() } "foo at bar line 1.\n", "got the right line";
    }
}

done_testing;