Skip to content
Browse files

Protect against autovivication.

  • Loading branch information...
1 parent 9abc1e8 commit add5792b45c600abbdd656e397ca679e589c9b29 @theory theory committed May 25, 2011
Showing with 42 additions and 3 deletions.
  1. +1 −0 Changes
  2. +41 −3 t/base.t
1 Changes
@@ -1,6 +1,7 @@
Revision history for Perl extension PGXN-Meta-Validator.
+ - Added tests to protect against autovivication of keys.
0.13.0 2011-05-26T03:52:07
- Fixed invalid Unicode character class.
44 t/base.t
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::More tests => 7;
+use Test::More tests => 28;
use File::Spec;
@@ -9,11 +9,13 @@ BEGIN {
my $file = File::Spec->catfile(qw(t META.json));
-ok my $pmv = PGXN::Meta::Validator->new(JSON->new->decode(do {
+my $data = JSON->new->decode(do {
local $/;
open my $fh, '<:raw', $file or die "Cannot open $file: $!\n";
-})), 'Construct from data structure';
+ok my $pmv = PGXN::Meta::Validator->new($data), 'Construct from data structure';
ok $pmv->is_valid, 'Structure should be valid';
ok $pmv = PGXN::Meta::Validator->load_file($file), 'Load from file';
@@ -31,3 +33,39 @@ eval {
like $@, qr{^malformed JSON string},
'Should catch exception for invalid JSON';
+# Make sure there's no autovivication.
+delete $data->{no_index};
+ok $pmv = PGXN::Meta::Validator->new($data), 'Construct with no no_index';
+ok $pmv->is_valid, 'Structure should be valid';
+ok !exists $data->{no_index}, 'Should still have no no_index key';
+delete $data->{prereqs}{runtime}{requires};
+ok $pmv = PGXN::Meta::Validator->new($data), 'Construct with no requires';
+ok $pmv->is_valid, 'Structure should be valid';
+ok !exists $data->{prereqs}{runtime}{requires}, 'Should still have no requires key';
+delete $data->{prereqs}{runtime};
+ok $pmv = PGXN::Meta::Validator->new($data), 'Construct with no runtime';
+ok $pmv->is_valid, 'Structure should be valid';
+ok !exists $data->{prereqs}{runtime}, 'Should still have no runtime key';
+delete $data->{prereqs};
+ok $pmv = PGXN::Meta::Validator->new($data), 'Construct with no prereqs';
+ok $pmv->is_valid, 'Structure should be valid';
+ok !exists $data->{prereqs}, 'Should still have no prereqs key';
+delete $data->{resources}{bugtracker};
+ok $pmv = PGXN::Meta::Validator->new($data), 'Construct with no bugtracker';
+ok $pmv->is_valid, 'Structure should be valid';
+ok !exists $data->{resources}{bugtracker}, 'Should still have no bugtracker key';
+delete $data->{resources}{repository};
+ok $pmv = PGXN::Meta::Validator->new($data), 'Construct with no repository';
+ok $pmv->is_valid, 'Structure should be valid';
+ok !exists $data->{resources}{repository}, 'Should still have no repository key';
+delete $data->{resources};
+ok $pmv = PGXN::Meta::Validator->new($data), 'Construct with no resources';
+ok $pmv->is_valid, 'Structure should be valid';
+ok !exists $data->{resources}, 'Should still have no resources key';

0 comments on commit add5792

Please sign in to comment.
Something went wrong with that request. Please try again.