Test::JSON::Schema::Acceptance - Acceptance testing for JSON-Schema based validators like JSON::Schema
Version 0.0.2
This module allows the JSON Schema Test Suite tests to be used in perl to test a module that implements json-schema. These are the same tests that many modules (libraries, plugins, packages, etc.) use to confirm support of json-scheam. Using this module to confirm support gives assurance of interoperability with other modules that run the same tests in differnet languages.
In the JSON::Schema module, a test could look like the following:
use Test::More; use JSON::Schema; use Test::JSON::Schema::Acceptance; my $accepter = Test::JSON::Schema::Acceptance->new(3); # Skip tests which are known not to be supported or which cause problems. my $skip_tests = ['multiple extends', 'dependencies', 'ref']; $accepter->acceptance( sub{ my ( $schema, $input ) = @_; return JSON::Schema->new($schema)->validate($input); }, { skip_tests => $skip_tests } ); done_testing();
This would determine if JSON::Schema's validate method returns the right result for all of the cases in the JSON Schema Test Suite, except for those listed in $skip_tests.
validate
$skip_tests
JSON Schema is an IETF draft (at time of writing) which allows you to define the structure of JSON.
The abstract from draft 4 of the specification:
JSON::Schema is a perl module created independantly of the specification, which aims to implement the json-schema specification.
This module allows other perl modules (for example JSON::Schema) to test that they are json-schema compliant, by running the tests from the official test suite, without having to manually convert them to perl tests.
You are unliekly to want this module, unless you are attempting to write a module which implements json-schema the specification, and want to test your compliance.
Test::JSON::Schema::Acceptance->new($schema_version)
Create a new instance of Test::JSON::Schema::Acceptance.
Accepts optional argument of $schema_version. This determins the draft version of the schema to confirm compliance to. Default is draft 4 (current), but in the synopsis example, JSON::Schema is testing draft 3 compliance.
Accepts a sub and optional options in the form of a hash. The sub should return truthy or falsey depending on if the schema was valid for the input or not.
The only option which is currently accepted is skip_tests, which should be an array ref of tests you want to skip. You can skip a whole section of tests or individual tests. Any test name that contains any of the array refs items will be skipped, using grep. You can also skip a test by its number.
Ben Hutton (@relequestual), <relequest at cpan.org>
<relequest at cpan.org>
Please report any bugs or feature requests to via github at https://github.com/Relequestual/Test-JSON-Schema-Acceptance/issues.
Users' IRC: #json-schema on irc.perl.org
(click for instant chatroom login)
For questions about json-schema in general IRC: #json-schema on chat.freenode.net
You can also look for information at:
Github issues (report bugs here)
https://github.com/Relequestual/Test-JSON-Schema-Acceptance/issues
CPAN Ratings
http://cpanratings.perl.org/d/Test-JSON-Schema-Acceptance
Search Meta CPAN
http://search.cpan.org/pod/Test::JSON::Schema::Acceptance/
Daniel Perrett <perrettdl@cpan.org> for the concept and help in design.
Ricardo SIGNES <rjbs@cpan.org> for direction to and creation of Test::Fatal.
Various others in #perl-help.
Copyright 2015 Ben Hutton (@relequestual).
This program is distributed under the MIT (X11) License: http://www.opensource.org/licenses/mit-license.php
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 POD Errors
The following errors were encountered while parsing the POD:
=over should be: '=over' or '=over positive_number'
You forgot a '=back' before '=head1'
To install Test::JSON::Schema::Acceptance, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::JSON::Schema::Acceptance
CPAN shell
perl -MCPAN -e shell install Test::JSON::Schema::Acceptance
For more information on module installation, please visit the detailed CPAN module installation guide.