remove test dependency on Test::Without::Module (RT#115394)
[p5sagit/JSON-MaybeXS.git] / t / legacy.t
index 0216033..fb5cc19 100644 (file)
@@ -1,20 +1,36 @@
 use strict;
-use warnings FATAL => 'all';
-
-use Test::Without::Module 'Cpanel::JSON::XS';
-use Test::More;
-use JSON::MaybeXS qw/:legacy/;
+use warnings;
 
+# hide Cpanel::JSON::XS
+use lib map {
+    my ( $m, $c ) = ( $_, qq{die "Can't locate $_ (hidden)\n"} );
+    sub { return unless $_[1] eq $m; open my $fh, "<", \$c; return $fh }
+} qw{Cpanel/JSON/XS.pm};
 
+use Test::More 0.88;
+use JSON::MaybeXS qw/:legacy/;
 
 my $in = '[1, 2, 3, 4]';
 
-
 my $arr = from_json($in);
 my $j = to_json($arr);
 is($j, '[1,2,3,4]');
 is(ref($arr), 'ARRAY');
 
+my $json = 'JSON::MaybeXS';
+diag "using invocant: $json";
+like(
+    do { eval { $json->from_json($in) }; $@ },
+    qr/from_json should not be called as a method/,
+    'blessed invocant detected in from_json',
+);
+
+like(
+    do { eval { $json->to_json($arr, { blah => 1 } ) }; $@ },
+    qr/to_json should not be called as a method/,
+    'blessed invocant detected in to_json',
+);
+
 done_testing;
 
 __END__