From: Chris Prather Date: Thu, 17 May 2007 03:04:43 +0000 (+0000) Subject: skipping tests if you don't have Test::* installed X-Git-Tag: 0_02~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7aac8ce996cd654b8a8eeb159b54a1853a079938;p=gitmo%2FMooseX-Storage.git skipping tests if you don't have Test::* installed r16589@alice-3: perigrin | 2007-04-13 19:26:09 -0500 now with accurate error messages (d'oh!) r21430@alice-3: perigrin | 2007-05-16 22:02:59 -0500 Add a first draft of MooseX::Daemonize --- diff --git a/t/002_basic_io.t b/t/002_basic_io.t new file mode 100644 index 0000000..f5acac8 --- /dev/null +++ b/t/002_basic_io.t @@ -0,0 +1,56 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More no_plan => 1; + +{ + package Foo; + use Moose; + use MooseX::Storage; + + with Storage( + format => 'JSON', + io => 'File', + ); + + has 'number' => (is => 'ro', isa => 'Int'); + has 'string' => (is => 'ro', isa => 'Str'); + has 'float' => (is => 'ro', isa => 'Num'); + has 'array' => (is => 'ro', isa => 'ArrayRef'); + has 'hash' => (is => 'ro', isa => 'HashRef'); + has 'object' => (is => 'ro', isa => 'Object'); +} + +my $file = 'temp.json'; + +{ + my $foo = Foo->new( + number => 10, + string => 'foo', + float => 10.5, + array => [ 1 .. 10 ], + hash => { map { $_ => undef } (1 .. 10) }, + object => Foo->new( number => 2 ), + ); + isa_ok($foo, 'Foo'); + + $foo->store($file); +} + +{ + my $foo = Foo->load($file); + isa_ok($foo, 'Foo'); + + is($foo->number, 10, '... got the right number'); + is($foo->string, 'foo', '... got the right string'); + is($foo->float, 10.5, '... got the right float'); + is_deeply($foo->array, [ 1 .. 10], '... got the right array'); + is_deeply($foo->hash, { map { $_ => undef } (1 .. 10) }, '... got the right hash'); + + isa_ok($foo->object, 'Foo'); + is($foo->object->number, 2, '... got the right number (in the embedded object)'); +} + +unlink $file; diff --git a/t/010_basic_json.t b/t/010_basic_json.t index 5a93cc5..a410b13 100644 --- a/t/010_basic_json.t +++ b/t/010_basic_json.t @@ -38,22 +38,23 @@ BEGIN { object => Foo->new( number => 2 ), ); isa_ok( $foo, 'Foo' ); - + my $json = $foo->freeze; - + is_valid_json($json, '.. this is valid JSON'); - + is_json( $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"}', +'{"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"}', '... got the right JSON' ); } { - my $foo = Foo->thaw( - '{"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"}' - ); + my $foo = + Foo->thaw( +'{"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"}' + ); isa_ok( $foo, 'Foo' ); is( $foo->number, 10, '... got the right number' ); diff --git a/t/020_basic_yaml.t b/t/020_basic_yaml.t index 36ee605..ab37909 100644 --- a/t/020_basic_yaml.t +++ b/t/020_basic_yaml.t @@ -38,11 +38,11 @@ BEGIN { object => Foo->new( number => 2 ), ); isa_ok( $foo, 'Foo' ); - + my $yaml = $foo->freeze; - - yaml_string_ok($yaml, '... we got valid YAML out of it'); - + + yaml_string_ok( $yaml, '... we got valid YAML out of it' ); + is( $yaml, q{--- @@ -76,12 +76,14 @@ object: number: 2 string: foo }, - '... got the same YAML'); - + '... got the same YAML' + ); + } { - my $foo = Foo->thaw(q{--- + my $foo = Foo->thaw( + q{--- __CLASS__: Foo array: - 1 @@ -111,7 +113,8 @@ object: __CLASS__: Foo number: 2 string: foo -}); +} + ); isa_ok( $foo, 'Foo' ); is( $foo->number, 10, '... got the right number' );