diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 126651595..fc25f1ac1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ add_executable(jsonschema_cli main.cc configure.h.in command.h - utils.h error.h logger.h configuration.h input.h resolver.h + utils.h error.h exit_code.h logger.h configuration.h input.h resolver.h command_fmt.cc command_inspect.cc command_bundle.cc diff --git a/src/command_bundle.cc b/src/command_bundle.cc index cc1e7d56b..c2114afff 100644 --- a/src/command_bundle.cc +++ b/src/command_bundle.cc @@ -73,6 +73,8 @@ auto sourcemeta::jsonschema::bundle(const sourcemeta::core::Options &options) } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( schema_path); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError(schema_path); } catch (const sourcemeta::core::SchemaError &error) { throw FileError(schema_path, error.what()); } diff --git a/src/command_canonicalize.cc b/src/command_canonicalize.cc index fd4962af0..62afd1637 100644 --- a/src/command_canonicalize.cc +++ b/src/command_canonicalize.cc @@ -70,6 +70,8 @@ auto sourcemeta::jsonschema::canonicalize( } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( schema_path); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError(schema_path); } catch (const sourcemeta::core::SchemaError &error) { throw FileError(schema_path, error.what()); } diff --git a/src/command_codegen.cc b/src/command_codegen.cc index 8cb91821a..47dfa6030 100644 --- a/src/command_codegen.cc +++ b/src/command_codegen.cc @@ -26,7 +26,7 @@ auto sourcemeta::jsonschema::codegen(const sourcemeta::core::Options &options) } if (!options.contains("target")) { - throw std::runtime_error{ + throw OptionConflictError{ "You must pass a target using the `--target/-t` option"}; } @@ -63,6 +63,8 @@ auto sourcemeta::jsonschema::codegen(const sourcemeta::core::Options &options) } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( schema_path); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError(schema_path); } catch (const sourcemeta::core::SchemaError &error) { throw FileError(schema_path, error.what()); } catch (const sourcemeta::core::SchemaVocabularyError &error) { @@ -76,6 +78,9 @@ auto sourcemeta::jsonschema::codegen(const sourcemeta::core::Options &options) throw FileError( schema_path, error.json(), error.pointer(), std::string{error.keyword()}, error.what()); + } catch (const sourcemeta::codegen::UnexpectedSchemaError &error) { + throw FileError( + schema_path, error.json(), error.pointer(), error.what()); } std::ostringstream output; diff --git a/src/command_compile.cc b/src/command_compile.cc index 0d1648fba..84dbb22f1 100644 --- a/src/command_compile.cc +++ b/src/command_compile.cc @@ -54,8 +54,14 @@ auto sourcemeta::jsonschema::compile(const sourcemeta::core::Options &options) frame.analyse(bundled, sourcemeta::core::schema_walker, custom_resolver, dialect, schema_default_id); - const auto entrypoint_uri{resolve_entrypoint( - frame, std::string{options.at("entrypoint").front()})}; + std::string entrypoint_uri; + try { + entrypoint_uri = resolve_entrypoint( + frame, std::string{options.at("entrypoint").front()}); + } catch (const sourcemeta::blaze::CompilerInvalidEntryPoint &error) { + throw FileError( + schema_path, error); + } schema_template = sourcemeta::blaze::compile( bundled, sourcemeta::core::schema_walker, custom_resolver, @@ -91,6 +97,8 @@ auto sourcemeta::jsonschema::compile(const sourcemeta::core::Options &options) } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( schema_path); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError(schema_path); } catch (const sourcemeta::core::SchemaError &error) { throw FileError(schema_path, error.what()); } diff --git a/src/command_fmt.cc b/src/command_fmt.cc index f1275a2a7..75f34ded9 100644 --- a/src/command_fmt.cc +++ b/src/command_fmt.cc @@ -88,6 +88,9 @@ auto sourcemeta::jsonschema::fmt(const sourcemeta::core::Options &options) } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( entry.resolution_base); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError( + entry.resolution_base); } catch (const sourcemeta::core::SchemaError &error) { throw FileError(entry.resolution_base, error.what()); @@ -118,8 +121,6 @@ auto sourcemeta::jsonschema::fmt(const sourcemeta::core::Options &options) << "\n"; } - // Report a different exit code for formatting check failures, to - // distinguish them from other errors - throw Fail{2}; + throw Fail{EXIT_EXPECTED_FAILURE}; } } diff --git a/src/command_inspect.cc b/src/command_inspect.cc index 45adad42f..d5458bf96 100644 --- a/src/command_inspect.cc +++ b/src/command_inspect.cc @@ -196,6 +196,8 @@ auto sourcemeta::jsonschema::inspect(const sourcemeta::core::Options &options) } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( schema_path); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError(schema_path); } catch (const sourcemeta::core::SchemaError &error) { throw FileError(schema_path, error.what()); } diff --git a/src/command_install.cc b/src/command_install.cc index 115f0da78..3035a08b5 100644 --- a/src/command_install.cc +++ b/src/command_install.cc @@ -3,7 +3,6 @@ #include // assert #include // std::uint8_t -#include // EXIT_FAILURE #include // std::filesystem #include // std::ofstream #include // std::cerr, std::cout @@ -130,11 +129,13 @@ auto output_json(sourcemeta::core::JSON &events_array) -> void { enum class OrphanedBehavior : std::uint8_t { Delete, Error }; -auto make_on_event(const sourcemeta::core::Options &options, bool &had_error, - const bool is_json, sourcemeta::core::JSON &events_array, +auto make_on_event(const sourcemeta::core::Options &options, + int &error_exit_code, const bool is_json, + sourcemeta::core::JSON &events_array, const OrphanedBehavior orphaned_behavior) -> sourcemeta::blaze::Configuration::FetchEvent::Callback { - return [&options, &had_error, is_json, &events_array, orphaned_behavior]( + return [&options, &error_exit_code, is_json, &events_array, + orphaned_behavior]( const sourcemeta::blaze::Configuration::FetchEvent &event) -> bool { using Type = sourcemeta::blaze::Configuration::FetchEvent::Type; @@ -217,7 +218,7 @@ auto make_on_event(const sourcemeta::core::Options &options, bool &had_error, break; case Type::Untracked: - had_error = true; + error_exit_code = sourcemeta::jsonschema::EXIT_EXPECTED_FAILURE; if (is_json) { emit_json(events_array, "untracked", "uri", event.uri); } else { @@ -235,12 +236,14 @@ auto make_on_event(const sourcemeta::core::Options &options, bool &had_error, if (orphaned_behavior == OrphanedBehavior::Delete) { std::filesystem::remove(event.path); } else { - had_error = true; + error_exit_code = sourcemeta::jsonschema::EXIT_EXPECTED_FAILURE; } break; case Type::Error: - had_error = true; + error_exit_code = orphaned_behavior == OrphanedBehavior::Error + ? sourcemeta::jsonschema::EXIT_EXPECTED_FAILURE + : sourcemeta::jsonschema::EXIT_OTHER_INPUT_ERROR; if (is_json) { auto json_event{sourcemeta::core::JSON::make_object()}; json_event.assign("type", sourcemeta::core::JSON{"error"}); @@ -433,10 +436,10 @@ auto sourcemeta::jsonschema::install(const sourcemeta::core::Options &options) return dependency_resolve(options, configuration, identifier); }}; - bool had_error{false}; - const auto on_event{make_on_event(options, had_error, is_json, events_array, - is_frozen ? OrphanedBehavior::Error - : OrphanedBehavior::Delete)}; + int error_exit_code{0}; + const auto on_event{make_on_event( + options, error_exit_code, is_json, events_array, + is_frozen ? OrphanedBehavior::Error : OrphanedBehavior::Delete)}; if (is_frozen) { configuration.fetch(lock, fetcher, resolver, configuration_reader, writer, @@ -454,8 +457,8 @@ auto sourcemeta::jsonschema::install(const sourcemeta::core::Options &options) output_json(events_array); } - if (had_error) { - throw Fail{EXIT_FAILURE}; + if (error_exit_code != 0) { + throw Fail{error_exit_code}; } if (!is_frozen) { diff --git a/src/command_lint.cc b/src/command_lint.cc index 35116be66..8824ec449 100644 --- a/src/command_lint.cc +++ b/src/command_lint.cc @@ -6,7 +6,7 @@ #include #include -#include // EXIT_FAILURE +#include // EXIT_SUCCESS #include // std::filesystem::current_path #include // std::ofstream, std::ifstream #include // std::cerr, std::cout @@ -174,6 +174,9 @@ static auto load_rule(sourcemeta::core::SchemaTransformer &bundle, } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw sourcemeta::jsonschema::FileError< sourcemeta::core::SchemaUnknownBaseDialectError>(rule_path); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw sourcemeta::jsonschema::FileError< + sourcemeta::core::SchemaUnknownDialectError>(rule_path); } catch (const sourcemeta::core::SchemaResolutionError &error) { throw sourcemeta::jsonschema::FileError< sourcemeta::core::SchemaResolutionError>(rule_path, error); @@ -353,7 +356,7 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options) } scores.emplace_back(apply_result.second); if (!apply_result.first) { - return 2; + return EXIT_EXPECTED_FAILURE; } return EXIT_SUCCESS; @@ -407,6 +410,13 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options) throw FileError( entry.resolution_base); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + if (printed_progress) { + std::cerr << "\n"; + } + + throw FileError( + entry.resolution_base); } catch (const sourcemeta::core::SchemaResolutionError &error) { if (printed_progress) { std::cerr << "\n"; @@ -423,7 +433,8 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options) } }); - if (wrapper_result == EXIT_SUCCESS || wrapper_result == 2) { + if (wrapper_result == EXIT_SUCCESS || + wrapper_result == EXIT_EXPECTED_FAILURE) { if (wrapper_result != EXIT_SUCCESS) { result = false; } @@ -452,8 +463,7 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options) output << "\n"; } } else { - // Exception was caught - exit immediately with error code 1 - throw Fail{EXIT_FAILURE}; + throw Fail{wrapper_result}; } } } else { @@ -482,7 +492,7 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options) return EXIT_SUCCESS; } else { // Return 2 for logical lint failures - return 2; + return EXIT_EXPECTED_FAILURE; } } catch ( const sourcemeta::blaze::CompilerReferenceTargetNotSchemaError @@ -499,18 +509,19 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options) } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( entry.resolution_base); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError( + entry.resolution_base); } catch (const sourcemeta::core::SchemaResolutionError &error) { throw FileError( entry.resolution_base, error); } }); - if (wrapper_result == 2) { - // Logical lint failure + if (wrapper_result == EXIT_EXPECTED_FAILURE) { result = false; } else if (wrapper_result != EXIT_SUCCESS) { - // Exception was caught - exit immediately with error code 1 - throw Fail{EXIT_FAILURE}; + throw Fail{wrapper_result}; } } } @@ -541,8 +552,6 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options) } if (!result) { - // Report a different exit code for linting failures, to - // distinguish them from other errors - throw Fail{2}; + throw Fail{EXIT_EXPECTED_FAILURE}; } } diff --git a/src/command_metaschema.cc b/src/command_metaschema.cc index 8f8cd9fed..89abe4575 100644 --- a/src/command_metaschema.cc +++ b/src/command_metaschema.cc @@ -117,12 +117,13 @@ auto sourcemeta::jsonschema::metaschema( } catch (const sourcemeta::core::SchemaResolutionError &error) { throw FileError( entry.resolution_base, error); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError( + entry.resolution_base); } } if (!result) { - // Report a different exit code for validation failures, to - // distinguish them from other errors - throw Fail{2}; + throw Fail{EXIT_EXPECTED_FAILURE}; } } diff --git a/src/command_test.cc b/src/command_test.cc index 4d2624e6f..20f98534a 100644 --- a/src/command_test.cc +++ b/src/command_test.cc @@ -5,7 +5,6 @@ #include #include // std::chrono -#include // EXIT_FAILURE #include // std::cerr, std::cout #include // std::ostringstream #include // std::string @@ -67,6 +66,12 @@ auto parse_test_suite(const sourcemeta::jsonschema::InputJSON &entry, } throw sourcemeta::jsonschema::FileError< sourcemeta::core::SchemaUnknownBaseDialectError>{entry.resolution_base}; + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + if (!json_output) { + std::cout << entry.first << ":\n"; + } + throw sourcemeta::jsonschema::FileError< + sourcemeta::core::SchemaUnknownDialectError>{entry.resolution_base}; } catch (...) { if (!json_output) { std::cout << entry.first << ":\n"; @@ -157,7 +162,8 @@ auto report_as_text(const sourcemeta::core::Options &options) -> void { } if (!result) { - throw sourcemeta::jsonschema::Fail{2}; + throw sourcemeta::jsonschema::Fail{ + sourcemeta::jsonschema::EXIT_EXPECTED_FAILURE}; } } @@ -313,7 +319,8 @@ auto report_as_ctrf(const sourcemeta::core::Options &options) -> void { std::cout << "\n"; if (!result) { - throw sourcemeta::jsonschema::Fail{2}; + throw sourcemeta::jsonschema::Fail{ + sourcemeta::jsonschema::EXIT_EXPECTED_FAILURE}; } } diff --git a/src/command_validate.cc b/src/command_validate.cc index 381029149..6a997b9ce 100644 --- a/src/command_validate.cc +++ b/src/command_validate.cc @@ -165,7 +165,7 @@ auto sourcemeta::jsonschema::validate(const sourcemeta::core::Options &options) const auto benchmark{options.contains("benchmark")}; const auto benchmark_loop{parse_loop(options)}; if (benchmark_loop == 0) { - throw std::runtime_error("The loop number cannot be zero"); + throw OptionConflictError{"The loop number cannot be zero"}; } const auto trace{options.contains("trace")}; @@ -203,6 +203,8 @@ auto sourcemeta::jsonschema::validate(const sourcemeta::core::Options &options) } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( schema_path); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError(schema_path); } catch (const sourcemeta::core::SchemaError &error) { throw FileError(schema_path, error.what()); } catch ( @@ -232,6 +234,8 @@ auto sourcemeta::jsonschema::validate(const sourcemeta::core::Options &options) } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( schema_path); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError(schema_path); } catch (const sourcemeta::core::SchemaError &error) { throw FileError(schema_path, error.what()); } @@ -277,6 +281,8 @@ auto sourcemeta::jsonschema::validate(const sourcemeta::core::Options &options) } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( schema_path); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError(schema_path); } catch (const sourcemeta::core::SchemaError &error) { throw FileError(schema_path, error.what()); } @@ -295,30 +301,30 @@ auto sourcemeta::jsonschema::validate(const sourcemeta::core::Options &options) } if (trace && instance_arguments.size() > 1) { - throw std::runtime_error{ + throw OptionConflictError{ "The `--trace/-t` option is only allowed given a single instance"}; } if (benchmark && instance_arguments.size() > 1) { - throw std::runtime_error{ + throw OptionConflictError{ "The `--benchmark/-b` option is only allowed given a single instance"}; } for (const auto &instance_path_view : instance_arguments) { const std::filesystem::path instance_path{instance_path_view}; if (trace && instance_path.extension() == ".jsonl") { - throw std::runtime_error{ + throw OptionConflictError{ "The `--trace/-t` option is only allowed given a single instance"}; } if (trace && std::filesystem::is_directory(instance_path)) { - throw std::runtime_error{ + throw OptionConflictError{ "The `--trace/-t` option is only allowed given a single instance"}; } if (benchmark && std::filesystem::is_directory(instance_path)) { - throw std::runtime_error{"The `--benchmark/-b` option is only allowed " - "given a single instance"}; + throw OptionConflictError{"The `--benchmark/-b` option is only allowed " + "given a single instance"}; } if (std::filesystem::is_directory(instance_path) || instance_path.extension() == ".jsonl" || @@ -459,8 +465,6 @@ auto sourcemeta::jsonschema::validate(const sourcemeta::core::Options &options) } if (!result) { - // Report a different exit code for validation failures, to - // distinguish them from other errors - throw Fail{2}; + throw Fail{EXIT_EXPECTED_FAILURE}; } } diff --git a/src/error.h b/src/error.h index b57203550..b58ac92d7 100644 --- a/src/error.h +++ b/src/error.h @@ -8,9 +8,9 @@ #include #include #include +#include #include -#include // EXIT_FAILURE #include // std::filesystem #include // std::function #include // std::initializer_list @@ -21,6 +21,8 @@ #include // std::is_base_of_v #include // std::vector +#include "exit_code.h" + namespace sourcemeta::jsonschema { class PositionalArgumentError : public std::runtime_error { @@ -455,7 +457,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, } catch (const InstallError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch (const ConfigurationNotFoundError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -465,43 +467,43 @@ inline auto try_catch(const sourcemeta::core::Options &options, "docs/install.markdown\n"; } - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch (const LockNotFoundError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch (const LockParseError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch (const NotSchemaError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch (const YAMLInputError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_NOT_SUPPORTED; } catch (const InvalidLintRuleError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_INVALID_CLI_ARGUMENTS; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch (const InvalidIncludeIdentifier &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_INVALID_CLI_ARGUMENTS; } catch (const LintAutoFixError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -520,7 +522,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, std::cerr << "https://github.com/sourcemeta/jsonschema/issues\n"; } - return EXIT_FAILURE; + return EXIT_UNEXPECTED_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -531,7 +533,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, "docs/test.markdown\n"; } - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch ( const FileError &error) { @@ -550,7 +552,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, } } - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch ( const FileError &error) { const auto is_json{options.contains("json")}; @@ -560,21 +562,21 @@ inline auto try_catch(const sourcemeta::core::Options &options, << "\nUse the `inspect` command to find valid schema locations\n"; } - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch ( const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -588,7 +590,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, } } - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch ( const FileError &error) { const auto is_json{options.contains("json")}; @@ -603,7 +605,22 @@ inline auto try_catch(const sourcemeta::core::Options &options, "`--default-dialect/-d`\n"; } - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; + } catch ( + const FileError &error) { + const auto is_json{options.contains("json")}; + print_exception(is_json, error); + if (!is_json) { + std::cerr << "\nAre you sure the input is a valid JSON Schema and its " + "dialect is known?\n"; + std::cerr + << "If the input does not declare the `$schema` keyword, you might " + "want to\n"; + std::cerr << "explicitly declare a default dialect using " + "`--default-dialect/-d`\n"; + } + + return EXIT_SCHEMA_INPUT_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -612,48 +629,52 @@ inline auto try_catch(const sourcemeta::core::Options &options, "valid according to its meta-schema?\n"; } - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_SCHEMA_INPUT_ERROR; } catch ( const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_NOT_SUPPORTED; } catch (const FileError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_NOT_SUPPORTED; + } catch (const FileError &error) { + const auto is_json{options.contains("json")}; + print_exception(is_json, error); + return EXIT_NOT_SUPPORTED; } catch (const sourcemeta::core::JSONFileParseError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch (const sourcemeta::core::JSONParseError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; // Command line parsing handling } catch (const OptionConflictError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_INVALID_CLI_ARGUMENTS; } catch (const InvalidOptionEnumerationValueError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -661,7 +682,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, std::cerr << "\nRun the `help` command for usage information\n"; } - return EXIT_FAILURE; + return EXIT_INVALID_CLI_ARGUMENTS; } catch (const PositionalArgumentError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -669,7 +690,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, std::cerr << "\nFor example: " << error.example() << "\n"; } - return EXIT_FAILURE; + return EXIT_INVALID_CLI_ARGUMENTS; } catch (const UnknownCommandError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -677,7 +698,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, std::cerr << "\nRun the `help` command for usage information\n"; } - return EXIT_FAILURE; + return EXIT_INVALID_CLI_ARGUMENTS; } catch (const sourcemeta::core::OptionsUnexpectedValueFlagError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -685,7 +706,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, std::cerr << "\nRun the `help` command for usage information\n"; } - return EXIT_FAILURE; + return EXIT_INVALID_CLI_ARGUMENTS; } catch (const sourcemeta::core::OptionsMissingOptionValueError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -693,7 +714,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, std::cerr << "\nRun the `help` command for usage information\n"; } - return EXIT_FAILURE; + return EXIT_INVALID_CLI_ARGUMENTS; } catch (const sourcemeta::core::OptionsUnknownOptionError &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); @@ -701,17 +722,17 @@ inline auto try_catch(const sourcemeta::core::Options &options, std::cerr << "\nRun the `help` command for usage information\n"; } - return EXIT_FAILURE; + return EXIT_INVALID_CLI_ARGUMENTS; // Standard library handlers } catch (const std::filesystem::filesystem_error &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_OTHER_INPUT_ERROR; } catch (const std::runtime_error &error) { const auto is_json{options.contains("json")}; print_exception(is_json, error); - return EXIT_FAILURE; + return EXIT_UNEXPECTED_ERROR; } catch (const std::exception &error) { const auto is_json{options.contains("json")}; if (is_json) { @@ -725,7 +746,7 @@ inline auto try_catch(const sourcemeta::core::Options &options, << "https://github.com/sourcemeta/jsonschema\n"; } - return EXIT_FAILURE; + return EXIT_UNEXPECTED_ERROR; } } diff --git a/src/exit_code.h b/src/exit_code.h new file mode 100644 index 000000000..76861feca --- /dev/null +++ b/src/exit_code.h @@ -0,0 +1,15 @@ +#ifndef SOURCEMETA_JSONSCHEMA_CLI_EXIT_CODE_H_ +#define SOURCEMETA_JSONSCHEMA_CLI_EXIT_CODE_H_ + +namespace sourcemeta::jsonschema { + +constexpr int EXIT_UNEXPECTED_ERROR = 1; +constexpr int EXIT_EXPECTED_FAILURE = 2; +constexpr int EXIT_NOT_SUPPORTED = 3; +constexpr int EXIT_SCHEMA_INPUT_ERROR = 4; +constexpr int EXIT_INVALID_CLI_ARGUMENTS = 5; +constexpr int EXIT_OTHER_INPUT_ERROR = 6; + +} // namespace sourcemeta::jsonschema + +#endif diff --git a/src/main.cc b/src/main.cc index 5df42b68a..b3776c111 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,7 +1,7 @@ #include #include -#include // EXIT_FAILURE, EXIT_SUCCESS +#include // EXIT_SUCCESS #include // std::filesystem #include // std::cerr, std::cout #include // std::string diff --git a/src/resolver.h b/src/resolver.h index 5f4f89e64..bfc0511f9 100644 --- a/src/resolver.h +++ b/src/resolver.h @@ -212,6 +212,9 @@ class CustomResolver { } catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) { throw FileError( entry.resolution_base); + } catch (const sourcemeta::core::SchemaUnknownDialectError &) { + throw FileError( + entry.resolution_base); } catch (const sourcemeta::core::SchemaRelativeMetaschemaResolutionError &error) { throw FileError< diff --git a/test/bundle/fail_default_dialect_config_extension_mismatch.sh b/test/bundle/fail_default_dialect_config_extension_mismatch.sh index c39a7ba71..d3856ad7a 100755 --- a/test/bundle/fail_default_dialect_config_extension_mismatch.sh +++ b/test/bundle/fail_default_dialect_config_extension_mismatch.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/jsonschema.json" } EOF -"$1" bundle "$TMP/document.json" --verbose 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" bundle "$TMP/document.json" --verbose 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema @@ -33,8 +34,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" bundle "$TMP/document.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" bundle "$TMP/document.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/bundle/fail_invalid_id_type.sh b/test/bundle/fail_invalid_id_type.sh index 121e35b54..b91951a2c 100755 --- a/test/bundle/fail_invalid_id_type.sh +++ b/test/bundle/fail_invalid_id_type.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" bundle "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" bundle "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema identifier is invalid diff --git a/test/bundle/fail_invalid_schema_uri.sh b/test/bundle/fail_invalid_schema_uri.sh index bb92c14f1..66af7195d 100755 --- a/test/bundle/fail_invalid_schema_uri.sh +++ b/test/bundle/fail_invalid_schema_uri.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" bundle "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" bundle "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The dialect is not a valid URI diff --git a/test/bundle/fail_no_schema.sh b/test/bundle/fail_no_schema.sh index e4b53f00c..a9d000263 100755 --- a/test/bundle/fail_no_schema.sh +++ b/test/bundle/fail_no_schema.sh @@ -7,8 +7,9 @@ TMP="$(mktemp -d)" clean() { rm -rf "$TMP"; } trap clean EXIT -"$1" bundle 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" bundle 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: This command expects a path to a schema @@ -19,8 +20,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" bundle --json > "$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" bundle --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/bundle/fail_relative_external_ref_missing.sh b/test/bundle/fail_relative_external_ref_missing.sh index 7c0e334c1..9ed1b1c12 100755 --- a/test/bundle/fail_relative_external_ref_missing.sh +++ b/test/bundle/fail_relative_external_ref_missing.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" bundle "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" bundle "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the reference to an external schema @@ -31,8 +32,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" bundle "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" bundle "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/bundle/fail_resolve_duplicate.sh b/test/bundle/fail_resolve_duplicate.sh index af5e04052..ffcad8480 100755 --- a/test/bundle/fail_resolve_duplicate.sh +++ b/test/bundle/fail_resolve_duplicate.sh @@ -41,8 +41,9 @@ EOF "$1" bundle "$TMP/schema.json" \ --resolve "$TMP/schemas" 2>"$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Cannot register the same identifier twice @@ -55,8 +56,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" bundle "$TMP/schema.json" \ --resolve "$TMP/schemas" --json >"$TMP/stdout.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/bundle/fail_resolve_invalid_json.sh b/test/bundle/fail_resolve_invalid_json.sh index b5f6f9b5a..fc6333eae 100755 --- a/test/bundle/fail_resolve_invalid_json.sh +++ b/test/bundle/fail_resolve_invalid_json.sh @@ -23,8 +23,9 @@ EOF "$1" bundle "$TMP/schema.json" \ --resolve "$TMP/invalid.json" 2>"$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -38,8 +39,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" bundle "$TMP/schema.json" \ --resolve "$TMP/invalid.json" --json >"$TMP/stdout.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/bundle/fail_schema_invalid_json.sh b/test/bundle/fail_schema_invalid_json.sh index 2ca1cd16b..93f65ed84 100755 --- a/test/bundle/fail_schema_invalid_json.sh +++ b/test/bundle/fail_schema_invalid_json.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" bundle "$TMP/schema.json" 2>"$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -28,8 +29,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" bundle "$TMP/schema.json" --json >"$TMP/stdout.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/bundle/fail_unknown_metaschema.sh b/test/bundle/fail_unknown_metaschema.sh index 788ed1c67..6391c5126 100755 --- a/test/bundle/fail_unknown_metaschema.sh +++ b/test/bundle/fail_unknown_metaschema.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" bundle "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" bundle "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the metaschema of the schema @@ -31,8 +32,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" bundle "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" bundle "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/canonicalize/fail_invalid_id_type.sh b/test/canonicalize/fail_invalid_id_type.sh index 5079d2580..2251f012a 100755 --- a/test/canonicalize/fail_invalid_id_type.sh +++ b/test/canonicalize/fail_invalid_id_type.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" canonicalize "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" canonicalize "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema identifier is invalid diff --git a/test/canonicalize/fail_invalid_schema_uri.sh b/test/canonicalize/fail_invalid_schema_uri.sh index b83cd0d0a..bd8ab9331 100755 --- a/test/canonicalize/fail_invalid_schema_uri.sh +++ b/test/canonicalize/fail_invalid_schema_uri.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" canonicalize "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" canonicalize "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The dialect is not a valid URI diff --git a/test/canonicalize/fail_no_schema.sh b/test/canonicalize/fail_no_schema.sh index c30292f30..23ccdba2b 100755 --- a/test/canonicalize/fail_no_schema.sh +++ b/test/canonicalize/fail_no_schema.sh @@ -7,8 +7,9 @@ TMP="$(mktemp -d)" clean() { rm -rf "$TMP"; } trap clean EXIT -"$1" canonicalize 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" canonicalize 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: This command expects a path to a schema @@ -19,8 +20,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" canonicalize --json >"$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" canonicalize --json >"$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/canonicalize/fail_non_schema.sh b/test/canonicalize/fail_non_schema.sh index eded40ca1..8935dd929 100755 --- a/test/canonicalize/fail_non_schema.sh +++ b/test/canonicalize/fail_non_schema.sh @@ -11,8 +11,9 @@ cat << 'EOF' > "$TMP/not_a_schema.json" [ 1, 2, 3 ] EOF -"$1" canonicalize "$TMP/not_a_schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" canonicalize "$TMP/not_a_schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema file you provided does not represent a valid JSON Schema @@ -22,8 +23,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" canonicalize "$TMP/not_a_schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" canonicalize "$TMP/not_a_schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/canonicalize/fail_unknown_metaschema.sh b/test/canonicalize/fail_unknown_metaschema.sh index 8bb9b899c..a55995772 100755 --- a/test/canonicalize/fail_unknown_metaschema.sh +++ b/test/canonicalize/fail_unknown_metaschema.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" canonicalize "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" canonicalize "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the metaschema of the schema @@ -28,8 +29,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" canonicalize "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" canonicalize "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/ci/fail_bundle_http_non_200.sh b/test/ci/fail_bundle_http_non_200.sh index 754af58ca..6deb73f6b 100755 --- a/test/ci/fail_bundle_http_non_200.sh +++ b/test/ci/fail_bundle_http_non_200.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" bundle "$TMP/schema.json" --http 2> "$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document diff --git a/test/ci/fail_bundle_http_non_schema.sh b/test/ci/fail_bundle_http_non_schema.sh index 7389df620..78af232aa 100755 --- a/test/ci/fail_bundle_http_non_schema.sh +++ b/test/ci/fail_bundle_http_non_schema.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" bundle "$TMP/schema.json" --http 2> "$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The JSON document is not a valid JSON Schema diff --git a/test/ci/fail_validate_http_non_200.sh b/test/ci/fail_validate_http_non_200.sh index 547a5e843..111f5eca0 100755 --- a/test/ci/fail_validate_http_non_200.sh +++ b/test/ci/fail_validate_http_non_200.sh @@ -21,8 +21,9 @@ cat << 'EOF' > "$TMP/instance.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" --http 2> "$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document diff --git a/test/ci/fail_validate_http_non_schema.sh b/test/ci/fail_validate_http_non_schema.sh index 6e1168652..15e2ffa74 100755 --- a/test/ci/fail_validate_http_non_schema.sh +++ b/test/ci/fail_validate_http_non_schema.sh @@ -21,8 +21,9 @@ cat << 'EOF' > "$TMP/instance.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" --http 2> "$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The JSON document is not a valid JSON Schema diff --git a/test/ci/precommit_lint.sh b/test/ci/precommit_lint.sh index 78457c1ff..88a04960e 100755 --- a/test/ci/precommit_lint.sh +++ b/test/ci/precommit_lint.sh @@ -37,7 +37,7 @@ cd "$TMP" pre-commit install PATH="$ROOT/bin:$PATH" \ pre-commit run --files schema.json > "$TMP/out.txt" 2>&1 \ - && CODE="$?" || CODE="$?" + && EXIT_CODE="$?" || EXIT_CODE="$?" cat "$TMP/out.txt" -test "$CODE" = "1" || exit 1 +test "$EXIT_CODE" = "1" || exit 1 grep -q "enum_with_type" "$TMP/out.txt" || exit 1 diff --git a/test/codegen/fail_default_dialect_config_extension_mismatch.sh b/test/codegen/fail_default_dialect_config_extension_mismatch.sh index 0eefd1f1e..f11826377 100755 --- a/test/codegen/fail_default_dialect_config_extension_mismatch.sh +++ b/test/codegen/fail_default_dialect_config_extension_mismatch.sh @@ -19,8 +19,9 @@ cat << 'EOF' > "$TMP/jsonschema.json" EOF "$1" codegen "$TMP/document.json" --target typescript --verbose \ - 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema @@ -35,8 +36,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" codegen "$TMP/document.json" --target typescript --json \ - >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/codegen/fail_invalid_id_type.sh b/test/codegen/fail_invalid_id_type.sh index e908cfc06..e0c6cdd23 100755 --- a/test/codegen/fail_invalid_id_type.sh +++ b/test/codegen/fail_invalid_id_type.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" codegen "$TMP/schema.json" --target typescript >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" codegen "$TMP/schema.json" --target typescript >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema identifier is invalid diff --git a/test/codegen/fail_invalid_schema_uri.sh b/test/codegen/fail_invalid_schema_uri.sh index 78b03b3ee..e2b62b4af 100755 --- a/test/codegen/fail_invalid_schema_uri.sh +++ b/test/codegen/fail_invalid_schema_uri.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" codegen "$TMP/schema.json" --target typescript >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" codegen "$TMP/schema.json" --target typescript >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The dialect is not a valid URI diff --git a/test/codegen/fail_invalid_target.sh b/test/codegen/fail_invalid_target.sh index 69937d1d0..bc40b4600 100755 --- a/test/codegen/fail_invalid_target.sh +++ b/test/codegen/fail_invalid_target.sh @@ -15,8 +15,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" codegen "$TMP/schema.json" --target foo \ - 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: Unknown code generation target @@ -31,8 +32,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" codegen "$TMP/schema.json" --target foo --json \ - >"$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/codegen/fail_missing_target.sh b/test/codegen/fail_missing_target.sh index 5417dd586..66c0f8acc 100755 --- a/test/codegen/fail_missing_target.sh +++ b/test/codegen/fail_missing_target.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" codegen "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" codegen "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: You must pass a target using the `--target/-t` option @@ -25,8 +26,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" codegen "$TMP/schema.json" --json \ - >"$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/codegen/fail_no_schema.sh b/test/codegen/fail_no_schema.sh index ad75deae7..a08e2d0a5 100755 --- a/test/codegen/fail_no_schema.sh +++ b/test/codegen/fail_no_schema.sh @@ -7,8 +7,9 @@ TMP="$(mktemp -d)" clean() { rm -rf "$TMP"; } trap clean EXIT -"$1" codegen 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" codegen 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: This command expects a path to a schema @@ -19,8 +20,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" codegen --json > "$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" codegen --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/codegen/fail_schema_invalid_json.sh b/test/codegen/fail_schema_invalid_json.sh index 6a335e850..8b4681e07 100755 --- a/test/codegen/fail_schema_invalid_json.sh +++ b/test/codegen/fail_schema_invalid_json.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" codegen "$TMP/schema.json" --target typescript 2>"$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -28,8 +29,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" codegen "$TMP/schema.json" --target typescript --json >"$TMP/stdout.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/codegen/fail_unknown_metaschema.sh b/test/codegen/fail_unknown_metaschema.sh index 019aee007..708a394fb 100755 --- a/test/codegen/fail_unknown_metaschema.sh +++ b/test/codegen/fail_unknown_metaschema.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" codegen "$TMP/schema.json" --target typescript \ - 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the metaschema of the schema @@ -33,8 +34,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" codegen "$TMP/schema.json" --target typescript --json \ - >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/codegen/fail_unsupported_keyword.sh b/test/codegen/fail_unsupported_keyword.sh index 5f9b60afe..2c2682d36 100755 --- a/test/codegen/fail_unsupported_keyword.sh +++ b/test/codegen/fail_unsupported_keyword.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" codegen "$TMP/schema.json" --target typescript \ - 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" error: Unsupported keyword in subschema @@ -30,8 +31,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" codegen "$TMP/schema.json" --target typescript --json \ - >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/codegen/fail_unsupported_keyword_value.sh b/test/codegen/fail_unsupported_keyword_value.sh index 21a0e9e1d..e634c5e27 100755 --- a/test/codegen/fail_unsupported_keyword_value.sh +++ b/test/codegen/fail_unsupported_keyword_value.sh @@ -15,8 +15,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" codegen "$TMP/schema.json" --target typescript \ - 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 # TODO: This error message is pretty bad. Can we do better somehow? @@ -30,8 +31,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" codegen "$TMP/schema.json" --target typescript --json \ - >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/codegen/fail_unsupported_schema.sh b/test/codegen/fail_unsupported_schema.sh index 7998e5af3..67bdabf98 100755 --- a/test/codegen/fail_unsupported_schema.sh +++ b/test/codegen/fail_unsupported_schema.sh @@ -7,10 +7,6 @@ TMP="$(mktemp -d)" clean() { rm -rf "$TMP"; } trap clean EXIT -# This error is not handled specifically by the CLI because ideally it would -# never happen. It is only thrown due to temporary limitations in the codegen -# module, and should be resolved as the module matures. - cat << 'EOF' > "$TMP/schema.json" { "$schema": "https://json-schema.org/draft/2020-12/schema", @@ -19,24 +15,26 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" codegen "$TMP/schema.json" --target typescript \ - 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 -cat << 'EOF' > "$TMP/expected.txt" -unexpected error: Unsupported schema -Please report it at https://github.com/sourcemeta/jsonschema +cat << EOF > "$TMP/expected.txt" +error: Unsupported schema + at file path $(realpath "$TMP")/schema.json EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" -# JSON error "$1" codegen "$TMP/schema.json" --target typescript --json \ - >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 -cat << 'EOF' > "$TMP/expected.txt" +cat << EOF > "$TMP/expected.txt" { - "error": "Unsupported schema" + "error": "Unsupported schema", + "filePath": "$(realpath "$TMP")/schema.json" } EOF diff --git a/test/codegen/fail_unsupported_vocabulary.sh b/test/codegen/fail_unsupported_vocabulary.sh index d989c3eb2..2860d1c91 100755 --- a/test/codegen/fail_unsupported_vocabulary.sh +++ b/test/codegen/fail_unsupported_vocabulary.sh @@ -15,8 +15,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" codegen "$TMP/schema.json" --target typescript \ - 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Unsupported required vocabulary @@ -28,8 +29,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" codegen "$TMP/schema.json" --target typescript --json \ - >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/compile/fail_default_dialect_config_extension_mismatch.sh b/test/compile/fail_default_dialect_config_extension_mismatch.sh index 8f52e5fa4..bafd0edae 100755 --- a/test/compile/fail_default_dialect_config_extension_mismatch.sh +++ b/test/compile/fail_default_dialect_config_extension_mismatch.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/jsonschema.json" } EOF -"$1" compile "$TMP/document.json" --verbose 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile "$TMP/document.json" --verbose 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema @@ -33,8 +34,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" compile "$TMP/document.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile "$TMP/document.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/compile/fail_draft4_x_keyword_ref_target.sh b/test/compile/fail_draft4_x_keyword_ref_target.sh index fea8a172a..fc3bd86d4 100755 --- a/test/compile/fail_draft4_x_keyword_ref_target.sh +++ b/test/compile/fail_draft4_x_keyword_ref_target.sh @@ -29,8 +29,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" compile "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The referenced schema is not considered to be a valid subschema given the dialect and vocabularies in use @@ -44,8 +45,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" compile "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/compile/fail_draft7_defs_ref_target.sh b/test/compile/fail_draft7_defs_ref_target.sh index 0e1bf5bfc..dec2dcb34 100755 --- a/test/compile/fail_draft7_defs_ref_target.sh +++ b/test/compile/fail_draft7_defs_ref_target.sh @@ -21,8 +21,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" compile "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The referenced schema is not considered to be a valid subschema given the dialect and vocabularies in use @@ -36,8 +37,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" compile "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/compile/fail_entrypoint_invalid_pointer.sh b/test/compile/fail_entrypoint_invalid_pointer.sh index 3c6f0c76d..5661e71bd 100755 --- a/test/compile/fail_entrypoint_invalid_pointer.sh +++ b/test/compile/fail_entrypoint_invalid_pointer.sh @@ -16,8 +16,9 @@ EOF "$1" compile "$TMP/schema.json" \ --entrypoint '/nonexistent' > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The given entry point URI does not exist in the schema @@ -31,8 +32,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" compile "$TMP/schema.json" \ --entrypoint '/nonexistent' --json > "$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/compile/fail_entrypoint_invalid_pointer_escape.sh b/test/compile/fail_entrypoint_invalid_pointer_escape.sh index ffa619371..85077c846 100755 --- a/test/compile/fail_entrypoint_invalid_pointer_escape.sh +++ b/test/compile/fail_entrypoint_invalid_pointer_escape.sh @@ -16,8 +16,9 @@ EOF "$1" compile "$TMP/schema.json" \ --entrypoint '/foo~bar' > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The given entry point URI does not exist in the schema @@ -31,8 +32,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" compile "$TMP/schema.json" \ --entrypoint '/foo~bar' --json > "$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/compile/fail_entrypoint_invalid_uri.sh b/test/compile/fail_entrypoint_invalid_uri.sh index 697c8231a..945b68d09 100755 --- a/test/compile/fail_entrypoint_invalid_uri.sh +++ b/test/compile/fail_entrypoint_invalid_uri.sh @@ -17,8 +17,9 @@ EOF "$1" compile "$TMP/schema.json" \ --entrypoint 'https://example.com/nonexistent' > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The given entry point URI does not exist in the schema @@ -32,8 +33,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" compile "$TMP/schema.json" \ --entrypoint 'https://example.com/nonexistent' --json > "$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/compile/fail_entrypoint_invalid_uri_parse.sh b/test/compile/fail_entrypoint_invalid_uri_parse.sh index c3475b068..9c05ad614 100755 --- a/test/compile/fail_entrypoint_invalid_uri_parse.sh +++ b/test/compile/fail_entrypoint_invalid_uri_parse.sh @@ -16,8 +16,9 @@ EOF "$1" compile "$TMP/schema.json" \ --entrypoint 'https://example.com/foo bar' > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The given entry point is not a valid URI or JSON Pointer @@ -31,8 +32,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" compile "$TMP/schema.json" \ --entrypoint 'https://example.com/foo bar' --json > "$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/compile/fail_include_invalid_identifier.sh b/test/compile/fail_include_invalid_identifier.sh index 5f3ca8d95..e3d16f4c3 100755 --- a/test/compile/fail_include_invalid_identifier.sh +++ b/test/compile/fail_include_invalid_identifier.sh @@ -17,8 +17,9 @@ EOF # Test with hyphen (invalid) "$1" compile "$TMP/schema.json" --include my-schema 2>"$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: The include identifier is not a valid C/C++ identifier @@ -29,8 +30,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" compile "$TMP/schema.json" --include my-schema --json > "$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/compile/fail_invalid_id_type.sh b/test/compile/fail_invalid_id_type.sh index 6c36e25ca..de38202df 100755 --- a/test/compile/fail_invalid_id_type.sh +++ b/test/compile/fail_invalid_id_type.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" compile "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema identifier is invalid diff --git a/test/compile/fail_invalid_schema_uri.sh b/test/compile/fail_invalid_schema_uri.sh index 00782fb2a..18b0b021a 100755 --- a/test/compile/fail_invalid_schema_uri.sh +++ b/test/compile/fail_invalid_schema_uri.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" compile "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The dialect is not a valid URI diff --git a/test/compile/fail_no_schema.sh b/test/compile/fail_no_schema.sh index 58fccde3a..409ca449a 100755 --- a/test/compile/fail_no_schema.sh +++ b/test/compile/fail_no_schema.sh @@ -7,8 +7,9 @@ TMP="$(mktemp -d)" clean() { rm -rf "$TMP"; } trap clean EXIT -"$1" compile 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: This command expects a path to a schema @@ -19,8 +20,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" compile --json > "$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/compile/fail_schema_invalid_json.sh b/test/compile/fail_schema_invalid_json.sh index 4d718cb85..c731dbe83 100755 --- a/test/compile/fail_schema_invalid_json.sh +++ b/test/compile/fail_schema_invalid_json.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" compile "$TMP/schema.json" 2>"$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -28,8 +29,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" compile "$TMP/schema.json" --json >"$TMP/stdout.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/compile/fail_unknown_metaschema.sh b/test/compile/fail_unknown_metaschema.sh index 3b1a7171c..1582eda26 100755 --- a/test/compile/fail_unknown_metaschema.sh +++ b/test/compile/fail_unknown_metaschema.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" compile "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the metaschema of the schema @@ -31,8 +32,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" compile "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" compile "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/decode/fail_no_document.sh b/test/decode/fail_no_document.sh index dda3e1d2a..bd9915504 100755 --- a/test/decode/fail_no_document.sh +++ b/test/decode/fail_no_document.sh @@ -11,8 +11,9 @@ cat << 'EOF' > "$TMP/document.json" { "version": 2.0 } EOF -"$1" decode 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" decode 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: This command expects a path to a binary file and an output path @@ -23,8 +24,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" decode --json > "$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" decode --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/decode/fail_no_output.sh b/test/decode/fail_no_output.sh index ede0bf69f..d2a865eac 100755 --- a/test/decode/fail_no_output.sh +++ b/test/decode/fail_no_output.sh @@ -12,8 +12,9 @@ cat << 'EOF' > "$TMP/document.json" EOF "$1" encode "$TMP/document.json" "$TMP/output.binpack" -"$1" decode "$TMP/output.binpack" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" decode "$TMP/output.binpack" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: This command expects a path to a binary file and an output path @@ -25,8 +26,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" encode "$TMP/document.json" "$TMP/output.binpack" -"$1" decode "$TMP/output.binpack" --json > "$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" decode "$TMP/output.binpack" --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/encode/fail_no_document.sh b/test/encode/fail_no_document.sh index b8aaa6c87..e5d192e63 100755 --- a/test/encode/fail_no_document.sh +++ b/test/encode/fail_no_document.sh @@ -11,8 +11,9 @@ cat << 'EOF' > "$TMP/document.json" { "version": 2.0 } EOF -"$1" encode 2> "$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" encode 2> "$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: This command expects a path to a JSON document and an output path @@ -23,8 +24,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" encode --json > "$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" encode --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/encode/fail_no_output.sh b/test/encode/fail_no_output.sh index 48229448b..9d9c05fbf 100755 --- a/test/encode/fail_no_output.sh +++ b/test/encode/fail_no_output.sh @@ -11,8 +11,9 @@ cat << 'EOF' > "$TMP/document.json" { "version": 2.0 } EOF -"$1" encode "$TMP/document.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" encode "$TMP/document.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: This command expects a path to a JSON document and an output path @@ -23,8 +24,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" encode "$TMP/document.json" --json > "$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" encode "$TMP/document.json" --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/flag_with_value.sh b/test/flag_with_value.sh index c55e2fae9..9e8926ffc 100755 --- a/test/flag_with_value.sh +++ b/test/flag_with_value.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" inspect "$TMP/schema.json" --json=foo > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" error: This flag cannot take a value diff --git a/test/format/fail_check_many.sh b/test/format/fail_check_many.sh index b786bdc4f..c07bea4b8 100755 --- a/test/format/fail_check_many.sh +++ b/test/format/fail_check_many.sh @@ -35,8 +35,9 @@ cat << 'EOF' > "$TMP/schemas/3.json" } EOF -"$1" fmt "$TMP/schemas" --check >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" fmt "$TMP/schemas" --check >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Format check failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" fail: $(realpath "$TMP")/schemas/1.json diff --git a/test/format/fail_check_many_json.sh b/test/format/fail_check_many_json.sh index e5be43ff8..2c423d00d 100755 --- a/test/format/fail_check_many_json.sh +++ b/test/format/fail_check_many_json.sh @@ -35,8 +35,9 @@ cat << 'EOF' > "$TMP/schemas/3.json" } EOF -"$1" fmt "$TMP/schemas" --check --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" fmt "$TMP/schemas" --check --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Format check failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/format/fail_check_single.sh b/test/format/fail_check_single.sh index 573e7c4c9..a43e7d59e 100755 --- a/test/format/fail_check_single.sh +++ b/test/format/fail_check_single.sh @@ -16,8 +16,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" fmt "$TMP/schema.json" --check >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" fmt "$TMP/schema.json" --check >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Format check failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" fail: $(realpath "$TMP")/schema.json diff --git a/test/format/fail_check_single_indentation.sh b/test/format/fail_check_single_indentation.sh index fae279977..cba862b7f 100755 --- a/test/format/fail_check_single_indentation.sh +++ b/test/format/fail_check_single_indentation.sh @@ -16,8 +16,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" fmt "$TMP/schema.json" --indentation 4 --check >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" fmt "$TMP/schema.json" --indentation 4 --check >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Format check failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" fail: $(realpath "$TMP")/schema.json diff --git a/test/format/fail_check_single_invalid.sh b/test/format/fail_check_single_invalid.sh index 736f56323..c81f8b66f 100755 --- a/test/format/fail_check_single_invalid.sh +++ b/test/format/fail_check_single_invalid.sh @@ -16,8 +16,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" fmt "$TMP/schema.json" --check >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema.json" --check >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document diff --git a/test/format/fail_check_single_json.sh b/test/format/fail_check_single_json.sh index a1512eeb3..fd84a6313 100755 --- a/test/format/fail_check_single_json.sh +++ b/test/format/fail_check_single_json.sh @@ -19,8 +19,9 @@ cat << 'EOF' > "$TMP/this/is/a/very/very/very/very/very/very/long/path/schema.js EOF "$1" fmt "$TMP/this/is/a/very/very/very/very/very/very/long/path/schema.json" \ - --check --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + --check --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Format check failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/format/fail_check_single_json_indentation.sh b/test/format/fail_check_single_json_indentation.sh index 8412dee7c..5c925ff70 100755 --- a/test/format/fail_check_single_json_indentation.sh +++ b/test/format/fail_check_single_json_indentation.sh @@ -19,8 +19,9 @@ cat << 'EOF' > "$TMP/this/is/a/very/very/very/long/path/schema.json" EOF "$1" fmt "$TMP/this/is/a/very/very/very/long/path/schema.json" \ - --check --json --indentation 4 >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + --check --json --indentation 4 >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Format check failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/format/fail_custom_extension_yaml.sh b/test/format/fail_custom_extension_yaml.sh index 05c867b1d..4b5a4d570 100755 --- a/test/format/fail_custom_extension_yaml.sh +++ b/test/format/fail_custom_extension_yaml.sh @@ -13,8 +13,9 @@ $schema: https://json-schema.org/draft/2020-12/schema type: string EOF -"$1" fmt "$TMP/schema.custom" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema.custom" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" error: This command does not support YAML input files yet diff --git a/test/format/fail_extension_empty_yaml.sh b/test/format/fail_extension_empty_yaml.sh index cd004df35..60e490843 100755 --- a/test/format/fail_extension_empty_yaml.sh +++ b/test/format/fail_extension_empty_yaml.sh @@ -16,8 +16,9 @@ additionalProperties: false title: Hello World EOF -"$1" fmt "$TMP/schemas" --extension '' 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schemas" --extension '' 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" warning: Matching files with no extension diff --git a/test/format/fail_invalid_id_type.sh b/test/format/fail_invalid_id_type.sh index d567e9917..438df9f20 100755 --- a/test/format/fail_invalid_id_type.sh +++ b/test/format/fail_invalid_id_type.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" fmt "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema identifier is invalid diff --git a/test/format/fail_invalid_path.sh b/test/format/fail_invalid_path.sh index 5d2dc415f..bf6bb91b7 100755 --- a/test/format/fail_invalid_path.sh +++ b/test/format/fail_invalid_path.sh @@ -7,8 +7,9 @@ TMP="$(mktemp -d)" clean() { rm -rf "$TMP"; } trap clean EXIT -"$1" fmt "$TMP/does_not_exist.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/does_not_exist.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: No such file or directory diff --git a/test/format/fail_invalid_schema_uri.sh b/test/format/fail_invalid_schema_uri.sh index 3e9efbb3e..8e95dbad9 100755 --- a/test/format/fail_invalid_schema_uri.sh +++ b/test/format/fail_invalid_schema_uri.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" fmt "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The dialect is not a valid URI diff --git a/test/format/fail_no_dialect.sh b/test/format/fail_no_dialect.sh index a9a64684b..6a4ba8f60 100755 --- a/test/format/fail_no_dialect.sh +++ b/test/format/fail_no_dialect.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" fmt "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema @@ -32,8 +33,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" # JSON error -"$1" fmt "$TMP/schema.json" --json >"$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema.json" --json >"$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/format/fail_unknown_metaschema.sh b/test/format/fail_unknown_metaschema.sh index 4cb8734f0..7ea5aa117 100755 --- a/test/format/fail_unknown_metaschema.sh +++ b/test/format/fail_unknown_metaschema.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" fmt "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the metaschema of the schema @@ -34,8 +35,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" # JSON error -"$1" fmt "$TMP/schema.json" --json >"$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema.json" --json >"$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/format/fail_without_extension_yaml.sh b/test/format/fail_without_extension_yaml.sh index a51108816..c0465bdba 100755 --- a/test/format/fail_without_extension_yaml.sh +++ b/test/format/fail_without_extension_yaml.sh @@ -17,8 +17,9 @@ properties: bar: {} EOF -"$1" fmt "$TMP/schema" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" error: This command does not support YAML input files yet diff --git a/test/format/pass_check_yaml.sh b/test/format/pass_check_yaml.sh index bbd6d7c73..c7da00474 100755 --- a/test/format/pass_check_yaml.sh +++ b/test/format/pass_check_yaml.sh @@ -12,8 +12,9 @@ type: 1 $schema: http://json-schema.org/draft-04/schema# EOF -"$1" fmt "$TMP/schema.yaml" --check >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema.yaml" --check >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" error: This command does not support YAML input files yet diff --git a/test/format/pass_yaml.sh b/test/format/pass_yaml.sh index 047da5fc3..7a2a3a552 100755 --- a/test/format/pass_yaml.sh +++ b/test/format/pass_yaml.sh @@ -12,8 +12,9 @@ additionalProperties: false title: Hello World EOF -"$1" fmt "$TMP/schema.yaml" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" fmt "$TMP/schema.yaml" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" error: This command does not support YAML input files yet diff --git a/test/inspect/fail_default_dialect_config_extension_mismatch.sh b/test/inspect/fail_default_dialect_config_extension_mismatch.sh index b1a47a161..57853ec09 100755 --- a/test/inspect/fail_default_dialect_config_extension_mismatch.sh +++ b/test/inspect/fail_default_dialect_config_extension_mismatch.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/jsonschema.json" } EOF -"$1" inspect "$TMP/document.json" --verbose 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" inspect "$TMP/document.json" --verbose 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema @@ -33,8 +34,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" inspect "$TMP/document.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" inspect "$TMP/document.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/inspect/fail_invalid_id_type.sh b/test/inspect/fail_invalid_id_type.sh index 55a22c265..4418c155c 100755 --- a/test/inspect/fail_invalid_id_type.sh +++ b/test/inspect/fail_invalid_id_type.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" inspect "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" inspect "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema identifier is invalid diff --git a/test/inspect/fail_invalid_schema_uri.sh b/test/inspect/fail_invalid_schema_uri.sh index b5c527d52..9a752a755 100755 --- a/test/inspect/fail_invalid_schema_uri.sh +++ b/test/inspect/fail_invalid_schema_uri.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" inspect "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" inspect "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The dialect is not a valid URI diff --git a/test/inspect/fail_no_schema.sh b/test/inspect/fail_no_schema.sh index 026dcdee5..2e25f8826 100755 --- a/test/inspect/fail_no_schema.sh +++ b/test/inspect/fail_no_schema.sh @@ -7,8 +7,9 @@ TMP="$(mktemp -d)" clean() { rm -rf "$TMP"; } trap clean EXIT -"$1" inspect 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" inspect 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: This command expects a path to a schema @@ -19,8 +20,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" inspect --json > "$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" inspect --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/inspect/fail_relative_file_metaschema_ref.sh b/test/inspect/fail_relative_file_metaschema_ref.sh index 5091f0de6..81e8c222e 100755 --- a/test/inspect/fail_relative_file_metaschema_ref.sh +++ b/test/inspect/fail_relative_file_metaschema_ref.sh @@ -26,8 +26,9 @@ EOF "$1" inspect "$TMP/schemas/folder/test.json" \ --resolve "$TMP/schemas/meta.json" > "$TMP/result.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Relative meta-schema URIs are not valid according to the JSON Schema specification diff --git a/test/inspect/fail_schema_invalid_json.sh b/test/inspect/fail_schema_invalid_json.sh index de9aba61d..61e4ffcc1 100755 --- a/test/inspect/fail_schema_invalid_json.sh +++ b/test/inspect/fail_schema_invalid_json.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" inspect "$TMP/schema.json" 2>"$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -28,8 +29,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" inspect "$TMP/schema.json" --json >"$TMP/stdout.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/inspect/fail_unknown_metaschema.sh b/test/inspect/fail_unknown_metaschema.sh index 8a142306f..2cdecb6a7 100755 --- a/test/inspect/fail_unknown_metaschema.sh +++ b/test/inspect/fail_unknown_metaschema.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" inspect "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" inspect "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the metaschema of the schema @@ -31,8 +32,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" inspect "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" inspect "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/install/fail_add_config_invalid_json.sh b/test/install/fail_add_config_invalid_json.sh index ec23f6a42..3ae81dca9 100755 --- a/test/install/fail_add_config_invalid_json.sh +++ b/test/install/fail_add_config_invalid_json.sh @@ -17,7 +17,8 @@ cd "$TMP/project" "$1" install "https://example.com/foo" "./vendor/foo.json" \ > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -31,7 +32,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --json "https://example.com/foo" "./vendor/foo.json" \ > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_add_config_not_object.sh b/test/install/fail_add_config_not_object.sh index f5f5e6eb2..5b96f7d3d 100755 --- a/test/install/fail_add_config_not_object.sh +++ b/test/install/fail_add_config_not_object.sh @@ -17,7 +17,8 @@ cd "$TMP/project" "$1" install "https://example.com/foo" "./vendor/foo.json" \ > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: The configuration must be an object @@ -30,7 +31,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --json "https://example.com/foo" "./vendor/foo.json" \ > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_add_duplicate_path.sh b/test/install/fail_add_duplicate_path.sh index 588ec3c61..7f12b34d5 100755 --- a/test/install/fail_add_duplicate_path.sh +++ b/test/install/fail_add_duplicate_path.sh @@ -19,8 +19,9 @@ EOF cd "$TMP/project" "$1" install "https://example.com/schema" "./vendor/user.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" cat << EOF > "$TMP/expected.txt" error: Multiple dependencies cannot point to the same path @@ -31,8 +32,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --json "https://example.com/schema" "./vendor/user.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_add_invalid_uri.sh b/test/install/fail_add_invalid_uri.sh index 2c8a5fbce..22629b54d 100755 --- a/test/install/fail_add_invalid_uri.sh +++ b/test/install/fail_add_invalid_uri.sh @@ -17,8 +17,9 @@ EOF cd "$TMP/project" "$1" install "not a valid uri" "./vendor/test.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" cat << 'EOF' > "$TMP/expected.txt" error: The given URI is not valid @@ -29,8 +30,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --json "not a valid uri" "./vendor/test.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" cat << 'EOF' > "$TMP/expected_json.txt" { diff --git a/test/install/fail_creates_parent_over_file.sh b/test/install/fail_creates_parent_over_file.sh index eccce3023..446568cc8 100755 --- a/test/install/fail_creates_parent_over_file.sh +++ b/test/install/fail_creates_parent_over_file.sh @@ -29,7 +29,8 @@ EOF cd "$TMP/project" "$1" install > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" Fetching : file://$(realpath "$TMP")/source/user.json @@ -41,7 +42,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_duplicate_destination.sh b/test/install/fail_duplicate_destination.sh index 64e45cddc..fc2978697 100755 --- a/test/install/fail_duplicate_destination.sh +++ b/test/install/fail_duplicate_destination.sh @@ -37,7 +37,8 @@ ESCAPED_TMP="$(realpath "$TMP" | sed 's|/|~1|g')" cd "$TMP/project" "$1" install > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Multiple dependencies cannot point to the same path @@ -49,7 +50,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_corrupted_lock_invalid_format.sh b/test/install/fail_frozen_corrupted_lock_invalid_format.sh index adfccd869..2bb6767d6 100755 --- a/test/install/fail_frozen_corrupted_lock_invalid_format.sh +++ b/test/install/fail_frozen_corrupted_lock_invalid_format.sh @@ -26,7 +26,8 @@ EOF cd "$TMP/project" "$1" install --frozen > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Lock file is corrupted @@ -37,7 +38,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --frozen --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_corrupted_lock_json.sh b/test/install/fail_frozen_corrupted_lock_json.sh index a9ceacb4a..aeac2c855 100755 --- a/test/install/fail_frozen_corrupted_lock_json.sh +++ b/test/install/fail_frozen_corrupted_lock_json.sh @@ -22,7 +22,8 @@ echo "NOT VALID JSON" > "$TMP/project/jsonschema.lock.json" cd "$TMP/project" "$1" install --frozen > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -35,7 +36,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --frozen --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_force_conflict.sh b/test/install/fail_frozen_force_conflict.sh index 699081ee1..feb6b4a27 100755 --- a/test/install/fail_frozen_force_conflict.sh +++ b/test/install/fail_frozen_force_conflict.sh @@ -20,7 +20,8 @@ EOF cd "$TMP/project" "$1" install --frozen --force > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: The --frozen and --force options cannot be used together @@ -30,7 +31,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --frozen --force --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_hash_mismatch.sh b/test/install/fail_frozen_hash_mismatch.sh index f8247e7ce..2a2014699 100755 --- a/test/install/fail_frozen_hash_mismatch.sh +++ b/test/install/fail_frozen_hash_mismatch.sh @@ -40,7 +40,8 @@ echo "TAMPERED CONTENT" > "$TMP/project/vendor/schema.json" "$1" install --frozen > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" Mismatched : $(realpath "$TMP")/project/vendor/schema.json @@ -54,7 +55,8 @@ diff "$TMP/project/jsonschema.lock.json" "$TMP/lock_before.json" "$1" install --frozen --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_multiple_errors.sh b/test/install/fail_frozen_multiple_errors.sh index 4f77a9753..f953e48fd 100755 --- a/test/install/fail_frozen_multiple_errors.sh +++ b/test/install/fail_frozen_multiple_errors.sh @@ -46,7 +46,8 @@ EOF "$1" install --frozen > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" Untracked : file:///tmp/fake/new.json @@ -59,7 +60,8 @@ diff "$TMP/project/jsonschema.lock.json" "$TMP/lock_before.json" "$1" install --frozen --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_no_lock_file.sh b/test/install/fail_frozen_no_lock_file.sh index a06dd5912..16a2cfed3 100755 --- a/test/install/fail_frozen_no_lock_file.sh +++ b/test/install/fail_frozen_no_lock_file.sh @@ -20,7 +20,8 @@ EOF cd "$TMP/project" "$1" install --frozen > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Lock file not found @@ -31,7 +32,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --frozen --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_orphaned.sh b/test/install/fail_frozen_orphaned.sh index 3db7284a3..2f91c4e09 100755 --- a/test/install/fail_frozen_orphaned.sh +++ b/test/install/fail_frozen_orphaned.sh @@ -56,7 +56,8 @@ EOF "$1" install --frozen > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" Up to date : file://$(realpath "$TMP")/source/schema.json @@ -69,7 +70,8 @@ diff "$TMP/project/jsonschema.lock.json" "$TMP/lock_before.json" "$1" install --frozen --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_path_mismatch.sh b/test/install/fail_frozen_path_mismatch.sh index db0e00b10..df1234884 100755 --- a/test/install/fail_frozen_path_mismatch.sh +++ b/test/install/fail_frozen_path_mismatch.sh @@ -42,7 +42,8 @@ cp "$TMP/project/jsonschema.lock.json" "$TMP/lock_before.json" cd "$TMP/project" "$1" install --frozen > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" Path mismatch : file://$(realpath "$TMP")/source/schema.json @@ -56,7 +57,8 @@ diff "$TMP/project/jsonschema.lock.json" "$TMP/lock_before.json" "$1" install --frozen --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_positional_args.sh b/test/install/fail_frozen_positional_args.sh index e876b9931..9854e5c4b 100755 --- a/test/install/fail_frozen_positional_args.sh +++ b/test/install/fail_frozen_positional_args.sh @@ -18,7 +18,8 @@ EOF cd "$TMP/project" "$1" install --frozen https://example.com/schema ./vendor/schema.json > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: Do not use --frozen when adding a new dependency @@ -30,7 +31,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --frozen --json https://example.com/schema ./vendor/schema.json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_untracked.sh b/test/install/fail_frozen_untracked.sh index 0a0b71101..75888e0ce 100755 --- a/test/install/fail_frozen_untracked.sh +++ b/test/install/fail_frozen_untracked.sh @@ -47,7 +47,8 @@ EOF "$1" install --frozen > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" Up to date : file://$(realpath "$TMP")/source/schema.json @@ -60,7 +61,8 @@ diff "$TMP/project/jsonschema.lock.json" "$TMP/lock_before.json" "$1" install --frozen --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_frozen_written_hash_mismatch.sh b/test/install/fail_frozen_written_hash_mismatch.sh index 14884520a..48e5ac359 100755 --- a/test/install/fail_frozen_written_hash_mismatch.sh +++ b/test/install/fail_frozen_written_hash_mismatch.sh @@ -47,7 +47,8 @@ EOF "$1" install --frozen > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" Fetching : file://$(realpath "$TMP")/source/schema.json @@ -64,7 +65,8 @@ rm "$TMP/project/vendor/schema.json" "$1" install --frozen --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Integrity verification failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_install_one_positional_arg.sh b/test/install/fail_install_one_positional_arg.sh index d00b1f6a2..4aec62955 100755 --- a/test/install/fail_install_one_positional_arg.sh +++ b/test/install/fail_install_one_positional_arg.sh @@ -11,7 +11,8 @@ cd "$TMP" "$1" install https://example.com/schema > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: The install command takes either zero or two positional arguments @@ -23,7 +24,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --json https://example.com/schema > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected_json.txt" { diff --git a/test/install/fail_install_three_positional_args.sh b/test/install/fail_install_three_positional_args.sh index 307dbac7a..cf7de96e8 100755 --- a/test/install/fail_install_three_positional_args.sh +++ b/test/install/fail_install_three_positional_args.sh @@ -11,7 +11,8 @@ cd "$TMP" "$1" install a b c > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: The install command takes either zero or two positional arguments @@ -23,7 +24,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --json a b c > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected_json.txt" { diff --git a/test/install/fail_invalid_json_configuration.sh b/test/install/fail_invalid_json_configuration.sh index 7786e0d09..a4c956426 100755 --- a/test/install/fail_invalid_json_configuration.sh +++ b/test/install/fail_invalid_json_configuration.sh @@ -16,7 +16,8 @@ EOF cd "$TMP/project" "$1" install > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -29,7 +30,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/install/fail_no_configuration.sh b/test/install/fail_no_configuration.sh index 7821167c4..c5cb7a74f 100755 --- a/test/install/fail_no_configuration.sh +++ b/test/install/fail_no_configuration.sh @@ -11,7 +11,8 @@ cd "$TMP" "$1" install > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not find a jsonschema.json configuration file @@ -24,7 +25,8 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" install --json > "$TMP/output_json.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_draft4_x_keyword_ref_target.sh b/test/lint/fail_draft4_x_keyword_ref_target.sh index 968f9f2a1..83e8837bf 100755 --- a/test/lint/fail_draft4_x_keyword_ref_target.sh +++ b/test/lint/fail_draft4_x_keyword_ref_target.sh @@ -32,8 +32,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The referenced schema is not considered to be a valid subschema given the dialect and vocabularies in use @@ -47,8 +48,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" lint "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_draft4_x_keyword_ref_target_fix.sh b/test/lint/fail_draft4_x_keyword_ref_target_fix.sh index d163959ac..74d70d37a 100755 --- a/test/lint/fail_draft4_x_keyword_ref_target_fix.sh +++ b/test/lint/fail_draft4_x_keyword_ref_target_fix.sh @@ -32,8 +32,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" --fix 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --fix 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 # After --fix elevates the allOf wrapper, the path changes cat << EOF > "$TMP/expected.txt" @@ -49,8 +50,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" lint "$TMP/schema.json" --fix --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --fix --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_draft7_defs_ref_target.sh b/test/lint/fail_draft7_defs_ref_target.sh index a28768aa6..b44e9cdc5 100755 --- a/test/lint/fail_draft7_defs_ref_target.sh +++ b/test/lint/fail_draft7_defs_ref_target.sh @@ -24,8 +24,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The referenced schema is not considered to be a valid subschema given the dialect and vocabularies in use @@ -39,8 +40,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" lint "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_draft7_defs_ref_target_fix.sh b/test/lint/fail_draft7_defs_ref_target_fix.sh index 568bb7f2d..4a1737e4b 100755 --- a/test/lint/fail_draft7_defs_ref_target_fix.sh +++ b/test/lint/fail_draft7_defs_ref_target_fix.sh @@ -24,8 +24,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" --fix 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --fix 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Unexpected error +test "$EXIT_CODE" = "1" || exit 1 cat << EOF > "$TMP/expected.txt" . @@ -47,8 +48,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" lint "$TMP/schema.json" --fix --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --fix --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Unexpected error +test "$EXIT_CODE" = "1" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_lint.sh b/test/lint/fail_lint.sh index 56ea6dd4c..0a48bb1fd 100755 --- a/test/lint/fail_lint.sh +++ b/test/lint/fail_lint.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" schema.json:6:3: diff --git a/test/lint/fail_lint_config_rule_duplicate_builtin.sh b/test/lint/fail_lint_config_rule_duplicate_builtin.sh index 760e05b13..469a09609 100755 --- a/test/lint/fail_lint_config_rule_duplicate_builtin.sh +++ b/test/lint/fail_lint_config_rule_duplicate_builtin.sh @@ -35,8 +35,9 @@ EOF cd "$TMP" "$1" lint "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: A lint rule with this name already exists @@ -48,8 +49,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" cd "$TMP" "$1" lint --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_config_rule_duplicate_cli.sh b/test/lint/fail_lint_config_rule_duplicate_cli.sh index fb3fe12db..c97f7c385 100755 --- a/test/lint/fail_lint_config_rule_duplicate_cli.sh +++ b/test/lint/fail_lint_config_rule_duplicate_cli.sh @@ -44,8 +44,9 @@ EOF cd "$TMP" "$1" lint --rule "$TMP/cli_rule.json" "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: A lint rule with this name already exists @@ -57,8 +58,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" cd "$TMP" "$1" lint --rule "$TMP/cli_rule.json" --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_config_rule_duplicate_config.sh b/test/lint/fail_lint_config_rule_duplicate_config.sh index 5fefc305f..e530db091 100755 --- a/test/lint/fail_lint_config_rule_duplicate_config.sh +++ b/test/lint/fail_lint_config_rule_duplicate_config.sh @@ -45,8 +45,9 @@ EOF cd "$TMP" "$1" lint "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: A lint rule with this name already exists @@ -58,8 +59,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" cd "$TMP" "$1" lint --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_config_rule_extension_mismatch.sh b/test/lint/fail_lint_config_rule_extension_mismatch.sh index fe60ce5e4..0f1ada82d 100755 --- a/test/lint/fail_lint_config_rule_extension_mismatch.sh +++ b/test/lint/fail_lint_config_rule_extension_mismatch.sh @@ -35,8 +35,9 @@ EOF cd "$TMP" "$1" lint --only require_type "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:1:1: diff --git a/test/lint/fail_lint_config_rule_invalid_title.sh b/test/lint/fail_lint_config_rule_invalid_title.sh index 095763f27..f6f2153cd 100755 --- a/test/lint/fail_lint_config_rule_invalid_title.sh +++ b/test/lint/fail_lint_config_rule_invalid_title.sh @@ -35,8 +35,9 @@ EOF cd "$TMP" "$1" lint "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema rule name must match ^[a-z0-9_/]+\$ @@ -48,8 +49,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" cd "$TMP" "$1" lint --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_config_rule_missing_title.sh b/test/lint/fail_lint_config_rule_missing_title.sh index 7361d20d1..f49f2a0a6 100755 --- a/test/lint/fail_lint_config_rule_missing_title.sh +++ b/test/lint/fail_lint_config_rule_missing_title.sh @@ -34,8 +34,9 @@ EOF cd "$TMP" "$1" lint "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema rule is missing a title @@ -46,8 +47,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" cd "$TMP" "$1" lint --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_config_rule_not_found.sh b/test/lint/fail_lint_config_rule_not_found.sh index 7d187be12..fbcfd8549 100755 --- a/test/lint/fail_lint_config_rule_not_found.sh +++ b/test/lint/fail_lint_config_rule_not_found.sh @@ -26,8 +26,9 @@ EOF cd "$TMP" "$1" lint "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: No such file or directory @@ -38,8 +39,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" cd "$TMP" "$1" lint --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_config_rule_other_directory.sh b/test/lint/fail_lint_config_rule_other_directory.sh index 5d474ff7e..83769fe64 100755 --- a/test/lint/fail_lint_config_rule_other_directory.sh +++ b/test/lint/fail_lint_config_rule_other_directory.sh @@ -37,8 +37,9 @@ EOF cd "$TMP/other" "$1" lint --only require_type "$TMP/project/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" ../project/schema.json:1:1: @@ -51,8 +52,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" cd "$TMP/other" "$1" lint --only require_type --json "$TMP/project/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_config_rule_violation.sh b/test/lint/fail_lint_config_rule_violation.sh index bbda3bc31..b02cacf2d 100755 --- a/test/lint/fail_lint_config_rule_violation.sh +++ b/test/lint/fail_lint_config_rule_violation.sh @@ -34,8 +34,9 @@ EOF cd "$TMP" "$1" lint --only require_type "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:1:1: @@ -48,8 +49,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" cd "$TMP" "$1" lint --only require_type --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_default.sh b/test/lint/fail_lint_default.sh index 0f9493e70..a9150e76c 100755 --- a/test/lint/fail_lint_default.sh +++ b/test/lint/fail_lint_default.sh @@ -23,8 +23,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" schema.json:9:7: diff --git a/test/lint/fail_lint_default_dialect.sh b/test/lint/fail_lint_default_dialect.sh index c672bea4d..cdc501f1f 100755 --- a/test/lint/fail_lint_default_dialect.sh +++ b/test/lint/fail_lint_default_dialect.sh @@ -19,8 +19,9 @@ EOF cd "$TMP" "$1" lint "$TMP/schema.json" \ --default-dialect "http://json-schema.org/draft-04/schema#" \ - >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" schema.json:5:3: diff --git a/test/lint/fail_lint_default_dialect_config.sh b/test/lint/fail_lint_default_dialect_config.sh index b43965120..33d9fb939 100755 --- a/test/lint/fail_lint_default_dialect_config.sh +++ b/test/lint/fail_lint_default_dialect_config.sh @@ -24,8 +24,9 @@ EOF cd "$TMP" "$1" lint "$TMP/schema.json" --verbose \ - >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" Linting: $(realpath "$TMP")/schema.json diff --git a/test/lint/fail_lint_default_dialect_config_relative.sh b/test/lint/fail_lint_default_dialect_config_relative.sh index 9e603d54a..bb3b18160 100755 --- a/test/lint/fail_lint_default_dialect_config_relative.sh +++ b/test/lint/fail_lint_default_dialect_config_relative.sh @@ -24,8 +24,9 @@ EOF cd "$TMP" "$1" lint schema.json --verbose \ - >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" Linting: $(realpath "$TMP")/schema.json diff --git a/test/lint/fail_lint_directory_json.sh b/test/lint/fail_lint_directory_json.sh index ef59b2c6c..3f6bae4d5 100755 --- a/test/lint/fail_lint_directory_json.sh +++ b/test/lint/fail_lint_directory_json.sh @@ -29,8 +29,9 @@ cat << 'EOF' > "$TMP/schemas/bar.json" } EOF -"$1" lint "$TMP/schemas" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schemas" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_directory_unresolvable.sh b/test/lint/fail_lint_directory_unresolvable.sh index a0eafc6b0..50e23d61e 100755 --- a/test/lint/fail_lint_directory_unresolvable.sh +++ b/test/lint/fail_lint_directory_unresolvable.sh @@ -33,8 +33,9 @@ cat << 'EOF' > "$TMP/baz.json" } EOF -"$1" lint "$TMP" --verbose >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP" --verbose >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" Linting: $(realpath "$TMP")/bar.json diff --git a/test/lint/fail_lint_directory_unresolvable_dialect.sh b/test/lint/fail_lint_directory_unresolvable_dialect.sh index 65373adf6..bb830ba3b 100755 --- a/test/lint/fail_lint_directory_unresolvable_dialect.sh +++ b/test/lint/fail_lint_directory_unresolvable_dialect.sh @@ -31,8 +31,9 @@ cat << 'EOF' > "$TMP/baz.json" } EOF -"$1" lint "$TMP" --verbose >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP" --verbose >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" Linting: $(realpath "$TMP")/bar.json diff --git a/test/lint/fail_lint_directory_unresolvable_fix.sh b/test/lint/fail_lint_directory_unresolvable_fix.sh index dbd101212..1e097847d 100755 --- a/test/lint/fail_lint_directory_unresolvable_fix.sh +++ b/test/lint/fail_lint_directory_unresolvable_fix.sh @@ -33,8 +33,9 @@ cat << 'EOF' > "$TMP/baz.json" } EOF -"$1" lint "$TMP" --fix --verbose >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP" --fix --verbose >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" Linting: $(realpath "$TMP")/bar.json diff --git a/test/lint/fail_lint_disable_many.sh b/test/lint/fail_lint_disable_many.sh index f75927c8a..038339a84 100755 --- a/test/lint/fail_lint_disable_many.sh +++ b/test/lint/fail_lint_disable_many.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" --exclude enum_to_const -x enum_with_type >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" --exclude enum_to_const -x enum_with_type >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" schema.json:7:3: diff --git a/test/lint/fail_lint_disable_one.sh b/test/lint/fail_lint_disable_one.sh index ba1527780..4f5fa4320 100755 --- a/test/lint/fail_lint_disable_one.sh +++ b/test/lint/fail_lint_disable_one.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" --exclude enum_to_const >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" --exclude enum_to_const >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" schema.json:7:3: diff --git a/test/lint/fail_lint_disable_one_verbose.sh b/test/lint/fail_lint_disable_one_verbose.sh index 8091ae372..cb80fca68 100755 --- a/test/lint/fail_lint_disable_one_verbose.sh +++ b/test/lint/fail_lint_disable_one_verbose.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" --verbose --exclude enum_to_const >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" --verbose --exclude enum_to_const >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" Disabling rule: enum_to_const diff --git a/test/lint/fail_lint_disable_unknown_verbose.sh b/test/lint/fail_lint_disable_unknown_verbose.sh index b736982ac..18efa2b6b 100755 --- a/test/lint/fail_lint_disable_unknown_verbose.sh +++ b/test/lint/fail_lint_disable_unknown_verbose.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" --verbose --exclude foo_bar >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" --verbose --exclude foo_bar >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" warning: Cannot exclude unknown rule: foo_bar diff --git a/test/lint/fail_lint_duplicate_id.sh b/test/lint/fail_lint_duplicate_id.sh index 4e99e0112..db90d83ed 100755 --- a/test/lint/fail_lint_duplicate_id.sh +++ b/test/lint/fail_lint_duplicate_id.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Schema identifier already exists @@ -28,8 +29,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_empty_anchor.sh b/test/lint/fail_lint_empty_anchor.sh index d09db8135..72f36c32d 100755 --- a/test/lint/fail_lint_empty_anchor.sh +++ b/test/lint/fail_lint_empty_anchor.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Schema identifier already exists @@ -25,8 +26,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_examples.sh b/test/lint/fail_lint_examples.sh index 330667d3b..32da8ad48 100755 --- a/test/lint/fail_lint_examples.sh +++ b/test/lint/fail_lint_examples.sh @@ -23,8 +23,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" schema.json:9:21: diff --git a/test/lint/fail_lint_exclude_partial.sh b/test/lint/fail_lint_exclude_partial.sh index d960783ae..8c65e0037 100755 --- a/test/lint/fail_lint_exclude_partial.sh +++ b/test/lint/fail_lint_exclude_partial.sh @@ -21,8 +21,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" schema.json:8:3: diff --git a/test/lint/fail_lint_fix_broken_reference.sh b/test/lint/fail_lint_fix_broken_reference.sh index 5215e1d68..2c1be1c4d 100755 --- a/test/lint/fail_lint_fix_broken_reference.sh +++ b/test/lint/fail_lint_fix_broken_reference.sh @@ -34,8 +34,9 @@ EOF cp "$TMP/schema.json" "$TMP/original.json" cd "$TMP" -"$1" lint "$TMP/schema.json" --fix >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --fix >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Unexpected error +test "$EXIT_CODE" = "1" || exit 1 cat << EOF > "$TMP/expected.txt" . diff --git a/test/lint/fail_lint_fix_custom_extension_yaml.sh b/test/lint/fail_lint_fix_custom_extension_yaml.sh index d28320b7c..290573549 100755 --- a/test/lint/fail_lint_fix_custom_extension_yaml.sh +++ b/test/lint/fail_lint_fix_custom_extension_yaml.sh @@ -13,8 +13,9 @@ type: string enum: [ foo ] EOF -"$1" lint "$TMP/schema.custom" --fix 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.custom" --fix 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" error: The --fix option is not supported for YAML input files diff --git a/test/lint/fail_lint_fix_extension_empty_yaml.sh b/test/lint/fail_lint_fix_extension_empty_yaml.sh index 7c8f220da..20481b55c 100755 --- a/test/lint/fail_lint_fix_extension_empty_yaml.sh +++ b/test/lint/fail_lint_fix_extension_empty_yaml.sh @@ -15,8 +15,9 @@ type: string enum: [ foo ] EOF -"$1" lint "$TMP/schemas" --extension '' --fix 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schemas" --extension '' --fix 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" warning: Matching files with no extension diff --git a/test/lint/fail_lint_fix_format_unfixable.sh b/test/lint/fail_lint_fix_format_unfixable.sh index 6636a48ba..4e75bf34b 100755 --- a/test/lint/fail_lint_fix_format_unfixable.sh +++ b/test/lint/fail_lint_fix_format_unfixable.sh @@ -18,8 +18,9 @@ EOF cd "$TMP" "$1" lint "$TMP/schema.json" --fix --format >"$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected_output.txt" schema.json:1:1: @@ -45,8 +46,9 @@ diff "$TMP/schema.json" "$TMP/expected.json" # JSON output "$1" lint "$TMP/schema.json" --fix --format --json >"$TMP/output_json.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected_output_json.txt" { diff --git a/test/lint/fail_lint_fix_without_extension_yaml.sh b/test/lint/fail_lint_fix_without_extension_yaml.sh index 5431e0e60..18b72dbe2 100755 --- a/test/lint/fail_lint_fix_without_extension_yaml.sh +++ b/test/lint/fail_lint_fix_without_extension_yaml.sh @@ -13,8 +13,9 @@ type: string enum: [ foo ] EOF -"$1" lint "$TMP/schema" --fix 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema" --fix 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" error: The --fix option is not supported for YAML input files diff --git a/test/lint/fail_lint_fix_yaml.sh b/test/lint/fail_lint_fix_yaml.sh index 8f7295542..14f11fc94 100755 --- a/test/lint/fail_lint_fix_yaml.sh +++ b/test/lint/fail_lint_fix_yaml.sh @@ -13,8 +13,9 @@ type: string enum: [ foo ] EOF -"$1" lint "$TMP/schema.yaml" --fix >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.yaml" --fix >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" error: The --fix option is not supported for YAML input files @@ -25,8 +26,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" lint "$TMP/schema.yaml" --fix --json >"$TMP/stdout.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_lint_fix_yml.sh b/test/lint/fail_lint_fix_yml.sh index bde2051ed..aecc75ced 100755 --- a/test/lint/fail_lint_fix_yml.sh +++ b/test/lint/fail_lint_fix_yml.sh @@ -13,8 +13,9 @@ type: string enum: [ foo ] EOF -"$1" lint "$TMP/schema.yml" --fix >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.yml" --fix >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" error: The --fix option is not supported for YAML input files @@ -25,8 +26,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" lint "$TMP/schema.yml" --fix --json >"$TMP/stdout.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_lint_format_without_fix.sh b/test/lint/fail_lint_format_without_fix.sh index f9c2a1b53..a83d9e4c2 100755 --- a/test/lint/fail_lint_format_without_fix.sh +++ b/test/lint/fail_lint_format_without_fix.sh @@ -15,8 +15,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint "$TMP/schema.json" --format >"$TMP/stderr.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" error: The --format option requires --fix to be set @@ -26,8 +27,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" lint "$TMP/schema.json" --format --json >"$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_lint_format_yaml.sh b/test/lint/fail_lint_format_yaml.sh index b534bfd18..de267ec28 100755 --- a/test/lint/fail_lint_format_yaml.sh +++ b/test/lint/fail_lint_format_yaml.sh @@ -13,8 +13,9 @@ type: string EOF "$1" lint "$TMP/schema.yaml" --fix --format >"$TMP/stderr.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" error: The --fix option is not supported for YAML input files @@ -25,8 +26,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" lint "$TMP/schema.yaml" --fix --format --json >"$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Not supported +test "$EXIT_CODE" = "3" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_lint_half_unfixable.sh b/test/lint/fail_lint_half_unfixable.sh index 8c030152a..c212a1703 100755 --- a/test/lint/fail_lint_half_unfixable.sh +++ b/test/lint/fail_lint_half_unfixable.sh @@ -22,8 +22,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" --fix >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" --fix >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" .. diff --git a/test/lint/fail_lint_id_with_fragment.sh b/test/lint/fail_lint_id_with_fragment.sh index abe678fc3..bfb84d275 100755 --- a/test/lint/fail_lint_id_with_fragment.sh +++ b/test/lint/fail_lint_id_with_fragment.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Identifiers must not contain non-empty fragments @@ -25,8 +26,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_invalid_embedded_resource.sh b/test/lint/fail_lint_invalid_embedded_resource.sh index 26b1c678e..90b27da06 100755 --- a/test/lint/fail_lint_invalid_embedded_resource.sh +++ b/test/lint/fail_lint_invalid_embedded_resource.sh @@ -29,8 +29,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat "$TMP/stderr.txt" diff --git a/test/lint/fail_lint_invalid_id_type.sh b/test/lint/fail_lint_invalid_id_type.sh index 1b24369c7..c963646a5 100755 --- a/test/lint/fail_lint_invalid_id_type.sh +++ b/test/lint/fail_lint_invalid_id_type.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema identifier is invalid @@ -28,8 +29,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_invalid_id_uri.sh b/test/lint/fail_lint_invalid_id_uri.sh index 760272b07..d5d35036c 100755 --- a/test/lint/fail_lint_invalid_id_uri.sh +++ b/test/lint/fail_lint_invalid_id_uri.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The identifier is not a valid URI @@ -28,8 +29,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_invalid_recursiveanchor_type.sh b/test/lint/fail_lint_invalid_recursiveanchor_type.sh index 4eb033232..d404872a7 100755 --- a/test/lint/fail_lint_invalid_recursiveanchor_type.sh +++ b/test/lint/fail_lint_invalid_recursiveanchor_type.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Invalid recursive anchor value @@ -28,8 +29,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_invalid_recursiveref_type.sh b/test/lint/fail_lint_invalid_recursiveref_type.sh index 7a753eb8a..034323df4 100755 --- a/test/lint/fail_lint_invalid_recursiveref_type.sh +++ b/test/lint/fail_lint_invalid_recursiveref_type.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Invalid recursive reference value @@ -28,8 +29,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_invalid_ref_uri.sh b/test/lint/fail_lint_invalid_ref_uri.sh index 2fd517f83..53c63fdfc 100755 --- a/test/lint/fail_lint_invalid_ref_uri.sh +++ b/test/lint/fail_lint_invalid_ref_uri.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The reference is not a valid URI @@ -28,8 +29,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_invalid_schema_type.sh b/test/lint/fail_lint_invalid_schema_type.sh index 2ae674765..08df3739b 100755 --- a/test/lint/fail_lint_invalid_schema_type.sh +++ b/test/lint/fail_lint_invalid_schema_type.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The dialect value is invalid @@ -28,8 +29,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_invalid_schema_uri.sh b/test/lint/fail_lint_invalid_schema_uri.sh index ed14c6ffe..8289da7c8 100755 --- a/test/lint/fail_lint_invalid_schema_uri.sh +++ b/test/lint/fail_lint_invalid_schema_uri.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The dialect is not a valid URI @@ -28,8 +29,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_json.sh b/test/lint/fail_lint_json.sh index 2fbc7a932..66125d91f 100755 --- a/test/lint/fail_lint_json.sh +++ b/test/lint/fail_lint_json.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_keep_ordering_without_format.sh b/test/lint/fail_lint_keep_ordering_without_format.sh index 2a4b0f79e..360fca013 100755 --- a/test/lint/fail_lint_keep_ordering_without_format.sh +++ b/test/lint/fail_lint_keep_ordering_without_format.sh @@ -15,8 +15,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint "$TMP/schema.json" --fix --keep-ordering >"$TMP/stderr.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" error: The --keep-ordering option requires --format to be set @@ -26,8 +27,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" lint "$TMP/schema.json" --fix --keep-ordering --json >"$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_lint_nested_invalid_schema_type.sh b/test/lint/fail_lint_nested_invalid_schema_type.sh index 0d29fc52a..6ede6a271 100755 --- a/test/lint/fail_lint_nested_invalid_schema_type.sh +++ b/test/lint/fail_lint_nested_invalid_schema_type.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The dialect value is invalid @@ -32,8 +33,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_non_schema.sh b/test/lint/fail_lint_non_schema.sh index 0c89f64b7..40c573e91 100755 --- a/test/lint/fail_lint_non_schema.sh +++ b/test/lint/fail_lint_non_schema.sh @@ -11,8 +11,9 @@ cat << 'EOF' > "$TMP/schema.json" { "foo": "bar" } EOF -"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema diff --git a/test/lint/fail_lint_non_schema_fix.sh b/test/lint/fail_lint_non_schema_fix.sh index 8dba94d66..0eaa2ff75 100755 --- a/test/lint/fail_lint_non_schema_fix.sh +++ b/test/lint/fail_lint_non_schema_fix.sh @@ -11,8 +11,9 @@ cat << 'EOF' > "$TMP/schema.json" { "foo": "bar" } EOF -"$1" lint "$TMP/schema.json" --fix >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" lint "$TMP/schema.json" --fix >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema diff --git a/test/lint/fail_lint_only.sh b/test/lint/fail_lint_only.sh index e6edea3d6..548349c37 100755 --- a/test/lint/fail_lint_only.sh +++ b/test/lint/fail_lint_only.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" schema.json:7:3: @@ -37,7 +38,7 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" -"$1" lint "$TMP/schema.json" --only content_media_type_without_encoding >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" +"$1" lint "$TMP/schema.json" --only content_media_type_without_encoding >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" cat << EOF > "$TMP/expected.txt" schema.json:7:3: diff --git a/test/lint/fail_lint_only_unknown.sh b/test/lint/fail_lint_only_unknown.sh index f20b81f7c..06bc99040 100755 --- a/test/lint/fail_lint_only_unknown.sh +++ b/test/lint/fail_lint_only_unknown.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint "$TMP/schema.json" --only foobarbaz \ - >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" error: The following linting rule does not exist diff --git a/test/lint/fail_lint_only_unknown_verbose.sh b/test/lint/fail_lint_only_unknown_verbose.sh index 07a5e7759..483aaeb9a 100755 --- a/test/lint/fail_lint_only_unknown_verbose.sh +++ b/test/lint/fail_lint_only_unknown_verbose.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint "$TMP/schema.json" --only foobarbaz --verbose \ - >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" Only enabling rule: foobarbaz diff --git a/test/lint/fail_lint_only_with_exclude.sh b/test/lint/fail_lint_only_with_exclude.sh index 67428466a..095f7986c 100755 --- a/test/lint/fail_lint_only_with_exclude.sh +++ b/test/lint/fail_lint_only_with_exclude.sh @@ -19,8 +19,9 @@ EOF "$1" lint "$TMP/schema.json" \ --only enum_with_type --exclude const_with_type --verbose \ - >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" error: Cannot use --only and --exclude at the same time diff --git a/test/lint/fail_lint_positions.sh b/test/lint/fail_lint_positions.sh index a1bb8c639..d24452e68 100755 --- a/test/lint/fail_lint_positions.sh +++ b/test/lint/fail_lint_positions.sh @@ -21,8 +21,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" schema.json:6:5: diff --git a/test/lint/fail_lint_positions_json.sh b/test/lint/fail_lint_positions_json.sh index b5a9bdd9d..f525995b7 100755 --- a/test/lint/fail_lint_positions_json.sh +++ b/test/lint/fail_lint_positions_json.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_rule_duplicate_builtin.sh b/test/lint/fail_lint_rule_duplicate_builtin.sh index 3cd5f42eb..7e72752f0 100755 --- a/test/lint/fail_lint_rule_duplicate_builtin.sh +++ b/test/lint/fail_lint_rule_duplicate_builtin.sh @@ -24,8 +24,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint --rule "$TMP/rule.json" "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: A lint rule with this name already exists @@ -36,8 +37,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" "$1" lint --rule "$TMP/rule.json" --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_rule_duplicate_custom.sh b/test/lint/fail_lint_rule_duplicate_custom.sh index dd0399fff..f887d717f 100755 --- a/test/lint/fail_lint_rule_duplicate_custom.sh +++ b/test/lint/fail_lint_rule_duplicate_custom.sh @@ -33,8 +33,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint --rule "$TMP/rule1.json" --rule "$TMP/rule2.json" "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: A lint rule with this name already exists @@ -45,8 +46,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" "$1" lint --rule "$TMP/rule1.json" --rule "$TMP/rule2.json" --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_rule_invalid_json.sh b/test/lint/fail_lint_rule_invalid_json.sh index c377a3d2b..c49d5126d 100755 --- a/test/lint/fail_lint_rule_invalid_json.sh +++ b/test/lint/fail_lint_rule_invalid_json.sh @@ -19,8 +19,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint --rule "$TMP/rule.json" "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -32,8 +33,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" "$1" lint --rule "$TMP/rule.json" --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_rule_invalid_title.sh b/test/lint/fail_lint_rule_invalid_title.sh index b3b775878..2b77b3603 100755 --- a/test/lint/fail_lint_rule_invalid_title.sh +++ b/test/lint/fail_lint_rule_invalid_title.sh @@ -24,8 +24,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint --rule "$TMP/rule.json" "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema rule name must match ^[a-z0-9_/]+\$ @@ -36,8 +37,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" "$1" lint --rule "$TMP/rule.json" --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_rule_missing_title.sh b/test/lint/fail_lint_rule_missing_title.sh index 31e594107..2abcb0f67 100755 --- a/test/lint/fail_lint_rule_missing_title.sh +++ b/test/lint/fail_lint_rule_missing_title.sh @@ -23,8 +23,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint --rule "$TMP/rule.json" "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema rule is missing a title @@ -34,8 +35,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" "$1" lint --rule "$TMP/rule.json" --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_rule_multiple.sh b/test/lint/fail_lint_rule_multiple.sh index ddd5742e7..e3b8f4ae1 100755 --- a/test/lint/fail_lint_rule_multiple.sh +++ b/test/lint/fail_lint_rule_multiple.sh @@ -35,8 +35,9 @@ EOF cd "$TMP" "$1" lint --rule "$TMP/rule_type.json" --rule "$TMP/rule_description.json" \ --only require_type --only require_description "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:1:1: diff --git a/test/lint/fail_lint_rule_multiple_json.sh b/test/lint/fail_lint_rule_multiple_json.sh index 9259eaa45..7c548af7c 100755 --- a/test/lint/fail_lint_rule_multiple_json.sh +++ b/test/lint/fail_lint_rule_multiple_json.sh @@ -34,8 +34,9 @@ EOF "$1" lint --rule "$TMP/rule_type.json" --rule "$TMP/rule_description.json" \ --only require_type --only require_description --json "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_lint_rule_not_found.sh b/test/lint/fail_lint_rule_not_found.sh index 428b1762b..04b062634 100755 --- a/test/lint/fail_lint_rule_not_found.sh +++ b/test/lint/fail_lint_rule_not_found.sh @@ -15,8 +15,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint --rule "$TMP/nonexistent.json" "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: No such file or directory @@ -26,8 +27,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" "$1" lint --rule "$TMP/nonexistent.json" --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_rule_only.sh b/test/lint/fail_lint_rule_only.sh index 6bb32a844..02e47abfc 100755 --- a/test/lint/fail_lint_rule_only.sh +++ b/test/lint/fail_lint_rule_only.sh @@ -24,8 +24,9 @@ EOF cd "$TMP" "$1" lint --rule "$TMP/rule.json" --only require_type "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:1:1: diff --git a/test/lint/fail_lint_rule_only_json.sh b/test/lint/fail_lint_rule_only_json.sh index b39639783..f8aaf8890 100755 --- a/test/lint/fail_lint_rule_only_json.sh +++ b/test/lint/fail_lint_rule_only_json.sh @@ -23,8 +23,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint --rule "$TMP/rule.json" --only require_type --json "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_lint_rule_property_names.sh b/test/lint/fail_lint_rule_property_names.sh index 3e9b6c4a0..cfe264151 100755 --- a/test/lint/fail_lint_rule_property_names.sh +++ b/test/lint/fail_lint_rule_property_names.sh @@ -38,8 +38,9 @@ EOF cd "$TMP" "$1" lint --rule "$TMP/rule.json" "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:7:5: diff --git a/test/lint/fail_lint_rule_property_names_json.sh b/test/lint/fail_lint_rule_property_names_json.sh index e21e5e0c4..0efa7e126 100755 --- a/test/lint/fail_lint_rule_property_names_json.sh +++ b/test/lint/fail_lint_rule_property_names_json.sh @@ -37,8 +37,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint --rule "$TMP/rule.json" --json "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_lint_rule_unresolvable.sh b/test/lint/fail_lint_rule_unresolvable.sh index ed350c310..14414dcfa 100755 --- a/test/lint/fail_lint_rule_unresolvable.sh +++ b/test/lint/fail_lint_rule_unresolvable.sh @@ -24,8 +24,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint --rule "$TMP/rule.json" "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the reference to an external schema @@ -38,8 +39,9 @@ EOF diff "$TMP/output.txt" "$TMP/expected.txt" "$1" lint --rule "$TMP/rule.json" --json "$TMP/schema.json" \ - > "$TMP/output_json.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected_json.txt" { diff --git a/test/lint/fail_lint_rule_violation.sh b/test/lint/fail_lint_rule_violation.sh index 6bb32a844..02e47abfc 100755 --- a/test/lint/fail_lint_rule_violation.sh +++ b/test/lint/fail_lint_rule_violation.sh @@ -24,8 +24,9 @@ EOF cd "$TMP" "$1" lint --rule "$TMP/rule.json" --only require_type "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:1:1: diff --git a/test/lint/fail_lint_rule_violation_json.sh b/test/lint/fail_lint_rule_violation_json.sh index b39639783..f8aaf8890 100755 --- a/test/lint/fail_lint_rule_violation_json.sh +++ b/test/lint/fail_lint_rule_violation_json.sh @@ -23,8 +23,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" lint --rule "$TMP/rule.json" --only require_type --json "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/lint/fail_lint_unfixable.sh b/test/lint/fail_lint_unfixable.sh index 4e2f5ff5c..9c64fec7e 100755 --- a/test/lint/fail_lint_unfixable.sh +++ b/test/lint/fail_lint_unfixable.sh @@ -15,8 +15,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:1:1: diff --git a/test/lint/fail_lint_unfixable_autofix.sh b/test/lint/fail_lint_unfixable_autofix.sh index 1bbf33c03..1180aaf19 100755 --- a/test/lint/fail_lint_unfixable_autofix.sh +++ b/test/lint/fail_lint_unfixable_autofix.sh @@ -17,8 +17,9 @@ EOF cp "$TMP/schema.json" "$TMP/copy.json" cd "$TMP" -"$1" lint "$TMP/schema.json" --fix >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" --fix >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:1:1: diff --git a/test/lint/fail_lint_unfixable_autofix_json.sh b/test/lint/fail_lint_unfixable_autofix_json.sh index f6263dc1d..eca43a86a 100755 --- a/test/lint/fail_lint_unfixable_autofix_json.sh +++ b/test/lint/fail_lint_unfixable_autofix_json.sh @@ -16,8 +16,9 @@ EOF cp "$TMP/schema.json" "$TMP/copy.json" -"$1" lint "$TMP/schema.json" --fix --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" --fix --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_unfixable_json.sh b/test/lint/fail_lint_unfixable_json.sh index b6d8a6036..b06aa582c 100755 --- a/test/lint/fail_lint_unfixable_json.sh +++ b/test/lint/fail_lint_unfixable_json.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/lint/fail_lint_with_id.sh b/test/lint/fail_lint_with_id.sh index 3e6bb02b2..08dbc8c44 100755 --- a/test/lint/fail_lint_with_id.sh +++ b/test/lint/fail_lint_with_id.sh @@ -19,8 +19,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF cd "$TMP" -"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:7:3: diff --git a/test/lint/fail_lint_yaml.sh b/test/lint/fail_lint_yaml.sh index a979e3389..5bdaafdfc 100755 --- a/test/lint/fail_lint_yaml.sh +++ b/test/lint/fail_lint_yaml.sh @@ -16,8 +16,9 @@ enum: [ foo ] EOF cd "$TMP" -"$1" lint "$TMP/schema.yaml" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" lint "$TMP/schema.yaml" >"$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" schema.yaml:5:1: diff --git a/test/lint/pass_lint_rule_no_description.sh b/test/lint/pass_lint_rule_no_description.sh index 92d5b7a72..c2036b259 100755 --- a/test/lint/pass_lint_rule_no_description.sh +++ b/test/lint/pass_lint_rule_no_description.sh @@ -23,8 +23,9 @@ EOF cd "$TMP" "$1" lint --rule "$TMP/rule.json" --only require_type "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:1:1: diff --git a/test/lint/pass_lint_rule_with_resolve.sh b/test/lint/pass_lint_rule_with_resolve.sh index 1cd08ee27..129faf1d6 100755 --- a/test/lint/pass_lint_rule_with_resolve.sh +++ b/test/lint/pass_lint_rule_with_resolve.sh @@ -37,8 +37,9 @@ EOF cd "$TMP" "$1" lint --rule "$TMP/rule.json" --resolve "$TMP/defs.json" \ --only require_type "$TMP/schema.json" \ - > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Lint violation +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" schema.json:1:1: diff --git a/test/metaschema/fail_config_path_enoent.sh b/test/metaschema/fail_config_path_enoent.sh index 4bdf67dac..57c7d85e1 100755 --- a/test/metaschema/fail_config_path_enoent.sh +++ b/test/metaschema/fail_config_path_enoent.sh @@ -16,8 +16,9 @@ cat << 'EOF' > "$TMP/jsonschema.json" EOF cd "$TMP/bar" -"$1" metaschema --verbose > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema --verbose > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" Using extension: .json @@ -31,8 +32,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" # JSON error cd "$TMP/bar" -"$1" metaschema --json > "$TMP/stdout.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/metaschema/fail_default_dialect_config_extension_mismatch.sh b/test/metaschema/fail_default_dialect_config_extension_mismatch.sh index 2ed6985b3..140469b7b 100755 --- a/test/metaschema/fail_default_dialect_config_extension_mismatch.sh +++ b/test/metaschema/fail_default_dialect_config_extension_mismatch.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/jsonschema.json" } EOF -"$1" metaschema "$TMP/document.json" --verbose 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/document.json" --verbose 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema @@ -33,8 +34,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" metaschema "$TMP/document.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/document.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/metaschema/fail_directory.sh b/test/metaschema/fail_directory.sh index b76516789..03151ed3a 100755 --- a/test/metaschema/fail_directory.sh +++ b/test/metaschema/fail_directory.sh @@ -27,8 +27,9 @@ cat << 'EOF' > "$TMP/schemas/schema_2.json" } EOF -"$1" metaschema "$TMP/schemas" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" metaschema "$TMP/schemas" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Metaschema validation failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" fail: $(realpath "$TMP")/schemas/schema_2.json diff --git a/test/metaschema/fail_directory_json.sh b/test/metaschema/fail_directory_json.sh index 3693c4991..f21c96bc0 100755 --- a/test/metaschema/fail_directory_json.sh +++ b/test/metaschema/fail_directory_json.sh @@ -27,8 +27,9 @@ cat << 'EOF' > "$TMP/schemas/schema_2.json" } EOF -"$1" metaschema "$TMP/schemas" --json > "$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" metaschema "$TMP/schemas" --json > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Metaschema validation failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/schemas/schema_1.json diff --git a/test/metaschema/fail_directory_non_resolved.sh b/test/metaschema/fail_directory_non_resolved.sh index 5f8ce3413..9ad4532b8 100755 --- a/test/metaschema/fail_directory_non_resolved.sh +++ b/test/metaschema/fail_directory_non_resolved.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/schemas/schema_1.json" } EOF -"$1" metaschema "$TMP/schemas" > "$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/schemas" > "$TMP/stderr.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the metaschema of the schema diff --git a/test/metaschema/fail_draft4_x_keyword_ref_target.sh b/test/metaschema/fail_draft4_x_keyword_ref_target.sh index ff6645d4f..0b737306a 100755 --- a/test/metaschema/fail_draft4_x_keyword_ref_target.sh +++ b/test/metaschema/fail_draft4_x_keyword_ref_target.sh @@ -37,8 +37,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" metaschema "$TMP/schema.json" --resolve "$TMP/metaschema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/schema.json" --resolve "$TMP/metaschema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The referenced schema is not considered to be a valid subschema given the dialect and vocabularies in use @@ -52,8 +53,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" metaschema "$TMP/schema.json" --resolve "$TMP/metaschema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/schema.json" --resolve "$TMP/metaschema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/metaschema/fail_draft7_defs_ref_target.sh b/test/metaschema/fail_draft7_defs_ref_target.sh index af9fcdae4..4a104537e 100755 --- a/test/metaschema/fail_draft7_defs_ref_target.sh +++ b/test/metaschema/fail_draft7_defs_ref_target.sh @@ -29,8 +29,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" metaschema "$TMP/schema.json" --resolve "$TMP/metaschema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/schema.json" --resolve "$TMP/metaschema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The referenced schema is not considered to be a valid subschema given the dialect and vocabularies in use @@ -44,8 +45,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" metaschema "$TMP/schema.json" --resolve "$TMP/metaschema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/schema.json" --resolve "$TMP/metaschema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/metaschema/fail_json.sh b/test/metaschema/fail_json.sh index 1575bbf79..910ddd835 100755 --- a/test/metaschema/fail_json.sh +++ b/test/metaschema/fail_json.sh @@ -16,8 +16,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" metaschema "$TMP/schema.json" --json > "$TMP/output.json" && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" metaschema "$TMP/schema.json" --json > "$TMP/output.json" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Metaschema validation failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/metaschema/fail_no_dialect.sh b/test/metaschema/fail_no_dialect.sh index ceffc9bf4..5ad3613a6 100755 --- a/test/metaschema/fail_no_dialect.sh +++ b/test/metaschema/fail_no_dialect.sh @@ -11,8 +11,9 @@ cat << 'EOF' > "$TMP/document.json" { "type": "string" } EOF -"$1" metaschema "$TMP/document.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/document.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema @@ -26,8 +27,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" metaschema "$TMP/document.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/document.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/metaschema/fail_non_schema.sh b/test/metaschema/fail_non_schema.sh index 2539ed656..ca47c8bd3 100755 --- a/test/metaschema/fail_non_schema.sh +++ b/test/metaschema/fail_non_schema.sh @@ -11,8 +11,9 @@ cat << 'EOF' > "$TMP/document.json" [ { "foo": 1 } ] EOF -"$1" metaschema "$TMP/document.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/document.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema file you provided does not represent a valid JSON Schema @@ -22,8 +23,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" metaschema "$TMP/document.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" metaschema "$TMP/document.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/metaschema/fail_relative_file_metaschema_ref.sh b/test/metaschema/fail_relative_file_metaschema_ref.sh index 0bcf96201..c0166bd1d 100755 --- a/test/metaschema/fail_relative_file_metaschema_ref.sh +++ b/test/metaschema/fail_relative_file_metaschema_ref.sh @@ -28,8 +28,9 @@ EOF "$1" metaschema "$TMP/schemas/folder/test.json" \ --resolve "$TMP/schemas/meta.json" > "$TMP/result.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Relative meta-schema URIs are not valid according to the JSON Schema specification @@ -42,8 +43,9 @@ diff "$TMP/result.txt" "$TMP/expected.txt" # JSON error "$1" metaschema "$TMP/schemas/folder/test.json" \ --resolve "$TMP/schemas/meta.json" --json > "$TMP/stdout.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/metaschema/fail_single.sh b/test/metaschema/fail_single.sh index 8794bd8d7..cb818d761 100755 --- a/test/metaschema/fail_single.sh +++ b/test/metaschema/fail_single.sh @@ -16,8 +16,9 @@ cat << 'EOF' > "$TMP/schema.json" } EOF -"$1" metaschema "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" metaschema "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Metaschema validation failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" fail: $(realpath "$TMP")/schema.json diff --git a/test/metaschema/fail_trace.sh b/test/metaschema/fail_trace.sh index 7d46df669..a1782a823 100755 --- a/test/metaschema/fail_trace.sh +++ b/test/metaschema/fail_trace.sh @@ -17,8 +17,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" metaschema "$TMP/schema.json" --trace > "$TMP/output.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Metaschema validation failure +test "$EXIT_CODE" = "2" || exit 1 cat << 'EOF' > "$TMP/expected.txt" -> (push) "/dependencies" (AssertionPropertyDependencies) diff --git a/test/metaschema/fail_yaml.sh b/test/metaschema/fail_yaml.sh index 007f97eda..dc22245f9 100755 --- a/test/metaschema/fail_yaml.sh +++ b/test/metaschema/fail_yaml.sh @@ -12,8 +12,9 @@ $schema: http://json-schema.org/draft-04/schema# type: 1 EOF -"$1" metaschema "$TMP/schema.yaml" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 +"$1" metaschema "$TMP/schema.yaml" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Metaschema validation failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" fail: $(realpath "$TMP")/schema.yaml diff --git a/test/option_without_value.sh b/test/option_without_value.sh index 28ec1dc24..7b4f40c03 100755 --- a/test/option_without_value.sh +++ b/test/option_without_value.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" inspect "$TMP/schema.json" --default-dialect > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" error: This option must take a value diff --git a/test/test/fail_anyof.sh b/test/test/fail_anyof.sh index 058b0fb4c..cd53f6b2b 100755 --- a/test/test/fail_anyof.sh +++ b/test/test/fail_anyof.sh @@ -40,8 +40,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 cat "$TMP/output.txt" diff --git a/test/test/fail_draft4_x_keyword_ref_target.sh b/test/test/fail_draft4_x_keyword_ref_target.sh index 11317d94f..59059513f 100755 --- a/test/test/fail_draft4_x_keyword_ref_target.sh +++ b/test/test/fail_draft4_x_keyword_ref_target.sh @@ -43,8 +43,9 @@ cat << 'EOF' > "$TMP/test.json" } EOF -"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The referenced schema is not considered to be a valid subschema given the dialect and vocabularies in use @@ -58,8 +59,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/test/fail_draft7_defs_ref_target.sh b/test/test/fail_draft7_defs_ref_target.sh index 4dc27a4fd..c7936e6da 100755 --- a/test/test/fail_draft7_defs_ref_target.sh +++ b/test/test/fail_draft7_defs_ref_target.sh @@ -35,8 +35,9 @@ cat << 'EOF' > "$TMP/test.json" } EOF -"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The referenced schema is not considered to be a valid subschema given the dialect and vocabularies in use @@ -50,8 +51,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/test/fail_false_single_resolve.sh b/test/test/fail_false_single_resolve.sh index eb21847f4..0d3e01087 100755 --- a/test/test/fail_false_single_resolve.sh +++ b/test/test/fail_false_single_resolve.sh @@ -41,8 +41,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_false_single_resolve_json.sh b/test/test/fail_false_single_resolve_json.sh index 16c70be91..775fa4f6d 100755 --- a/test/test/fail_false_single_resolve_json.sh +++ b/test/test/fail_false_single_resolve_json.sh @@ -29,8 +29,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --json > "$TMP/output.json" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 # Validate against CTRF schema CTRF_SCHEMA="$(dirname "$0")/../../vendor/ctrf/specification/schema-0.0.0.json" diff --git a/test/test/fail_false_single_resolve_verbose.sh b/test/test/fail_false_single_resolve_verbose.sh index 6801cb4f3..dcbae26b0 100755 --- a/test/test/fail_false_single_resolve_verbose.sh +++ b/test/test/fail_false_single_resolve_verbose.sh @@ -41,8 +41,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --verbose 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_multi_resolve.sh b/test/test/fail_multi_resolve.sh index fbec81b23..196263df2 100755 --- a/test/test/fail_multi_resolve.sh +++ b/test/test/fail_multi_resolve.sh @@ -46,8 +46,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_multi_resolve_verbose.sh b/test/test/fail_multi_resolve_verbose.sh index 92691796d..ad65950ef 100755 --- a/test/test/fail_multi_resolve_verbose.sh +++ b/test/test/fail_multi_resolve_verbose.sh @@ -46,8 +46,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --verbose 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_multi_test.sh b/test/test/fail_multi_test.sh index 6abf1130e..e59baa40c 100755 --- a/test/test/fail_multi_test.sh +++ b/test/test/fail_multi_test.sh @@ -64,8 +64,9 @@ cat << 'EOF' > "$TMP/tests/3.json" EOF "$1" test "$TMP/tests" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/tests/1.json: diff --git a/test/test/fail_no_schema.sh b/test/test/fail_no_schema.sh index dfee845ea..4656eb069 100755 --- a/test/test/fail_no_schema.sh +++ b/test/test/fail_no_schema.sh @@ -23,8 +23,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: @@ -41,8 +42,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" # JSON error "$1" test "$TMP/test.json" --json > "$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/test/fail_no_tests.sh b/test/test/fail_no_tests.sh index e531f1bfe..d100ff8cf 100755 --- a/test/test/fail_no_tests.sh +++ b/test/test/fail_no_tests.sh @@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_not_object.sh b/test/test/fail_not_object.sh index 005de7010..f7e608f29 100755 --- a/test/test/fail_not_object.sh +++ b/test/test/fail_not_object.sh @@ -26,8 +26,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_resolve_directory_non_schema.sh b/test/test/fail_resolve_directory_non_schema.sh index 6a7961e0b..17d84501c 100755 --- a/test/test/fail_resolve_directory_non_schema.sh +++ b/test/test/fail_resolve_directory_non_schema.sh @@ -36,8 +36,9 @@ cat << 'EOF' > "$TMP/schemas/test.json" EOF "$1" test "$TMP/schemas/test.json" --verbose --resolve "$TMP" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema diff --git a/test/test/fail_schema_non_string.sh b/test/test/fail_schema_non_string.sh index 5654c2dd6..9c224bad9 100755 --- a/test/test/fail_schema_non_string.sh +++ b/test/test/fail_schema_non_string.sh @@ -24,8 +24,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_test_case_data_and_data_path.sh b/test/test/fail_test_case_data_and_data_path.sh index 061d656f0..82105c4b2 100755 --- a/test/test/fail_test_case_data_and_data_path.sh +++ b/test/test/fail_test_case_data_and_data_path.sh @@ -21,8 +21,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_test_case_no_data.sh b/test/test/fail_test_case_no_data.sh index 27f171a5f..1d1cef7ba 100755 --- a/test/test/fail_test_case_no_data.sh +++ b/test/test/fail_test_case_no_data.sh @@ -27,8 +27,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_test_case_no_valid.sh b/test/test/fail_test_case_no_valid.sh index b77942fa7..16541df54 100755 --- a/test/test/fail_test_case_no_valid.sh +++ b/test/test/fail_test_case_no_valid.sh @@ -23,8 +23,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_test_case_non_boolean_valid.sh b/test/test/fail_test_case_non_boolean_valid.sh index f0f8cf43f..850d71be4 100755 --- a/test/test/fail_test_case_non_boolean_valid.sh +++ b/test/test/fail_test_case_non_boolean_valid.sh @@ -24,8 +24,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_test_case_non_object.sh b/test/test/fail_test_case_non_object.sh index 8937d1300..bf7d8ea49 100755 --- a/test/test/fail_test_case_non_object.sh +++ b/test/test/fail_test_case_non_object.sh @@ -21,8 +21,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_test_case_non_string_data_path.sh b/test/test/fail_test_case_non_string_data_path.sh index 3ce7dd57a..f0f8eca0b 100755 --- a/test/test/fail_test_case_non_string_data_path.sh +++ b/test/test/fail_test_case_non_string_data_path.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_test_case_non_string_description.sh b/test/test/fail_test_case_non_string_description.sh index 998a18eb2..09ade0593 100755 --- a/test/test/fail_test_case_non_string_description.sh +++ b/test/test/fail_test_case_non_string_description.sh @@ -26,8 +26,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_tests_non_array.sh b/test/test/fail_tests_non_array.sh index ab81265da..0dffec644 100755 --- a/test/test/fail_tests_non_array.sh +++ b/test/test/fail_tests_non_array.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_true_resolve_fragment.sh b/test/test/fail_true_resolve_fragment.sh index 2cbea8fab..fa952e3fd 100755 --- a/test/test/fail_true_resolve_fragment.sh +++ b/test/test/fail_true_resolve_fragment.sh @@ -34,8 +34,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_true_single_resolve.sh b/test/test/fail_true_single_resolve.sh index 87f02d514..4e2475976 100755 --- a/test/test/fail_true_single_resolve.sh +++ b/test/test/fail_true_single_resolve.sh @@ -41,8 +41,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_true_single_resolve_json.sh b/test/test/fail_true_single_resolve_json.sh index 4c5768bb6..23de5b924 100755 --- a/test/test/fail_true_single_resolve_json.sh +++ b/test/test/fail_true_single_resolve_json.sh @@ -29,8 +29,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --json > "$TMP/output.json" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 # Validate against CTRF schema CTRF_SCHEMA="$(dirname "$0")/../../vendor/ctrf/specification/schema-0.0.0.json" diff --git a/test/test/fail_true_single_resolve_verbose.sh b/test/test/fail_true_single_resolve_verbose.sh index 3a3a94cc5..5bafb25b7 100755 --- a/test/test/fail_true_single_resolve_verbose.sh +++ b/test/test/fail_true_single_resolve_verbose.sh @@ -41,8 +41,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --verbose 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Test assertion failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_unresolvable.sh b/test/test/fail_unresolvable.sh index eb3aa9fdc..bac084dbd 100755 --- a/test/test/fail_unresolvable.sh +++ b/test/test/fail_unresolvable.sh @@ -24,8 +24,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --verbose 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_unresolvable_anchor.sh b/test/test/fail_unresolvable_anchor.sh index 00334e5d4..064ee3fd1 100755 --- a/test/test/fail_unresolvable_anchor.sh +++ b/test/test/fail_unresolvable_anchor.sh @@ -37,8 +37,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --verbose 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_unresolvable_fragment.sh b/test/test/fail_unresolvable_fragment.sh index 27232cecd..d85d62ad2 100755 --- a/test/test/fail_unresolvable_fragment.sh +++ b/test/test/fail_unresolvable_fragment.sh @@ -37,8 +37,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --verbose 1> "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" $(realpath "$TMP")/test.json: diff --git a/test/test/fail_unresolvable_json.sh b/test/test/fail_unresolvable_json.sh index 0adbd695a..4bd71bf15 100755 --- a/test/test/fail_unresolvable_json.sh +++ b/test/test/fail_unresolvable_json.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/test.json" EOF "$1" test "$TMP/test.json" --json > "$TMP/output.json" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/unknown_command.sh b/test/unknown_command.sh index 61dc549d4..9a7945e3d 100755 --- a/test/unknown_command.sh +++ b/test/unknown_command.sh @@ -6,10 +6,11 @@ TMP="$(mktemp -d)" clean() { rm -rf "$TMP"; } trap clean EXIT -"$1" unknown_command 1> "$TMP/stdout" 2> "$TMP/stderr" && CODE="$?" || CODE="$?" -if [ "$CODE" != "1" ] +"$1" unknown_command 1> "$TMP/stdout" 2> "$TMP/stderr" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +if [ "$EXIT_CODE" != "5" ] then - echo "FAIL: Unknown command did not return exit code 1" 1>&2 + echo "FAIL: Unknown command did not return exit code 5" 1>&2 exit 1 fi if [ -s "$TMP/stdout" ] diff --git a/test/unknown_option.sh b/test/unknown_option.sh index 0ccaecbe8..88fa44ee1 100755 --- a/test/unknown_option.sh +++ b/test/unknown_option.sh @@ -20,8 +20,9 @@ cat << 'EOF' > "$TMP/schema.json" EOF "$1" inspect "$TMP/schema.json" --hello foo > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" error: Unknown option diff --git a/test/validate/fail_2019_09.sh b/test/validate/fail_2019_09.sh index 5cf71b0f5..13ab723b5 100755 --- a/test/validate/fail_2019_09.sh +++ b/test/validate/fail_2019_09.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2> "$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_2020_12.sh b/test/validate/fail_2020_12.sh index 8416b42b9..baa642ce3 100755 --- a/test/validate/fail_2020_12.sh +++ b/test/validate/fail_2020_12.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2> "$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_2020_12_fast.sh b/test/validate/fail_2020_12_fast.sh index 128dfbf84..1d5551c21 100755 --- a/test/validate/fail_2020_12_fast.sh +++ b/test/validate/fail_2020_12_fast.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" --fast 2> "$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_benchmark.sh b/test/validate/fail_benchmark.sh index b6b462439..e4e6acf77 100755 --- a/test/validate/fail_benchmark.sh +++ b/test/validate/fail_benchmark.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" --benchmark > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 if ! grep -E "/instance\.json: FAIL [0-9]+\.[0-9]+ \+- [0-9]+\.[0-9]+ us \([0-9]+\.[0-9]+\)$" "$TMP/output.txt" > /dev/null diff --git a/test/validate/fail_benchmark_directory.sh b/test/validate/fail_benchmark_directory.sh index acf687365..d3ae82036 100755 --- a/test/validate/fail_benchmark_directory.sh +++ b/test/validate/fail_benchmark_directory.sh @@ -27,7 +27,8 @@ cat << 'EOF' > "$TMP/instances/instance_2.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instances" --benchmark 2> "$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: The `--benchmark/-b` option is only allowed given a single instance @@ -37,7 +38,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instances" --benchmark --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/validate/fail_benchmark_multiple.sh b/test/validate/fail_benchmark_multiple.sh index b628e29de..d9723774c 100755 --- a/test/validate/fail_benchmark_multiple.sh +++ b/test/validate/fail_benchmark_multiple.sh @@ -25,7 +25,8 @@ cat << 'EOF' > "$TMP/instance_2.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instance_1.json" "$TMP/instance_2.json" --benchmark 2> "$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: The `--benchmark/-b` option is only allowed given a single instance @@ -35,7 +36,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instance_1.json" "$TMP/instance_2.json" --benchmark --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/validate/fail_benchmark_zero.sh b/test/validate/fail_benchmark_zero.sh index 0527ebd6c..7b8a92bd6 100755 --- a/test/validate/fail_benchmark_zero.sh +++ b/test/validate/fail_benchmark_zero.sh @@ -27,7 +27,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" --benchmark --loop 0 > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" error: The loop number cannot be zero diff --git a/test/validate/fail_default_dialect_config_extension_mismatch.sh b/test/validate/fail_default_dialect_config_extension_mismatch.sh index 9036c3eae..4f10cad27 100755 --- a/test/validate/fail_default_dialect_config_extension_mismatch.sh +++ b/test/validate/fail_default_dialect_config_extension_mismatch.sh @@ -23,8 +23,9 @@ cat << 'EOF' > "$TMP/jsonschema.json" EOF "$1" validate "$TMP/document.json" "$TMP/instance.json" --verbose 2>"$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not determine the base dialect of the schema @@ -39,8 +40,9 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/document.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_directory.sh b/test/validate/fail_directory.sh index 85de1b4b1..ec4025181 100755 --- a/test/validate/fail_directory.sh +++ b/test/validate/fail_directory.sh @@ -35,6 +35,7 @@ cat << 'EOF' > "$TMP/instances/nested/instance_2.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instances" 2> "$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_directory_fast.sh b/test/validate/fail_directory_fast.sh index 0f52ac4b1..59efc3c63 100755 --- a/test/validate/fail_directory_fast.sh +++ b/test/validate/fail_directory_fast.sh @@ -32,6 +32,7 @@ cat << 'EOF' > "$TMP/instances/instance_2.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instances" --fast 2> "$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_directory_fast_json.sh b/test/validate/fail_directory_fast_json.sh index b53f4bb7e..07e500445 100755 --- a/test/validate/fail_directory_fast_json.sh +++ b/test/validate/fail_directory_fast_json.sh @@ -32,6 +32,7 @@ cat << 'EOF' > "$TMP/instances/instance_2.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instances" --fast --json > "$TMP/stdout.txt" 2> "$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected_stderr.txt" diff --git a/test/validate/fail_directory_json.sh b/test/validate/fail_directory_json.sh index 8bc2d2797..e53e2c06f 100755 --- a/test/validate/fail_directory_json.sh +++ b/test/validate/fail_directory_json.sh @@ -35,6 +35,7 @@ cat << 'EOF' > "$TMP/instances/instance_2.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instances" --json > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_directory_verbose.sh b/test/validate/fail_directory_verbose.sh index a839db02a..da4e60277 100755 --- a/test/validate/fail_directory_verbose.sh +++ b/test/validate/fail_directory_verbose.sh @@ -35,6 +35,7 @@ cat << 'EOF' > "$TMP/instances/nested/instance_2.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instances" --verbose 2> "$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_draft4.sh b/test/validate/fail_draft4.sh index 0b06cf4c4..253900081 100755 --- a/test/validate/fail_draft4.sh +++ b/test/validate/fail_draft4.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2> "$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_draft4_x_keyword_ref_target.sh b/test/validate/fail_draft4_x_keyword_ref_target.sh index 2b242e857..04e661a1f 100755 --- a/test/validate/fail_draft4_x_keyword_ref_target.sh +++ b/test/validate/fail_draft4_x_keyword_ref_target.sh @@ -33,8 +33,9 @@ cat << 'EOF' > "$TMP/instance.json" {} EOF -"$1" validate "$TMP/schema.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" validate "$TMP/schema.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The referenced schema is not considered to be a valid subschema given the dialect and vocabularies in use @@ -48,8 +49,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" validate "$TMP/schema.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" validate "$TMP/schema.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_draft6.sh b/test/validate/fail_draft6.sh index fb0b7d688..8d56379e0 100755 --- a/test/validate/fail_draft6.sh +++ b/test/validate/fail_draft6.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2> "$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_draft7.sh b/test/validate/fail_draft7.sh index 53334befa..b5fb3cbdf 100755 --- a/test/validate/fail_draft7.sh +++ b/test/validate/fail_draft7.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2> "$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_draft7_defs_ref_target.sh b/test/validate/fail_draft7_defs_ref_target.sh index 35b2a0bba..54050d27d 100755 --- a/test/validate/fail_draft7_defs_ref_target.sh +++ b/test/validate/fail_draft7_defs_ref_target.sh @@ -25,8 +25,9 @@ cat << 'EOF' > "$TMP/instance.json" {} EOF -"$1" validate "$TMP/schema.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" validate "$TMP/schema.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The referenced schema is not considered to be a valid subschema given the dialect and vocabularies in use @@ -40,8 +41,9 @@ EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error -"$1" validate "$TMP/schema.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" validate "$TMP/schema.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_draft7_top_level_ref.sh b/test/validate/fail_draft7_top_level_ref.sh index 0dc0773da..b842a05e3 100755 --- a/test/validate/fail_draft7_top_level_ref.sh +++ b/test/validate/fail_draft7_top_level_ref.sh @@ -27,7 +27,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2> "$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: A schema with a top-level \`\$ref\` in JSON Schema Draft 7 and older dialects ignores every sibling keywords (like identifiers and meta-schema declarations) and therefore many operations, like bundling, are not possible without undefined behavior @@ -39,7 +40,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" --json > "$TMP/stdout.json" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.json" { diff --git a/test/validate/fail_entrypoint_invalid_pointer.sh b/test/validate/fail_entrypoint_invalid_pointer.sh index 4a6c01021..933bc10a0 100755 --- a/test/validate/fail_entrypoint_invalid_pointer.sh +++ b/test/validate/fail_entrypoint_invalid_pointer.sh @@ -20,8 +20,9 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --entrypoint '/nonexistent' > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The given entry point URI does not exist in the schema @@ -35,8 +36,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --entrypoint '/nonexistent' --json > "$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_entrypoint_invalid_pointer_escape.sh b/test/validate/fail_entrypoint_invalid_pointer_escape.sh index fa3264e40..cbb52b82c 100755 --- a/test/validate/fail_entrypoint_invalid_pointer_escape.sh +++ b/test/validate/fail_entrypoint_invalid_pointer_escape.sh @@ -20,8 +20,9 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --entrypoint '/foo~bar' > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The given entry point URI does not exist in the schema @@ -35,8 +36,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --entrypoint '/foo~bar' --json > "$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_entrypoint_invalid_uri_parse.sh b/test/validate/fail_entrypoint_invalid_uri_parse.sh index d4386384a..6051de1b0 100755 --- a/test/validate/fail_entrypoint_invalid_uri_parse.sh +++ b/test/validate/fail_entrypoint_invalid_uri_parse.sh @@ -20,8 +20,9 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --entrypoint 'https://example.com/foo bar' > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The given entry point is not a valid URI or JSON Pointer @@ -35,8 +36,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --entrypoint 'https://example.com/foo bar' --json > "$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_entrypoint_mismatch.sh b/test/validate/fail_entrypoint_mismatch.sh index 049fa01fc..1fb88b0d1 100755 --- a/test/validate/fail_entrypoint_mismatch.sh +++ b/test/validate/fail_entrypoint_mismatch.sh @@ -26,8 +26,9 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --entrypoint "/\$defs/PositiveInt" --verbose > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" fail: $(realpath "$TMP")/instance.json @@ -41,8 +42,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --entrypoint "/\$defs/PositiveInt" --json > "$TMP/stdout.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "2" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure +test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_entrypoint_with_template.sh b/test/validate/fail_entrypoint_with_template.sh index bbf8eb3e8..93e771fd1 100755 --- a/test/validate/fail_entrypoint_with_template.sh +++ b/test/validate/fail_entrypoint_with_template.sh @@ -25,8 +25,9 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --entrypoint "/\$defs/Foo" --template "$TMP/template.json" \ > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" error: The --entrypoint option cannot be used with --template @@ -37,8 +38,9 @@ diff "$TMP/output.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --entrypoint "/\$defs/Foo" --template "$TMP/template.json" --json \ > "$TMP/output.txt" 2>&1 \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 + && EXIT_CODE="$?" || EXIT_CODE="$?" +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_instance_enoent.sh b/test/validate/fail_instance_enoent.sh index b22fb21a1..75bc6ea82 100755 --- a/test/validate/fail_instance_enoent.sh +++ b/test/validate/fail_instance_enoent.sh @@ -18,7 +18,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/foo.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: No such file or directory @@ -30,7 +31,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/foo.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_instance_invalid_json.sh b/test/validate/fail_instance_invalid_json.sh index 502d3c5da..4d0da3b43 100755 --- a/test/validate/fail_instance_invalid_json.sh +++ b/test/validate/fail_instance_invalid_json.sh @@ -24,7 +24,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -38,7 +39,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_invalid_config.sh b/test/validate/fail_invalid_config.sh index 99a6d8646..f1132c6dc 100755 --- a/test/validate/fail_invalid_config.sh +++ b/test/validate/fail_invalid_config.sh @@ -25,7 +25,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" >"$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: The defaultDialect property must be a string diff --git a/test/validate/fail_invalid_id_type.sh b/test/validate/fail_invalid_id_type.sh index 2e40d67f6..c26e9d902 100755 --- a/test/validate/fail_invalid_id_type.sh +++ b/test/validate/fail_invalid_id_type.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/instance.json" {} EOF -"$1" validate "$TMP/schema.json" "$TMP/instance.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" validate "$TMP/schema.json" "$TMP/instance.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema identifier is invalid diff --git a/test/validate/fail_invalid_ref.sh b/test/validate/fail_invalid_ref.sh index 5162c1451..a8a2b19d3 100755 --- a/test/validate/fail_invalid_ref.sh +++ b/test/validate/fail_invalid_ref.sh @@ -26,7 +26,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve schema reference @@ -40,7 +41,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_invalid_schema_uri.sh b/test/validate/fail_invalid_schema_uri.sh index 09606447d..d67d58234 100755 --- a/test/validate/fail_invalid_schema_uri.sh +++ b/test/validate/fail_invalid_schema_uri.sh @@ -18,8 +18,9 @@ cat << 'EOF' > "$TMP/instance.json" "hello" EOF -"$1" validate "$TMP/schema.json" "$TMP/instance.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 +"$1" validate "$TMP/schema.json" "$TMP/instance.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The dialect is not a valid URI diff --git a/test/validate/fail_json.sh b/test/validate/fail_json.sh index ade700770..9529752f3 100755 --- a/test/validate/fail_json.sh +++ b/test/validate/fail_json.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" --json > "$TMP/output.json" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" diff --git a/test/validate/fail_jsonl_all.sh b/test/validate/fail_jsonl_all.sh index 8b8c98d3c..f6a3500ee 100755 --- a/test/validate/fail_jsonl_all.sh +++ b/test/validate/fail_jsonl_all.sh @@ -24,6 +24,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_jsonl_all_verbose.sh b/test/validate/fail_jsonl_all_verbose.sh index c4c8de45d..a2d301414 100755 --- a/test/validate/fail_jsonl_all_verbose.sh +++ b/test/validate/fail_jsonl_all_verbose.sh @@ -24,6 +24,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" --verbose 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_jsonl_invalid_entry.sh b/test/validate/fail_jsonl_invalid_entry.sh index b8d410981..8677323a1 100755 --- a/test/validate/fail_jsonl_invalid_entry.sh +++ b/test/validate/fail_jsonl_invalid_entry.sh @@ -24,7 +24,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -38,7 +39,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_jsonl_one.sh b/test/validate/fail_jsonl_one.sh index d2a033e8c..9826e725d 100755 --- a/test/validate/fail_jsonl_one.sh +++ b/test/validate/fail_jsonl_one.sh @@ -24,6 +24,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_jsonl_one_json.sh b/test/validate/fail_jsonl_one_json.sh index 9158a710b..062e06124 100755 --- a/test/validate/fail_jsonl_one_json.sh +++ b/test/validate/fail_jsonl_one_json.sh @@ -24,6 +24,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" --json > "$TMP/output.json" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" diff --git a/test/validate/fail_jsonl_one_json_verbose.sh b/test/validate/fail_jsonl_one_json_verbose.sh index a7c3d8d6d..237434e43 100755 --- a/test/validate/fail_jsonl_one_json_verbose.sh +++ b/test/validate/fail_jsonl_one_json_verbose.sh @@ -24,6 +24,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" --json --verbose > "$TMP/output.json" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.json" diff --git a/test/validate/fail_jsonl_one_verbose.sh b/test/validate/fail_jsonl_one_verbose.sh index 9c11dedec..158db194c 100755 --- a/test/validate/fail_jsonl_one_verbose.sh +++ b/test/validate/fail_jsonl_one_verbose.sh @@ -24,6 +24,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" --verbose 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_many.sh b/test/validate/fail_many.sh index 4940a17c7..33ccee1b0 100755 --- a/test/validate/fail_many.sh +++ b/test/validate/fail_many.sh @@ -39,6 +39,7 @@ EOF "$TMP/instance_3.json" \ 2> "$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_many_verbose.sh b/test/validate/fail_many_verbose.sh index e17ce8e1c..f9b681d38 100755 --- a/test/validate/fail_many_verbose.sh +++ b/test/validate/fail_many_verbose.sh @@ -39,6 +39,7 @@ EOF "$TMP/instance_3.json" \ --verbose 2> "$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_no_identifier_ref_without_resolve.sh b/test/validate/fail_no_identifier_ref_without_resolve.sh index c7c4961c6..5b92dce1d 100755 --- a/test/validate/fail_no_identifier_ref_without_resolve.sh +++ b/test/validate/fail_no_identifier_ref_without_resolve.sh @@ -22,7 +22,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" --verbose > "$TMP/output.txt" 2>&1 \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the reference to an external schema diff --git a/test/validate/fail_no_schema.sh b/test/validate/fail_no_schema.sh index 66865f478..432f2d1b7 100755 --- a/test/validate/fail_no_schema.sh +++ b/test/validate/fail_no_schema.sh @@ -8,7 +8,8 @@ clean() { rm -rf "$TMP"; } trap clean EXIT "$1" validate 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: This command expects a path to a schema and a path to an @@ -21,7 +22,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/validate/fail_relative_external_ref_missing.sh b/test/validate/fail_relative_external_ref_missing.sh index b28651fd9..255a04c39 100755 --- a/test/validate/fail_relative_external_ref_missing.sh +++ b/test/validate/fail_relative_external_ref_missing.sh @@ -25,7 +25,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the reference to an external schema @@ -40,7 +41,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_resolve_directory_with_invalid_json.sh b/test/validate/fail_resolve_directory_with_invalid_json.sh index 5b602352a..c8ee14c7d 100755 --- a/test/validate/fail_resolve_directory_with_invalid_json.sh +++ b/test/validate/fail_resolve_directory_with_invalid_json.sh @@ -33,7 +33,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/schemas" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -48,7 +49,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/schemas" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_resolve_enoent.sh b/test/validate/fail_resolve_enoent.sh index ca05f4326..ef293e5e2 100755 --- a/test/validate/fail_resolve_enoent.sh +++ b/test/validate/fail_resolve_enoent.sh @@ -23,7 +23,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/test" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: No such file or directory @@ -36,7 +37,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/test" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_resolve_invalid_id.sh b/test/validate/fail_resolve_invalid_id.sh index 88559e3ad..714657457 100755 --- a/test/validate/fail_resolve_invalid_id.sh +++ b/test/validate/fail_resolve_invalid_id.sh @@ -29,7 +29,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/resolve.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The identifier is not a valid URI @@ -45,7 +46,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/resolve.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_resolve_invalid_json.sh b/test/validate/fail_resolve_invalid_json.sh index 75d193cad..ca9ada49f 100755 --- a/test/validate/fail_resolve_invalid_json.sh +++ b/test/validate/fail_resolve_invalid_json.sh @@ -27,7 +27,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/invalid.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -42,7 +43,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/invalid.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_resolve_invalid_recursive_ref.sh b/test/validate/fail_resolve_invalid_recursive_ref.sh index 6a46b8a41..d2f8235cc 100755 --- a/test/validate/fail_resolve_invalid_recursive_ref.sh +++ b/test/validate/fail_resolve_invalid_recursive_ref.sh @@ -29,7 +29,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/resolve.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Invalid recursive reference @@ -43,7 +44,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/resolve.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_resolve_missing_core_vocabulary.sh b/test/validate/fail_resolve_missing_core_vocabulary.sh index 868aad3f5..46bdaf76e 100755 --- a/test/validate/fail_resolve_missing_core_vocabulary.sh +++ b/test/validate/fail_resolve_missing_core_vocabulary.sh @@ -39,7 +39,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/meta.json" --resolve "$TMP/resolve.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The core vocabulary must always be present @@ -51,7 +52,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/meta.json" --resolve "$TMP/resolve.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_resolve_missing_open_brace.sh b/test/validate/fail_resolve_missing_open_brace.sh index 8ec21b262..a499938bc 100755 --- a/test/validate/fail_resolve_missing_open_brace.sh +++ b/test/validate/fail_resolve_missing_open_brace.sh @@ -31,7 +31,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/invalid.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The file you provided does not represent a valid JSON Schema @@ -44,7 +45,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/invalid.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_resolve_relative_metaschema.sh b/test/validate/fail_resolve_relative_metaschema.sh index c8c6c6d91..ff9769b55 100755 --- a/test/validate/fail_resolve_relative_metaschema.sh +++ b/test/validate/fail_resolve_relative_metaschema.sh @@ -29,7 +29,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/resolve.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Relative meta-schema URIs are not valid according to the JSON Schema specification @@ -42,7 +43,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/resolve.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_resolve_unknown_dialect.sh b/test/validate/fail_resolve_unknown_dialect.sh index 2b8d0a72f..d1016057c 100755 --- a/test/validate/fail_resolve_unknown_dialect.sh +++ b/test/validate/fail_resolve_unknown_dialect.sh @@ -29,7 +29,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/resolve.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the metaschema of the schema @@ -44,7 +45,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" "$1" validate "$TMP/schema.json" "$TMP/instance.json" \ --resolve "$TMP/resolve.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_schema_directory.sh b/test/validate/fail_schema_directory.sh index b494f6ea3..cb86a0b41 100755 --- a/test/validate/fail_schema_directory.sh +++ b/test/validate/fail_schema_directory.sh @@ -15,7 +15,8 @@ EOF "$1" validate "$TMP/schema-directory" "$TMP/instance.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: The input was supposed to be a file but it is a directory @@ -27,7 +28,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema-directory" "$TMP/instance.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_schema_enoent.sh b/test/validate/fail_schema_enoent.sh index 803d64701..6594cad18 100755 --- a/test/validate/fail_schema_enoent.sh +++ b/test/validate/fail_schema_enoent.sh @@ -13,7 +13,8 @@ EOF "$1" validate "$TMP/foo.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: No such file or directory @@ -25,7 +26,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/foo.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_schema_invalid_json.sh b/test/validate/fail_schema_invalid_json.sh index ed4a04d5c..d341c4f36 100755 --- a/test/validate/fail_schema_invalid_json.sh +++ b/test/validate/fail_schema_invalid_json.sh @@ -19,7 +19,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" error: Failed to parse the JSON document @@ -33,7 +34,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Other input error +test "$EXIT_CODE" = "6" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_schema_non_schema.sh b/test/validate/fail_schema_non_schema.sh index eb272d5ee..12046a949 100755 --- a/test/validate/fail_schema_non_schema.sh +++ b/test/validate/fail_schema_non_schema.sh @@ -17,7 +17,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: The schema file you provided does not represent a valid JSON Schema @@ -29,7 +30,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_schema_unknown_dialect.sh b/test/validate/fail_schema_unknown_dialect.sh index cdbb39464..266cd8dc5 100755 --- a/test/validate/fail_schema_unknown_dialect.sh +++ b/test/validate/fail_schema_unknown_dialect.sh @@ -22,7 +22,8 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" error: Could not resolve the metaschema of the schema @@ -37,7 +38,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instance.json" --json >"$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Schema input error +test "$EXIT_CODE" = "4" || exit 1 cat << EOF > "$TMP/expected.txt" { diff --git a/test/validate/fail_trace.sh b/test/validate/fail_trace.sh index b7b9c9330..a5ba3791d 100755 --- a/test/validate/fail_trace.sh +++ b/test/validate/fail_trace.sh @@ -26,6 +26,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" --trace > "$TMP/output.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_trace_directory.sh b/test/validate/fail_trace_directory.sh index 5a76feacf..17f647edb 100755 --- a/test/validate/fail_trace_directory.sh +++ b/test/validate/fail_trace_directory.sh @@ -27,7 +27,8 @@ cat << 'EOF' > "$TMP/instances/instance_2.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instances" --trace 2> "$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: The `--trace/-t` option is only allowed given a single instance @@ -37,7 +38,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instances" --trace --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/validate/fail_trace_fast.sh b/test/validate/fail_trace_fast.sh index fdeecdbd0..f2d1668ff 100755 --- a/test/validate/fail_trace_fast.sh +++ b/test/validate/fail_trace_fast.sh @@ -26,6 +26,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.json" --trace --fast > "$TMP/output.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_trace_jsonl.sh b/test/validate/fail_trace_jsonl.sh index 8412524ca..96493c567 100755 --- a/test/validate/fail_trace_jsonl.sh +++ b/test/validate/fail_trace_jsonl.sh @@ -22,7 +22,8 @@ cat << 'EOF' > "$TMP/instances.jsonl" EOF "$1" validate "$TMP/schema.json" "$TMP/instances.jsonl" --trace 2> "$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: The `--trace/-t` option is only allowed given a single instance @@ -32,7 +33,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instances.jsonl" --trace --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/validate/fail_trace_multiple.sh b/test/validate/fail_trace_multiple.sh index 27f2d44ca..89fb26c59 100755 --- a/test/validate/fail_trace_multiple.sh +++ b/test/validate/fail_trace_multiple.sh @@ -25,7 +25,8 @@ cat << 'EOF' > "$TMP/instance_2.json" EOF "$1" validate "$TMP/schema.json" "$TMP/instance_1.json" "$TMP/instance_2.json" --trace 2> "$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" error: The `--trace/-t` option is only allowed given a single instance @@ -35,7 +36,8 @@ diff "$TMP/stderr.txt" "$TMP/expected.txt" # JSON error "$1" validate "$TMP/schema.json" "$TMP/instance_1.json" "$TMP/instance_2.json" --trace --json > "$TMP/stdout.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" -test "$EXIT_CODE" = "1" || exit 1 +# Invalid CLI arguments +test "$EXIT_CODE" = "5" || exit 1 cat << 'EOF' > "$TMP/expected.txt" { diff --git a/test/validate/fail_yaml.sh b/test/validate/fail_yaml.sh index 87c8a15b5..6189d41b4 100755 --- a/test/validate/fail_yaml.sh +++ b/test/validate/fail_yaml.sh @@ -21,6 +21,7 @@ EOF "$1" validate "$TMP/schema.yaml" "$TMP/instance.yaml" 2> "$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_yaml_multi_blank_lines.sh b/test/validate/fail_yaml_multi_blank_lines.sh index 4cdab5467..51e97460d 100755 --- a/test/validate/fail_yaml_multi_blank_lines.sh +++ b/test/validate/fail_yaml_multi_blank_lines.sh @@ -30,6 +30,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.yaml" --verbose 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_yaml_multi_one.sh b/test/validate/fail_yaml_multi_one.sh index 29c09433b..1ff53abcd 100755 --- a/test/validate/fail_yaml_multi_one.sh +++ b/test/validate/fail_yaml_multi_one.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.yaml" 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_yaml_multi_one_json.sh b/test/validate/fail_yaml_multi_one_json.sh index 49e215207..8e7a1c3fc 100755 --- a/test/validate/fail_yaml_multi_one_json.sh +++ b/test/validate/fail_yaml_multi_one_json.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.yaml" --json > "$TMP/stdout.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/validate/fail_yaml_multi_one_verbose.sh b/test/validate/fail_yaml_multi_one_verbose.sh index 053c7ddd9..ea48e38a0 100755 --- a/test/validate/fail_yaml_multi_one_verbose.sh +++ b/test/validate/fail_yaml_multi_one_verbose.sh @@ -27,6 +27,7 @@ EOF "$1" validate "$TMP/schema.json" "$TMP/instance.yaml" --verbose 2>"$TMP/stderr.txt" \ && EXIT_CODE="$?" || EXIT_CODE="$?" +# Validation failure test "$EXIT_CODE" = "2" || exit 1 cat << EOF > "$TMP/expected.txt"