yshavit / mdq

MIT License
1 stars 0 forks source link

add end-to-end tests #92

Open yshavit opened 6 days ago

yshavit commented 6 days ago

It'd be cool if I could have a dir that contains yamls, where each yaml is something like:

given: |
  <markdown contents>
check:
  - ["# my selector"]: |
    <expected markdown for section>
  - [--some-switch, "[]()"]: |
    <expected markdown for links>
  - ...

... and then be able to turn that into a bunch of tests.

This would (a) be useful to have, just for testing; but also (b) be good for documentation of examples.

Ideally, each of those check cases would be a separate sub-test; but I think that would require parsing the yaml at compile-time (so that I can use it in a macro), and I don't know if any libraries allow that.

I do think keeping the md and checks in one file (as opposed to something like test-1.md + test-1-check-1.txt) is useful, because it lets you see the inputs and outputs together more easily.

yshavit commented 6 days ago

(note: marking this as "enhancement" and not "task" because of the public-facing nature of the examples. see also #85)

yshavit commented 6 days ago

I may be able to use a build script for this: https://doc.rust-lang.org/cargo/reference/build-scripts.html

Also, it looks like the main yaml parser library is in archive mode and not getting any new updates, so I should consider another format. Maybe toml?

yshavit commented 6 days ago

(It'd be tempting to use markdown for these tests, but then I wouldn't be able to detect certain failure modes. For example, if the selector # Test cases | - * erroneously always returned an empty stream, then all of the files would have no test cases, and thus no test cases would fail! I could work around that, but I think it's best to keep it simple and just do the tests in another language.)

yshavit commented 6 days ago

ah, this one is still maintained: https://docs.rs/serde_yml/latest/serde_yml/