File: safe.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 (49 lines) | stat: -rw-r--r-- 1,081 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
45
46
47
48
49
use strict;
use warnings;
BEGIN {
  $ENV{DEVEL_CONFESS_OPTIONS} = '';
}
use Test::More tests => 3;
use Safe;
use Devel::Confess ();

local $TODO = 'not working reliably with Safe in perl 5.6'
  if "$]" < 5.008;
{
  package Shared::Ex;
  use overload '""' => sub { $_[0]->{message} };
  sub foo {
    die @_;
  }
  sub bar {
    foo(@_);
  }
  sub new {
    my $class = shift;
    bless {@_}, $class;
  }
}

my $comp = Safe->new;
$comp->share_from('main', [
  '*Shared::Ex::'
]);
$comp->permit('entereval');
Devel::Confess->import;
$comp->reval('Shared::Ex::bar("string")');
Devel::Confess->unimport;
like $@, qr{
  \Astring\ at\ \S+\ line\ \d+\.[\r\n]+
  [\t]Shared::Ex::foo\(.*?\)\ called\ at\ .*\ line\ \d+[\r\n]+
  [\t]Shared::Ex::bar\(.*?\)\ called\ at\ .*\ line\ \d+[\r\n]+
}x, 'works in Safe compartment with string error';

Devel::Confess->import;
sub { sub {
  $comp->reval('Shared::Ex->new(message => "welp")->bar');
}->(2) }->(1);
Devel::Confess->unimport;

isa_ok $@, 'Shared::Ex';
ok !$@->isa('Devel::Confess::_Attached'),
  "didn't interfere with object inside Safe";