Test::Deep is already required; use it instead of is_deeply
[gitmo/MooseX-Storage.git] / t / 101_io_atomic.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Deep;
8 use File::Temp qw(tempdir);
9 use File::Spec::Functions;
10 my $dir = tempdir( CLEANUP => 1 );
11
12 use Test::Requires {
13     'JSON::Any' => 0.01, # skip all if not installed
14     'IO::AtomicFile' => 0.01,
15 };
16
17 BEGIN {
18     plan tests => 10;
19     use_ok('MooseX::Storage');
20 }
21
22 {
23     package Foo;
24     use Moose;
25     use MooseX::Storage;
26     
27     with Storage(format => 'JSON', io => 'AtomicFile');
28     
29     has 'number' => (is => 'ro', isa => 'Int');
30     has 'string' => (is => 'ro', isa => 'Str');
31     has 'float'  => (is => 'ro', isa => 'Num');        
32     has 'array'  => (is => 'ro', isa => 'ArrayRef');
33     has 'hash'   => (is => 'ro', isa => 'HashRef');    
34         has 'object' => (is => 'ro', isa => 'Object');    
35 }
36
37 my $file = catfile($dir,'temp.json');
38
39 {
40     my $foo = Foo->new(
41         number => 10,
42         string => 'foo',
43         float  => 10.5,
44         array  => [ 1 .. 10 ],
45         hash   => { map { $_ => undef } (1 .. 10) },
46         object => Foo->new( number => 2 ),
47     );
48     isa_ok($foo, 'Foo');
49
50     $foo->store($file);
51 }
52
53 {
54     my $foo = Foo->load($file);
55     isa_ok($foo, 'Foo');
56
57     is($foo->number, 10, '... got the right number');
58     is($foo->string, 'foo', '... got the right string');
59     is($foo->float, 10.5, '... got the right float');
60     cmp_deeply($foo->array, [ 1 .. 10], '... got the right array');
61     cmp_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash');
62
63     isa_ok($foo->object, 'Foo');
64     is($foo->object->number, 2, '... got the right number (in the embedded object)');
65 }
66