Marwes / schemafy

Crate for generating rust types from a json schema
MIT License
242 stars 51 forks source link

Test against (part of) the JSON Schema Test Suite #24

Closed adeschamps closed 4 years ago

adeschamps commented 4 years ago

See #16.

This adds the JSON Schema Test Suite repository as a submodule in the tests/ directory. It also adds another binary target which reads the JSON files containing the tests, extracts the schemas to separate files (placed in tests/test_suite/schemas/<test_name>_<index>.json), and generates a .rs file which generates types from the schema and checks whether the sample data does or does not parse.

The code generator, in src/generate_tests.rs, can be run with cargo run --bin generate-tests. It contains a function called is_blacklisted(), which is used to skip the majority of the tests in the test suite.

I think it would take quite a lot of work to get schemafy to pass the test suite, but hopefully this provides at least a bit of value in terms of test coverage, and helps people trying to add new features.


Note: If you don't run git submodule update --init and then cargo run --bin generate-tests, then cargo test will fail. It would be easy to change things around so that running the test suite is optional.

Marwes commented 4 years ago

Nice! Thanks!