Skip to content

Commit

Permalink
Change how Schema Store must-fail tests are handled.
Browse files Browse the repository at this point in the history
The allowlist (exceptions designed for the regular tests that are believed wrong when the standard is carefully studied) is no longer used. Instead they're simply expected to fail.
  • Loading branch information
jimblacklercorp committed Oct 15, 2021
1 parent 526bfbe commit 693a455
Show file tree
Hide file tree
Showing 26 changed files with 25 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import static net.jimblackler.jsonschemafriend.ReaderUtils.getLines;
import static net.jimblackler.jsonschemafriend.ResourceUtils.getResource;
import static net.jimblackler.jsonschemafriend.ResourceUtils.getResourceAsStream;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import com.fasterxml.jackson.core.util.DefaultIndenter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
Expand Down Expand Up @@ -34,15 +36,15 @@ public class SchemaStoreTest {

@TestFactory
Collection<DynamicNode> all() {
return test("test");
return test("test", false);
}

@TestFactory
Collection<DynamicNode> allNegative() {
return test("negative_test");
return test("negative_test", true);
}

private Collection<DynamicNode> test(String dirName) {
private Collection<DynamicNode> test(String dirName, boolean mustFail) {
ObjectMapper objectMapper = new ObjectMapper();
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);
Expand Down Expand Up @@ -106,26 +108,32 @@ private Collection<DynamicNode> test(String dirName) {
URI outputSchema =
URI.create("https://json-schema.org/draft/2020-12/output/schema#/$defs/basic");
Schema outputValidator = schemaStore.loadSchema(outputSchema);
new Validator().validate(outputValidator, output, errorHandler);
new Validator().validate(outputValidator, output, validationError -> fail());
schema.validateExamplesRecursive(validator, errorHandler);
validator.validate(schema, o, errorHandler);
if (new File("schemaStoreErrors").exists()) {
if (allErrors.isEmpty()) {
errorsPath.toFile().delete();
} else {
Path schemaStoreErrors = FILE_SYSTEM.getPath("schemaStoreErrors");
Files.createDirectories(schemaStoreErrors.resolve(schemaName));
try (FileWriter w = new FileWriter(
schemaStoreErrors.resolve(schemaName).resolve(testFileName).toString())) {
objectWriter.writeValue(w, allErrors);
if (mustFail) {
assertFalse(allErrors.isEmpty(), "No errors reported in must-fail test");
}

if (!mustFail) {
if (new File("schemaStoreErrors").exists()) {
if (allErrors.isEmpty()) {
errorsPath.toFile().delete();
} else {
Path schemaStoreErrors = FILE_SYSTEM.getPath("schemaStoreErrors");
Files.createDirectories(schemaStoreErrors.resolve(schemaName));
try (FileWriter w = new FileWriter(
schemaStoreErrors.resolve(schemaName).resolve(testFileName).toString())) {
objectWriter.writeValue(w, allErrors);
}
}
}
}

System.out.println(objectWriter.writeValueAsString(output));
System.out.println(objectWriter.writeValueAsString(output));

assertTrue(extraReported.isEmpty(), "Errors reported not seen in reference file");
assertTrue(notReported.isEmpty(), "Errors in reference file not reported");
assertTrue(extraReported.isEmpty(), "Errors reported not seen in reference file");
assertTrue(notReported.isEmpty(), "Errors in reference file not reported");
}
}));
});
testsOut.add(
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 693a455

Please sign in to comment.