Tehforsch / diman

Define rust compile time unit systems using const generics
52 stars 2 forks source link

Improve doctest situation #58

Open Tehforsch opened 8 months ago

Tehforsch commented 8 months ago

At the moment, the doctests are a bit annoying to maintain and easy to forget about for a few reasons:

  1. Every doctest needs the unstable feature gates as a setup, which is annoying to type.
  2. Due to a namespacing issue that I don't fully understand, I have to wrap any doctest using the unit_system macro in an internal module.
  3. These things conflict with loading the lib.rs doctests directly from the readme (because the lines starting with # won't show when looking up the doctest, but they will show up in the readme).
  4. There are a few features hidden behind feature gates which I currently don't deal with at all and simply ignore those doctests.

For these reasons, many of the doctests are currently set to ignore although they run fine (and I check every now and then by adding their setup code again).

For 1-3 to I am not sure how to deal with this aside from adding a bit of machinery to generate these tests (and possibly generate a readme as well). Unfortunately adding some kind of prelude that can be included easily does not work for 1/2, since feature gates need to be declared on top of the doctest and the module also needs to be defined around the entire doctest.

I think 4 is dealt with by https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html which seems easy enough to use.

jedbrown commented 8 months ago

Have you considered scraping examples for the inline documentation?

https://doc.rust-lang.org/rustdoc/scraped-examples.html

Tehforsch commented 8 months ago

Have you considered scraping examples for the inline documentation?

Oh, nice - I didn't know about this feature. I don't think it will help with unit_system, since it doesnt seem to scrape usage of proc macros, but this could be very useful for documenting some of the methods on quantity, because we could have many examples in one file and it shows only the small part of the example that applies to the function, so none of the ugly unstable features are shown.