Stranger6667 / jsonschema-rs

JSON Schema validation library
https://docs.rs/jsonschema
MIT License
482 stars 90 forks source link

How to run the unit tests? #443

Closed OrangeTux closed 4 months ago

OrangeTux commented 6 months ago

How do I execute the unit tests?

I ran cargo test in jsonschema/, but that fails with:

jsonschema/ $ cargo test
error: custom attribute panicked
 --> tests/test_suite.rs:5:1
  |
5 | #[json_schema_test_suite("tests/suite", "draft4", {"optional_bignum_0_0", "optional_bignum_2_0"})]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: Tests directory not found: tests/suite/tests/draft4

I solved this particular issue by cloning the repository https://github.com/json-schema-org/JSON-Schema-Test-Suite and copying the tests/ folder to jsonschema/tests/suite.

That resulted in another error:

jsonschema/ $ cargo test
error: custom attribute panicked
 --> tests/test_suite.rs:5:1
  |
5 | #[json_schema_test_suite("tests/suite", "draft4", {"optional_bignum_0_0", "optional_bignum_2_0"})]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: Remotes directory not found: tests/suite/remotes
OrangeTux commented 6 months ago

I think I solved my problem, but ran in new ones.

First of all, one should copy the the entire content of https://github.com/json-schema-org/JSON-Schema-Test-Suite to jsonschema/tests/suite.

One way of doing that is cloning the repository to that location:

jsonschema/ $ git clone https://github.com/json-schema-org/JSON-Schema-Test-Suite.git tests/suite 

cargo run executes all tests. However, a lot of them fail:

$ jsonschema/ $ cargo test
...
failures:
    test_draft_draft4::optional_bignum_0_1
    test_draft_draft4::optional_ecmascript_regex_16_1
    test_draft_draft4::optional_ecmascript_regex_16_2
    test_draft_draft4::optional_ecmascript_regex_18_2
    test_draft_draft4::refRemote_7_0
    test_draft_draft4::refRemote_7_1
    test_draft_draft4::ref_6_0
    test_draft_draft4::ref_6_1
    test_draft_draft6::maxItems_1_0
    test_draft_draft6::maxItems_1_1
    test_draft_draft6::maxLength_1_0
    test_draft_draft6::maxLength_1_1
    test_draft_draft6::maxProperties_1_0
    test_draft_draft6::maxProperties_1_1
    test_draft_draft6::minItems_1_0
    test_draft_draft6::minItems_1_1
    test_draft_draft6::minLength_1_0
    test_draft_draft6::minLength_1_1
    test_draft_draft6::minProperties_1_0
    test_draft_draft6::minProperties_1_1
    test_draft_draft6::optional_ecmascript_regex_16_1
    test_draft_draft6::optional_ecmascript_regex_16_2
    test_draft_draft6::optional_ecmascript_regex_18_2
    test_draft_draft6::refRemote_10_0
    test_draft_draft6::refRemote_10_1
    test_draft_draft6::refRemote_8_0
    test_draft_draft6::refRemote_8_1
    test_draft_draft6::ref_6_0
    test_draft_draft6::ref_6_1
    test_draft_draft7::maxItems_1_0
    test_draft_draft7::maxItems_1_1
    test_draft_draft7::maxLength_1_0
    test_draft_draft7::maxLength_1_1
    test_draft_draft7::maxProperties_1_0
    test_draft_draft7::maxProperties_1_1
    test_draft_draft7::minItems_1_0
    test_draft_draft7::minItems_1_1
    test_draft_draft7::minLength_1_0
    test_draft_draft7::minLength_1_1
    test_draft_draft7::minProperties_1_0
    test_draft_draft7::minProperties_1_1
    test_draft_draft7::optional_cross_draft_0_0
    test_draft_draft7::optional_ecmascript_regex_16_1
    test_draft_draft7::optional_ecmascript_regex_16_2
    test_draft_draft7::optional_ecmascript_regex_18_2
    test_draft_draft7::optional_format_time_0_10
    test_draft_draft7::optional_format_time_0_13
    test_draft_draft7::optional_format_time_0_16
    test_draft_draft7::optional_format_time_0_17
    test_draft_draft7::optional_format_time_0_20
    test_draft_draft7::optional_format_time_0_21
    test_draft_draft7::optional_format_time_0_24
    test_draft_draft7::refRemote_10_0
    test_draft_draft7::refRemote_10_1
    test_draft_draft7::refRemote_8_0
    test_draft_draft7::refRemote_8_1
    test_draft_draft7::ref_6_0
    test_draft_draft7::ref_6_1
    test_instance_path

test result: FAILED. 3235 passed; 59 failed; 57 ignored; 0 measured; 0 filtered out; finished in 0.56s

Do you have any suggestions?

Stranger6667 commented 6 months ago

The project uses a specific commit from that repo via a git submodule. git submodule init and git submodule update should do the trick, but I guess the project will benefit from contributing docs.

OrangeTux commented 6 months ago

I see. Thanks! I'll open a PR soon to fix the documentation.