File: 04-ENV.t

package info (click to toggle)
libjson-any-perl 1.28-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 252 kB
  • sloc: perl: 2,701; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 921 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -w

use strict;
use Test::More;
eval "use JSON::Any";

if ($@) {
    plan skip_all => "$@";
}
else {
    plan no_plan => 1;
}

SKIP: {
    eval { require JSON; };
    skip "JSON not installed: $@", 1 if $@;

    $ENV{JSON_ANY_ORDER} = qw(JSON);
    JSON::Any->import();
    skip "JSON not installed: $@", 1 if $@;
    is_deeply( $ENV{JSON_ANY_ORDER}, qw(JSON) );
    is( JSON::Any->handlerType, 'JSON' );
}

SKIP: {
    eval { require JSON::XS; };
    skip "JSON::XS not installed: $@", 1 if $@;

    $ENV{JSON_ANY_ORDER} = qw(XS);

    JSON::Any->import();
    is( JSON::Any->handlerType, 'JSON::XS' );

    my ($json);
    ok( $json = JSON::Any->new() );
    eval { $json->encode("") };
    ok( $@, 'trapped a failure' );
    undef $@;
    $ENV{JSON_ANY_CONFIG} = 'allow_nonref=1';
    ok( $json = JSON::Any->new() );
    ok( $json->encode("dahut"), qq["dahut"] );
    is( $@, undef, 'no failure' );
}