Skip to content

Commit

Permalink
Rename $schema property to target in test cases (#125)
Browse files Browse the repository at this point in the history
See: #110
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jul 15, 2024
1 parent b789eea commit 04a906b
Show file tree
Hide file tree
Showing 30 changed files with 38 additions and 39 deletions.
2 changes: 1 addition & 1 deletion docs/test.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ To create a test definition, you must write JSON documents that look like this:

```json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"target": "http://json-schema.org/draft-04/schema#",
"$comment": "An arbitrary comment! Put whatever you want here",
"tests": [
{
Expand Down
13 changes: 6 additions & 7 deletions src/command_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ auto intelligence::jsonschema::cli::test(
return EXIT_FAILURE;
}

if (!test.defines("$schema")) {
if (!test.defines("target")) {
std::cout
<< "\nerror: The test document must contain a `$schema` property\n\n";
<< "\nerror: The test document must contain a `target` property\n\n";
std::cout << "Learn more here: "
"https://github.com/Intelligence-AI/jsonschema/blob/main/"
"docs/test.markdown\n";
return EXIT_FAILURE;
}

if (!test.at("$schema").is_string()) {
if (!test.at("target").is_string()) {
std::cout
<< "\nerror: The test document `$schema` property must be a URI\n\n";
<< "\nerror: The test document `target` property must be a URI\n\n";
std::cout << "Learn more here: "
"https://github.com/Intelligence-AI/jsonschema/blob/main/"
"docs/test.markdown\n";
Expand All @@ -65,15 +65,14 @@ auto intelligence::jsonschema::cli::test(
return EXIT_FAILURE;
}

const auto schema{test_resolver(test.at("$schema").to_string()).get()};
const auto schema{test_resolver(test.at("target").to_string()).get()};
if (!schema.has_value()) {
if (verbose) {
std::cout << "\n";
}

throw sourcemeta::jsontoolkit::SchemaResolutionError(
test.at("$schema").to_string(),
"Could not resolve schema under test");
test.at("target").to_string(), "Could not resolve schema under test");
}

unsigned int pass_count{0};
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_false_single_resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": [
{
"description": "First test",
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_false_single_resolve_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": [
{
"description": "First test",
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_multi_resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": [
{
"description": "First test",
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_multi_resolve_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": [
{
"description": "First test",
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_no_schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test "$CODE" = "1" || exit 1

cat << EOF > "$TMP/expected.txt"
$(realpath "$TMP")/test.json:
error: The test document must contain a \`\$schema\` property
error: The test document must contain a \`target\` property
Learn more here: https://github.com/Intelligence-AI/jsonschema/blob/main/docs/test.markdown
EOF
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_no_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://json-schema.org/draft/2020-12/schema"
"target": "https://json-schema.org/draft/2020-12/schema"
}
EOF

Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_not_object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trap clean EXIT
cat << 'EOF' > "$TMP/test.json"
[
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"target": "https://json-schema.org/draft/2020-12/schema",
"tests": [
{
"valid": true,
Expand Down
4 changes: 2 additions & 2 deletions test/test/fail_schema_non_string.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": 1,
"target": 1,
"tests": [
{
"valid": true,
Expand All @@ -29,7 +29,7 @@ test "$CODE" = "1" || exit 1

cat << EOF > "$TMP/expected.txt"
$(realpath "$TMP")/test.json:
error: The test document \`\$schema\` property must be a URI
error: The test document \`target\` property must be a URI
Learn more here: https://github.com/Intelligence-AI/jsonschema/blob/main/docs/test.markdown
EOF
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_test_case_no_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"target": "http://json-schema.org/draft-04/schema#",
"tests": [
{
"valid": true,
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_test_case_no_valid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"target": "http://json-schema.org/draft-04/schema#",
"tests": [
{
"data": {}
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_test_case_non_boolean_valid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"target": "http://json-schema.org/draft-04/schema#",
"tests": [
{
"data": {},
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_test_case_non_object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"target": "http://json-schema.org/draft-04/schema#",
"tests": [
{
"valid": true,
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_test_case_non_string_description.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"target": "http://json-schema.org/draft-04/schema#",
"tests": [
{
"description": "foo",
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_tests_non_array.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"target": "https://json-schema.org/draft/2020-12/schema",
"tests": {
"valid": true,
"data": {}
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_true_single_resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": [
{
"description": "First test",
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_true_single_resolve_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": [
{
"description": "First test",
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_unresolvable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com/unknown",
"target": "https://example.com/unknown",
"tests": [
{
"valid": true,
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_unsupported.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"target": "https://json-schema.org/draft/2020-12/schema",
"tests": [
{
"valid": true,
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_unsupported_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trap clean EXIT

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"target": "https://json-schema.org/draft/2020-12/schema",
"tests": [
{
"valid": true,
Expand Down
2 changes: 1 addition & 1 deletion test/test/pass_empty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": []
}
EOF
Expand Down
2 changes: 1 addition & 1 deletion test/test/pass_empty_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": []
}
EOF
Expand Down
4 changes: 2 additions & 2 deletions test/test/pass_multi_directory_resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mkdir "$TMP/tests"

cat << 'EOF' > "$TMP/tests/1.json"
{
"$schema": "https://example.com/1",
"target": "https://example.com/1",
"tests": [
{
"description": "First test",
Expand All @@ -47,7 +47,7 @@ EOF

cat << 'EOF' > "$TMP/tests/2.json"
{
"$schema": "https://example.com/2",
"target": "https://example.com/2",
"tests": [
{
"description": "First test",
Expand Down
4 changes: 2 additions & 2 deletions test/test/pass_multi_directory_resolve_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mkdir "$TMP/tests"

cat << 'EOF' > "$TMP/tests/1.json"
{
"$schema": "https://example.com/1",
"target": "https://example.com/1",
"tests": [
{
"description": "First test",
Expand All @@ -47,7 +47,7 @@ EOF

cat << 'EOF' > "$TMP/tests/2.json"
{
"$schema": "https://example.com/2",
"target": "https://example.com/2",
"tests": [
{
"description": "First test",
Expand Down
2 changes: 1 addition & 1 deletion test/test/pass_single_comment_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"$comment": "A random comment",
"tests": [
{
Expand Down
2 changes: 1 addition & 1 deletion test/test/pass_single_no_description_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": [
{
"valid": true,
Expand Down
2 changes: 1 addition & 1 deletion test/test/pass_single_no_test_description_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": [
{
"valid": true,
Expand Down
2 changes: 1 addition & 1 deletion test/test/pass_single_resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": [
{
"description": "First test",
Expand Down
2 changes: 1 addition & 1 deletion test/test/pass_single_resolve_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"target": "https://example.com",
"tests": [
{
"description": "First test",
Expand Down

0 comments on commit 04a906b

Please sign in to comment.