do not skip any tests in author mode - die instead!
[gitmo/MooseX-Storage.git] / t / 040_basic_utils.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 5;
5
6 BEGIN {
7     use_ok('MooseX::Storage');
8     use_ok('MooseX::Storage::Util');
9 }
10
11 my $packed = {
12     __CLASS__ => 'Foo',
13     number    => 10,
14     string    => 'foo',
15     float     => 10.5,
16     array     => [ 1 .. 10 ],
17     hash      => { map { $_ => undef } ( 1 .. 10 ) },
18     object    => {
19        __CLASS__ => 'Foo',
20        number    => 2
21     },
22 };
23
24 my $json = '{"array":[1,2,3,4,5,6,7,8,9,10],"hash":{"6":null,"3":null,"7":null,"9":null,"2":null,"8":null,"1":null,"4":null,"10":null,"5":null},"float":10.5,"object":{"number":2,"__CLASS__":"Foo"},"number":10,"__CLASS__":"Foo","string":"foo"}';
25 my $yaml = q{---
26 __CLASS__: Foo
27 array:
28   - 1
29   - 2
30   - 3
31   - 4
32   - 5
33   - 6
34   - 7
35   - 8
36   - 9
37   - 10
38 float: 10.5
39 hash:
40   1: ~
41   10: ~
42   2: ~
43   3: ~
44   4: ~
45   5: ~
46   6: ~
47   7: ~
48   8: ~
49   9: ~
50 number: 10
51 object:
52   __CLASS__: Foo
53   number: 2
54 string: foo
55 };
56
57 is('Foo', MooseX::Storage::Util->peek($packed),
58    '... got the right class name from the packed item');
59
60 SKIP: {
61     my $classname = eval {
62         MooseX::Storage::Util->peek($json => ('format' => 'JSON'))
63     };
64     if ($@ =~ /^Could not load JSON module because/) {
65         die 'No JSON module found' if $ENV{AUTHOR_TESTING};
66         skip "No JSON module found", 1;
67     }
68
69     is('Foo', $classname,
70        '... got the right class name from the json item');
71 }
72
73 SKIP: {
74     my $classname = eval {
75         MooseX::Storage::Util->peek($yaml => ('format' => 'YAML'))
76     };
77     if ($@ =~ /^Could not load YAML module because/
78         or $@ =~ /^Can't locate Best/
79     ) {
80         die 'No YAML module found' if $ENV{AUTHOR_TESTING};
81         skip "No YAML module found", 1;
82     }
83
84     is('Foo', $classname,
85        '... got the right class name from the yaml item');
86 }
87
88