File: line_numbers.t

package info (click to toggle)
libmethod-signatures-perl 20170211-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 672 kB
  • sloc: perl: 3,860; makefile: 2
file content (86 lines) | stat: -r--r--r-- 2,011 bytes parent folder | download | duplicates (5)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/perl -w

# Test that Method::Signatures does not change the line numbers
# in caller and error messages.

use strict;
use Test::More;

use Method::Signatures;

my $DEFAULT_LINES_NOT_WORKING = $] < 5.012;
my $DEFAULT_LINES_NOT_WORKING_REASON = 'Earlier versions of Perl get the line numbers wrong';

note "Basic multi-line signature"; {
#line 13
    func basic_multi_line (
        $arg = "test"
    ) {
        return __LINE__;
    }

    is basic_multi_line(), 16;

    is __LINE__, 21, "line numbers ok after function";
}


note "Computed default"; {
    # Using 'sub' to avoid further Method::Signatures interference
    sub return_caller_line {
        return (caller)[2];
    }

#line 30
    func computed_default (
        $static_default   = "test",
        $computed_default = return_caller_line()
    ) {
        return [__LINE__, $computed_default];
    }

    my $have = computed_default();
    is $have->[0], 34, "body line number";
    SKIP: {
        skip $DEFAULT_LINES_NOT_WORKING_REASON, 1 if $DEFAULT_LINES_NOT_WORKING;
        is $have->[1], 32, "computed default line number";
    };

    is __LINE__, 44, "line numbers ok after function";
}


note "single line signature"; {
#line 45
    func single_line($a?, $b?, $c?) { return __LINE__ }
    is single_line, 45;
    is __LINE__, 47, "line numbers ok after function";
}


# Multi-line defaults are collapsed into one line, so __LINE__
# will be off after the first line of each default.
note "multi-line default"; {
#line 52
    func multi_line_defaults(
        $a = { line => __LINE__
        },
        $b = { line => __LINE__
        }
    ) {
        return [$a->{line}, $b->{line}, __LINE__];
    }

    my $have = multi_line_defaults;
    SKIP: {
        skip $DEFAULT_LINES_NOT_WORKING_REASON, 1 if $DEFAULT_LINES_NOT_WORKING;
        is $have->[0], 53, 'default $a';
        is $have->[1], 55, 'default $b';
    }
    is $have->[2], 58, 'body';

    is __LINE__, 69, "line numbers ok after function";
}


done_testing;