File: perl-monks-1165399.t

package info (click to toggle)
libjson-parse-perl 0.62-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 572 kB
  • sloc: ansic: 3,614; perl: 475; makefile: 12
file content (33 lines) | stat: -rw-r--r-- 627 bytes parent folder | download | duplicates (2)
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
# This is a test for the fix of the following bug:
# https://github.com/benkasminbullock/JSON-Parse/issues/34

# There is also a discussion here:
# http://perlmonks.org/?node_id=1165399

use FindBin '$Bin';
use lib "$Bin";
use JPT;

my $j = JSON::Parse->new();
# no complain, no effect:
$j->warn_only(1);

# legal json:
eval {
    my $pl = $j->run('{"k":"v"}');
};
ok (! $@);

# illegal json, the following statement dies:
my $warning;

$SIG{__WARN__} = sub { $warning = "@_" };
eval {
    my $pl = $j->run('illegal json');
};
ok (! $@, "No fatal error");
ok ($warning, "Got warning");

undef $SIG{__WARN__};

done_testing ();