wasmerio / wasmer-ruby

💎🕸 WebAssembly runtime for Ruby
https://wasmer.io
MIT License
465 stars 18 forks source link

test+doc: Doctests are now tested via `rustdoc` #51

Closed Hywan closed 3 years ago

Hywan commented 3 years ago

rustdoc will run the Rust doctests. Those latters use rutie-test which defines the test_ruby! macro. This macro runs the code of the doctest inside the Ruby VM.

So for example, when one writes:

/// ```rust
/// # fn main() { rutie_test::test_ruby!(r#"
/// true
/// # "#); }
/// ```

rustdoc will generate in HTML a code block that only contains:

true

but it will generate a test that will contain:

fn main() {
    rutie_test::test_ruby!("true");
}

And this Ruby code (here, true), will be evaluated inside the Ruby VM.

It's a very naive solution. The path to rutie is hardcoded for example, and RbConfig is not found, so I had to hardcode it myself. It's very likely to break in the future, but for the moment, it works and it allows us to deliver a correct documentation with correct examples to our users.