use json for serialized data in tests
Graham Knop [Thu, 12 Apr 2018 13:53:02 +0000 (15:53 +0200)]
maint/Makefile.PL.include
t/lib/TestApp/Controller/Fork.pm
t/live_fork.t
t/optional_memleak.t
t/optional_stress.json [new file with mode: 0644]
t/optional_stress.t
t/optional_stress.yml [deleted file]

index d41f46e..235ed1f 100644 (file)
@@ -12,7 +12,7 @@ manifest_include 't/lib/TestMiddleware/share' => qr/.*/;
 manifest_include 't/lib/TestMiddlewareFromConfig/share' => qr/.*/;
 manifest_include 't/lib/TestMiddlewareFromConfig' => 'testmiddlewarefromconfig.pl';
 manifest_include t => qr/optional_apache-.*\.pl/;
-manifest_include t => 'optional_stress.yml';
+manifest_include t => 'optional_stress.json';
 manifest_include t => 'something/Makefile.PL';
 manifest_include t => 'something/script/foo/bar/for_dist';
 manifest_include t => 'utf8.txt';
index 2a91193..2645e6e 100644 (file)
@@ -7,7 +7,7 @@ use strict;
 use warnings;
 use base 'Catalyst::Controller';
 
-eval 'use YAML';
+use JSON::MaybeXS qw(encode_json);
 
 sub system : Local {
     my ($self, $c, $ls) = @_;
@@ -21,7 +21,7 @@ sub system : Local {
         $result = $! if $result != 0;
     }
     
-    $c->response->body(Dump({result => $result}));
+    $c->response->body(encode_json({result => $result}));
 }
 
 sub backticks : Local {
@@ -37,7 +37,7 @@ sub backticks : Local {
         $code = $?;
     }
     
-    $c->response->body(Dump({result => $result, code => $code}));
+    $c->response->body(encode_json({result => $result, code => $code}));
 }
 
 sub fork : Local {
@@ -54,7 +54,7 @@ sub fork : Local {
 
     waitpid $pid,0 or die;
     
-    $c->response->body(Dump({pid => $pid, result => $x}));
+    $c->response->body(encode_json({pid => $pid, result => $x}));
 }
 
 1;
index 3a2dc3c..e716b38 100644 (file)
@@ -12,9 +12,7 @@ use Test::More;
 use FindBin;
 use lib "$FindBin::Bin/lib";
 use Catalyst::Test qw(TestApp);
-
-eval 'use YAML';
-plan skip_all => 'YAML required' if $@;
+use JSON::MaybeXS qw(decode_json);
 
 plan skip_all => 'Using remote server (and REMOTE_FORK not set)'
     if $ENV{CATALYST_SERVER} && !$ENV{REMOTE_FORK};
@@ -26,7 +24,7 @@ plan skip_all => 'Skipping fork tests: no /bin/ls'
     ok(my $result = get('/fork/system/%2Fbin%2Fls'), 'system');
 
     if (my $result_ref = result_ok($result)) {
-        ok($result_ref, 'is YAML');
+        ok($result_ref, 'is JSON');
         is($result_ref->{result}, 0, 'exited OK');
     }
 }
