File: names.t

package info (click to toggle)
libdevel-confess-perl 0.009004-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 212 kB
  • ctags: 57
  • sloc: perl: 991; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 750 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
use strict;
use warnings;
BEGIN {
  $ENV{DEVEL_CONFESS_OPTIONS} = '';
}
use Devel::Confess ();
use Test::More
  Devel::Confess::_CAN_USE_INFORMATIVE_NAMES ? (tests => 2)
  : (skip_all => "Can't enable better names at runtime on perl < 5.8");

use Devel::Confess qw(better_names);

sub foo {
  die "welp";
}

my $bar = sub {
  foo();
};

sub baz {
  $bar->();
}

eval q{ baz; };
my $err = $@;

Devel::Confess->unimport;

my $file = quotemeta __FILE__;

my @lines = split /\n/, $err;

my $fail;
like $lines[2], qr/main::__ANON__\[$file:\d+\]\(\) called at/,
  'anonymous function names include file and line number'
    or $fail = 1;

like $lines[4], qr/baz;/,
  'string evals include eval text'
    or $fail = 1;

diag "Full error:\n$err"
  if $fail;