Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 11 commits into from
May 17, 2021

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented May 11, 2021

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.

Hywan added 2 commits May 11, 2021 16:18
`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
/// ```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:

```rust
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.
@Hywan Hywan added 🤖 bot Bip bip 📚 documentation Do you like to read? 🧪 tests I love tests labels May 11, 2021
@Hywan Hywan self-assigned this May 11, 2021
@Hywan Hywan added this to 🌱 In progress in Kanban via automation May 11, 2021
@Hywan Hywan merged commit 408e41a into wasmerio:master May 17, 2021
Kanban automation moved this from 🌱 In progress to 🎉 Done May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 bot Bip bip 📚 documentation Do you like to read? 🧪 tests I love tests
Projects
Kanban
  
🎉 Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant