Hacker News new | ask | show | jobs
by boustrophedon 2282 days ago
Rust has a feature that somewhat provides this - doctests[1]. Rust doc comments begin with `///` and will be parsed as markdown when generating documentation. If there are codeblocks in the documentation comments, they will be run with all other tests and the test runner will report if the blocks fail to compile or if they error at runtime.

So if the API changes, the example code in the documentation will fail to compile.

[1] https://doc.rust-lang.org/rustdoc/documentation-tests.html

1 comments

For anyone looking for something similar with JS, we wrote doctest-js: https://github.com/supabase/doctest-js

It allows you to write Unit Tests using JSDoc

It won't necessarily stop your documentation from building but offers another good reason to document your code