move to github
[gitmo/MooseX-Storage.git] / t / 104_io_w_utf8.t
index 39753ad..bc05023 100644 (file)
@@ -1,24 +1,28 @@
-#!/usr/bin/perl
-
 use strict;
 use warnings;
 
 use Test::More;
-
-BEGIN {  
-    # NOTE: 
-    # this is because JSON::XS is 
-    # the only one which really gets
-    # utf8 correct
-    # - SL 
-    BEGIN { 
-        $ENV{JSON_ANY_ORDER}  = qw(XS);
-        $ENV{JSON_ANY_CONFIG} = "utf8=1";        
-    }           
-    plan tests => 8;
-    use_ok('MooseX::Storage');
+use File::Temp qw(tempdir);
+use File::Spec::Functions;
+my $dir = tempdir( CLEANUP => 1 );
+
+# NOTE:
+# this is because JSON::XS (and Cpanel::JSON::XS) is
+# the only one which really gets utf8 correct
+# - SL
+BEGIN {
+    $ENV{JSON_ANY_ORDER}  = 'XS CPANEL';
+    $ENV{JSON_ANY_CONFIG} = "utf8=0,canonical=1";
 }
 
+use Test::Requires {
+    'JSON::Any' => 0.01, # skip all if not installed
+    'IO::AtomicFile' => 0.01,
+};
+
+plan tests => 8;
+use_ok('MooseX::Storage');
+
 use utf8;
 
 {
@@ -27,7 +31,7 @@ use utf8;
     use MooseX::Storage;
 
     with Storage( 'format' => 'JSON', 'io' => 'File' );
-    
+
     has 'utf8_string' => (
         is      => 'rw',
         isa     => 'Str',
@@ -35,21 +39,21 @@ use utf8;
     );
 }
 
-my $file = 'temp.json';
+my $file = catfile($dir,'temp.json');
 
 {
     my $foo = Foo->new;
     isa_ok( $foo, 'Foo' );
-       
-    $foo->store($file);         
+
+    $foo->store($file);
 }
 
 {
     my $foo = Foo->load($file);
     isa_ok($foo, 'Foo');
 
-    is($foo->utf8_string, 
-      "ネットスーパー (Internet Shopping)", 
+    is($foo->utf8_string,
+      "ネットスーパー (Internet Shopping)",
       '... got the string we expected');
 }
 
@@ -62,19 +66,18 @@ unlink $file;
         utf8_string => 'Escritório'
     );
     isa_ok( $foo, 'Foo' );
-       
-    $foo->store($file);         
+
+    $foo->store($file);
 }
 
 {
     my $foo = Foo->load($file);
     isa_ok($foo, 'Foo');
-    
+
     ok(utf8::is_utf8($foo->utf8_string), '... the string is still utf8');
 
-    is($foo->utf8_string, 
-      "Escritório", 
+    is($foo->utf8_string,
+      "Escritório",
       '... got the string we expected');
 }
 
-unlink $file;