Skip to content

Commit

Permalink
Handle unsupported vocabularies in test and validate (#14)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti authored May 30, 2024
1 parent 495b65e commit e6b1bd5
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 28 deletions.
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
noa https://github.com/sourcemeta/noa 5ff4024902642afc9cc2f9a9e02ae9dff9d15d4f
jsontoolkit https://github.com/sourcemeta/jsontoolkit 466493636bdc27725ad5b171141410ec072919bc
jsontoolkit https://github.com/sourcemeta/jsontoolkit 503146c9412c040bcbcdb9a09a6da42c300d3435
hydra https://github.com/sourcemeta/hydra d5e0c314dae88b0bf2ac4eeff2c7395910e2c7e9
2 changes: 2 additions & 0 deletions src/command_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "command.h"
#include "utils.h"

// TODO: Add a flag to first validate schema against its metaschema
// TODO: Add a flag to prevent the use of HTTP resolution
auto intelligence::jsonschema::cli::test(
const std::span<const std::string> &arguments) -> int {
const auto options{parse_options(arguments, {})};
Expand Down
4 changes: 4 additions & 0 deletions src/command_validate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

#include <cstdlib> // EXIT_SUCCESS, EXIT_FAILURE
#include <iostream> // std::cerr
#include <set> // std::set
#include <string> // std::string

#include "command.h"
#include "utils.h"

// TODO: Add a flag to first validate schema against its metaschema
// TODO: Add a flag to emit output using the standard JSON Schema output format
// TODO: Add a flag to prevent the use of HTTP resolution
auto intelligence::jsonschema::cli::validate(
const std::span<const std::string> &arguments) -> int {
const auto options{parse_options(arguments, {})};
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ add_jsonschema_test_unix(format_cwd)
add_jsonschema_test_unix(frame)
add_jsonschema_test_unix(validate_pass)
add_jsonschema_test_unix(validate_fail)
add_jsonschema_test_unix(validate_non_supported)
add_jsonschema_test_unix(bundle_non_remote)
add_jsonschema_test_unix(bundle_remote_single_schema)
add_jsonschema_test_unix(test_single_pass)
add_jsonschema_test_unix(test_single_fail)
add_jsonschema_test_unix(test_single_unsupported)
39 changes: 39 additions & 0 deletions test/test_single_unsupported.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh

set -o errexit
set -o nounset

TMP="$(mktemp -d)"
# shellcheck disable=SC2317
clean() { rm -rf "$TMP"; }
trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"description": "My sample suite",
"schema": "https://json-schema.org/draft/2020-12/schema",
"tests": [
{
"description": "First test",
"valid": true,
"data": {}
},
{
"description": "Invalid type, expected to fail",
"valid": true,
"data": { "type": 1 }
}
]
}
EOF

"$1" test "$TMP/test.json" && CODE="$?" || CODE="$?"

if [ "$CODE" = "0" ]
then
echo "FAIL" 1>&2
exit 1
else
echo "PASS" 1>&2
exit 0
fi
36 changes: 36 additions & 0 deletions test/validate_non_supported.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

set -o errexit
set -o nounset

TMP="$(mktemp -d)"
# shellcheck disable=SC2317
clean() { rm -rf "$TMP"; }
trap clean EXIT

cat << 'EOF' > "$TMP/schema.json"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"foo": {
"type": "string"
}
}
}
EOF

cat << 'EOF' > "$TMP/instance.json"
{ "foo": 1 }
EOF

"$1" validate "$TMP/schema.json" "$TMP/instance.json" && CODE="$?" || CODE="$?"

if [ "$CODE" = "0" ]
then
echo "FAIL" 1>&2
exit 1
else
echo "PASS" 1>&2
exit 0
fi
1 change: 0 additions & 1 deletion vendor/jsontoolkit/src/jsonschema/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions vendor/jsontoolkit/src/jsonschema/default_compiler.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions vendor/jsontoolkit/src/jsonschema/default_compiler_2020_12.h

This file was deleted.

0 comments on commit e6b1bd5

Please sign in to comment.