A JSON Schema test runner. More...
Classes | |
| struct | sourcemeta::blaze::TestCase |
| struct | sourcemeta::blaze::TestOutcome |
| struct | sourcemeta::blaze::TestTarget |
| struct | sourcemeta::blaze::TestSuite |
| class | sourcemeta::blaze::TestParseError |
Typedefs | |
| using | sourcemeta::blaze::TestTimestamp = std::chrono::steady_clock::time_point |
| using | sourcemeta::blaze::TestTargetResolver |
A JSON Schema test runner.
This functionality is included as follows:
| struct sourcemeta::blaze::TestCase |
Represents a single test case in a test suite
Static Public Member Functions | |
| static auto | parse (const sourcemeta::core::JSON &test_case_json, const sourcemeta::core::PointerPositionTracker &tracker, const std::filesystem::path &base_path, const sourcemeta::core::Pointer &location, const sourcemeta::core::PointerPositionTracker::Position &position) -> TestCase |
| Parse a single test case. | |
Public Attributes | |
| sourcemeta::core::JSON::String | description |
| The optional description of the test case. | |
| bool | valid |
| Whether the test data is expected to be valid against the schema. | |
| sourcemeta::core::JSON | data |
| The test data to validate. | |
| std::optional< sourcemeta::core::JSON > | rdf |
| The expected promotion of the test data to expanded-form JSON-LD. | |
| sourcemeta::core::PointerPositionTracker | tracker |
| The position tracker for error reporting on the data. | |
| sourcemeta::core::PointerPositionTracker::Position | position |
| The position of this test case in the test suite file. | |
| struct sourcemeta::blaze::TestOutcome |
Represents the outcome of evaluating a single test case against a target
Public Attributes | |
| bool | passed |
| Whether the test case passed overall. | |
| bool | valid |
| The actual validity outcome of the test data against the target. | |
| std::optional< sourcemeta::core::JSON > | rdf |
| The actual expansion, when RDF promotion ran and succeeded. | |
| std::optional< JSONLDResolutionError > | rdf_error |
| The resolution error, when RDF promotion failed. | |
| struct sourcemeta::blaze::TestTarget |
Where a target of a test document lives, as the caller resolved it
The document and the frame are borrowed rather than copied, and the exhaustive template of a target is compiled on the first request, so both must outlive the test suite
Public Attributes | |
| const sourcemeta::core::JSON & | document |
| const sourcemeta::core::SchemaFrame & | frame |
| sourcemeta::core::JSON::String | entrypoint |
| const sourcemeta::core::JSON& sourcemeta::blaze::TestTarget::document |
The document that holds the schema under test, which may be that schema or a wrapper that holds it, such as an OpenAPI description
| sourcemeta::core::JSON::String sourcemeta::blaze::TestTarget::entrypoint |
The URI of the schema under test, which the frame must locate. This is typically the target itself, as what a test document names a schema by and what framing the document it lives in keys that schema by are the same URI. An empty string names whatever the frame was rooted at
| const sourcemeta::core::SchemaFrame& sourcemeta::blaze::TestTarget::frame |
The frame of the schemas that the document holds. For a wrapper, this is what framing the places it keeps its schemas in reports, such as what sourcemeta::core::OpenAPIFrame::schemas returns
| struct sourcemeta::blaze::TestSuite |
Represents a test suite containing multiple test cases
A test suite does not resolve or frame anything. The caller hands over the document that holds each target, a frame of the schemas in it, and where in it the schema under test sits. That is what lets a target name a schema inside a document that is not a schema itself, such as an OpenAPI description, without this module knowing anything about wrappers
Public Types | |
| using | Callback |
| A callback invoked for each test case during execution. | |
Public Member Functions | |
| auto | fast (std::size_t target_index) const -> const Template & |
| The compiled schema template for fast validation of the given target. | |
| auto | exhaustive (std::size_t target_index) -> const Template & |
| auto | run (const Callback &callback) -> Result |
Static Public Member Functions | |
| static auto | parse (const sourcemeta::core::JSON &document, const sourcemeta::core::PointerPositionTracker &tracker, const std::filesystem::path &base_path, const TestTargetResolver &target_resolver, const sourcemeta::core::SchemaResolver &schema_resolver, const sourcemeta::core::SchemaWalker &walker, const Compiler &compiler, const std::optional< Tweaks > &tweaks=std::nullopt) -> TestSuite |
Public Attributes | |
| std::vector< sourcemeta::core::JSON::String > | targets |
| std::vector< TestCase > | tests |
| The list of test cases in the suite. | |
| Evaluator | evaluator |
| The evaluator instance used for validation. | |
A callback invoked for each test case during execution.
| auto sourcemeta::blaze::TestSuite::exhaustive | ( | std::size_t | target_index | ) | ->constTemplate & |
The compiled schema template for exhaustive validation of the given target, compiled on the first request and cached from then on. A test suite must not be shared across threads
|
static |
Parse a test suite from a JSON object, resolving and compiling every target that it names. For example:
The frame that a target resolves to must contain reference information for the document it frames, and that document must be bundled, which are the same pre-conditions that the overload of sourcemeta::blaze::compile taking a frame states. The frame must also locate the entry point, so a document is framed under the base that the target was resolved against rather than under no base at all
Run all test cases in the suite, invoking the callback for each. For example:
A target that names a schema inside a document that is not a schema itself is reached the same way, by handing over that document and a frame of the schemas it holds. Nothing else about it differs, as framing a document under the base it was read from keys a schema within it by that base and the place it sits in, which is what the target spells:
| std::vector<sourcemeta::core::JSON::String> sourcemeta::blaze::TestSuite::targets |
The target schema URIs or file paths, resolved against the location of the test document
| class sourcemeta::blaze::TestParseError |
An error that occurs when parsing a test file
How to reach what a target names, invoked once per target of a test document in the order that the document lists them
| using sourcemeta::blaze::TestTimestamp = std::chrono::steady_clock::time_point |
The monotonic timestamp type used for timing measurements