@@ -35,7 +33,7 @@ plan skip_all => 'Skipping fork tests: no /bin/ls'
     ok(my $result = get('/fork/backticks/%2Fbin%2Fls'), '`backticks`');
 
     if (my $result_ref = result_ok($result)) {
-        ok($result_ref, 'is YAML');
+        ok($result_ref, 'is JSON');
         is($result_ref->{code}, 0, 'exited successfully');
         like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$');
         like($result_ref->{result}, qr{\n.*\n}m, 'contains two newlines');
@@ -46,7 +44,7 @@ plan skip_all => 'Skipping fork tests: no /bin/ls'
     ok(my $result = get('/fork/fork'), 'fork');
 
     if (my $result_ref = result_ok($result)) {
-        ok($result_ref, 'is YAML');
+        ok($result_ref, 'is JSON');
         isnt($result_ref->{pid}, 0, q{fork's "pid" wasn't 0});
         isnt($result_ref->{pid}, $$, 'fork got a new pid');
         is($result_ref->{result}, 'ok', 'fork was effective');
@@ -61,7 +59,7 @@ sub result_ok {
 
     $result =~ s/\r\n|\r/\n/g;
 
-    return eval { Load($result) };
+    return eval { decode_json($result) };
 }
 
 done_testing;
index ca4cbcf..646332a 100644 (file)
@@ -17,12 +17,17 @@ plan skip_all => 'Proc::ProcessTable required for this test' if $@;
 eval "use HTTP::Body 0.03";
 plan skip_all => 'HTTP::Body >= 0.03 required for this test' if $@;
 
-eval "use YAML";
-plan skip_all => 'YAML required for this test' if $@;
+use JSON::MaybeXS qw(decode_json);
 
 our $t = Proc::ProcessTable->new( cache_ttys => 1 );
 our ( $initial, $final ) = ( 0, 0 ); 
-our $tests = YAML::LoadFile("$FindBin::Bin/optional_stress.yml");
+my $test_data = do {
+  open my $fh, '<:raw', "$FindBin::Bin/optional_stress.json" or die "$!";
+  local $/;
+  <$fh>;
+};
+
+our $tests = decode_json($test_data);
 
 my $total_tests = 0;
 
diff --git a/t/optional_stress.json b/t/optional_stress.json
new file mode 100644 (file)
index 0000000..2e1b15a
--- /dev/null
@@ -0,0 +1,126 @@
+{
+   "component/controller/action/auto" : [
+      "http://localhost/action/auto/one",
+      "http://localhost/action/auto/anything",
+      "http://localhost/action/auto/deep/one",
+      "http://localhost/action/auto/deep/anything",
+      "http://localhost/action/auto/abort/one",
+      "http://localhost/action/auto/abort/anything"
+   ],
+   "component/controller/action/begin" : [
+      "http://localhost/action/begin"
+   ],
+   "component/controller/action/default" : [
+      "http://localhost/action/default",
+      "http://localhost/foo/bar/action",
+      "http://localhost/action/default/arg1/arg2"
+   ],
+   "component/controller/action/detach" : [
+      "http://localhost/action/detach/one",
+      "http://localhost/action/detach/path",
+      "http://localhost/action/detach/with_args/old",
+      "http://localhost/action/detach/with_method_and_args/old"
+   ],
+   "component/controller/action/end" : [
+      "http://localhost/action/end"
+   ],
+   "component/controller/action/forward" : [
+      "http://localhost/action/forward/global",
+      "http://localhost/action/forward/one",
+      "http://localhost/action/forward/jojo",
+      "http://localhost/action/forward/with_args/old",
+      "http://localhost/action/forward/with_method_and_args/old",
+      "http://localhost/action/forward/args_embed_relative",
+      "http://localhost/action/forward/args_embed_absolute"
+   ],
+   "component/controller/action/global" : [
+      "http://localhost/action_global_one",
+      "http://localhost/action_global_two",
+      "http://localhost/action_global_three"
+   ],
+   "component/controller/action/index" : [
+      "http://localhost/",
+      "http://localhost",
+      "http://localhost/index/",
+      "http://localhost/index",
+      "http://localhost/action/index/",
+      "http://localhost/action/index",
+      "http://localhost/action/index/foo"
+   ],
+   "component/controller/action/inheritance" : [
+      "http://localhost/action/inheritance",
+      "http://localhost/action/inheritance/a",
+      "http://localhost/action/inheritance/a/b"
+   ],
+   "component/controller/action/local" : [
+      "http://localhost/action/local/one",
+      "http://localhost/action/local/two",
+      "http://localhost/action/local/three",
+      "http://localhost/action/local/four/five/six"
+   ],
+   "component/controller/action/multipath" : [
+      "http://localhost/action/multipath/multipath",
+      "http://localhost/multipath",
+      "http://localhost/multipath1",
+      "http://localhost/action/multipath/multipath2"
+   ],
+   "component/controller/action/path" : [
+      "http://localhost/action/path/a path with spaces",
+      "http://localhost/action/path/åäö"
+   ],
+   "component/controller/action/private" : [
+      "http://localhost/action/private/one",
+      "http://localhost/action/private/two",
+      "http://localhost/three",
+      "http://localhost/action/private/four",
+      "http://localhost/action/private/five"
+   ],
+   "component/controller/action/regexp" : [
+      "http://localhost/action/regexp/10/hello",
+      "http://localhost/action/regexp/hello/10"
+   ],
+   "component/controller/action/streaming" : [
+      "http://localhost/streaming",
+      "http://localhost/action/streaming/body"
+   ],
+   "engine/request/body" : [],
+   "engine/request/cookies" : [],
+   "engine/request/headers" : [],
+   "engine/request/parameters" : [],
+   "engine/request/uploads" : [],
+   "engine/request/uri" : [
+      "http://localhost/engine/request/uri/change_path",
+      "http://localhost/engine/request/uri/change_base",
+      "http://localhost/engine/request/uri",
+      "http://localhost/engine/request/uri?a=1;a=2;b=3",
+      "http://localhost/engine/request/uri?text=Catalyst%20Rocks"
+   ],
+   "engine/response/cookies" : [
+      "http://localhost/engine/response/cookies/one",
+      "http://localhost/engine/response/cookies/two"
+   ],
+   "engine/response/errors" : [
+      "http://localhost/engine/response/errors/one",
+      "http://localhost/engine/response/errors/two",
+      "http://localhost/engine/response/errors/three"
+   ],
+   "engine/response/headers" : [
+      "http://localhost/engine/response/headers/one"
+   ],
+   "engine/response/large" : [
+      "http://localhost/engine/response/large/"
+   ],
+   "engine/response/redirect" : [
+      "http://localhost/engine/response/redirect/one",
+      "http://localhost/engine/response/redirect/two",
+      "http://localhost/engine/response/redirect/three",
+      "http://localhost/engine/response/redirect/four"
+   ],
+   "engine/response/status" : [
+      "http://localhost/engine/response/status/s200",
+      "http://localhost/engine/response/status/s400",
+      "http://localhost/engine/response/status/s403",
+      "http://localhost/engine/response/status/s404",
+      "http://localhost/engine/response/status/s500"
+   ]
+}
index 9e73cc5..620c840 100644 (file)
@@ -14,11 +14,16 @@ use Catalyst::Test 'TestApp';
 our ( $iters, $tests );
 
 BEGIN {
-    eval "use YAML";
-    plan skip_all => 'YAML is required for this test' if $@;
+    use JSON::MaybeXS qw(decode_json);
+
+    my $test_data = do {
+      open my $fh, '<:raw', "$FindBin::Bin/optional_stress.json" or die "$!";
+      local $/;
+      <$fh>;
+    };
 
     $iters = $ENV{TEST_STRESS} || 10;
-    $tests = YAML::LoadFile("$FindBin::Bin/optional_stress.yml");
+    $tests = decode_json($test_data);
 
     my $total_tests = 0;
     map { $total_tests += scalar @{ $tests->{$_} } } keys %{$tests};
diff --git a/t/optional_stress.yml b/t/optional_stress.yml
deleted file mode 100644 (file)
index 7589063..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
----
-component/controller/action/auto:
-  - http://localhost/action/auto/one
-  - http://localhost/action/auto/anything
-  - http://localhost/action/auto/deep/one
-  - http://localhost/action/auto/deep/anything
-  - http://localhost/action/auto/abort/one
-  - http://localhost/action/auto/abort/anything
-component/controller/action/begin:
-  - http://localhost/action/begin
-component/controller/action/default:
-  - http://localhost/action/default
-  - http://localhost/foo/bar/action
-  - http://localhost/action/default/arg1/arg2
-component/controller/action/detach:
-  - http://localhost/action/detach/one
-  - http://localhost/action/detach/path
-  - http://localhost/action/detach/with_args/old
-  - http://localhost/action/detach/with_method_and_args/old
-component/controller/action/end:
-  - http://localhost/action/end
-component/controller/action/forward:
-  - http://localhost/action/forward/global
-  - http://localhost/action/forward/one
-  - http://localhost/action/forward/jojo
-  - http://localhost/action/forward/with_args/old
-  - http://localhost/action/forward/with_method_and_args/old
-  - http://localhost/action/forward/args_embed_relative
-  - http://localhost/action/forward/args_embed_absolute
-component/controller/action/global:
-  - http://localhost/action_global_one
-  - http://localhost/action_global_two
-  - http://localhost/action_global_three
-component/controller/action/index:
-  - http://localhost/
-  - http://localhost
-  - http://localhost/index/
-  - http://localhost/index
-  - http://localhost/action/index/
-  - http://localhost/action/index
-  - http://localhost/action/index/foo
-component/controller/action/inheritance:
-  - http://localhost/action/inheritance
-  - http://localhost/action/inheritance/a
-  - http://localhost/action/inheritance/a/b
-component/controller/action/local:
-  - http://localhost/action/local/one
-  - http://localhost/action/local/two
-  - http://localhost/action/local/three
-  - http://localhost/action/local/four/five/six
-component/controller/action/multipath:
-  - http://localhost/action/multipath/multipath
-  - http://localhost/multipath
-  - http://localhost/multipath1
-  - http://localhost/action/multipath/multipath2
-component/controller/action/path:
-  - http://localhost/action/path/a path with spaces
-  - http://localhost/action/path/åäö
-component/controller/action/private:
-  - http://localhost/action/private/one
-  - http://localhost/action/private/two
-  - http://localhost/three
-  - http://localhost/action/private/four
-  - http://localhost/action/private/five
-component/controller/action/regexp:
-  - http://localhost/action/regexp/10/hello
-  - http://localhost/action/regexp/hello/10
-component/controller/action/streaming:
-  - http://localhost/streaming
-  - http://localhost/action/streaming/body
-engine/request/body: []
-engine/request/cookies: []
-engine/request/headers: []
-engine/request/parameters: []
-engine/request/uploads: []
-engine/request/uri:
-  - http://localhost/engine/request/uri/change_path
-  - http://localhost/engine/request/uri/change_base
-  - http://localhost/engine/request/uri
-  - http://localhost/engine/request/uri?a=1;a=2;b=3
-  - http://localhost/engine/request/uri?text=Catalyst%20Rocks
-engine/response/cookies:
-  - http://localhost/engine/response/cookies/one
-  - http://localhost/engine/response/cookies/two
-engine/response/errors:
-  - http://localhost/engine/response/errors/one
-  - http://localhost/engine/response/errors/two
-  - http://localhost/engine/response/errors/three
-engine/response/headers:
-  - http://localhost/engine/response/headers/one
-engine/response/large:
-  - http://localhost/engine/response/large/
-engine/response/redirect:
-  - http://localhost/engine/response/redirect/one
-  - http://localhost/engine/response/redirect/two
-  - http://localhost/engine/response/redirect/three
-  - http://localhost/engine/response/redirect/four
-engine/response/status:
-  - http://localhost/engine/response/status/s200
-  - http://localhost/engine/response/status/s400
-  - http://localhost/engine/response/status/s403
-  - http://localhost/engine/response/status/s404
-  - http://localhost/engine/response/status/s500