Skip to content

Add support for doctests - #52

Merged
phil-opp merged 6 commits into
rust-osdev:masterfrom
Freax13:master
Apr 30, 2020
Merged

Add support for doctests#52
phil-opp merged 6 commits into
rust-osdev:masterfrom
Freax13:master

Conversation

@Freax13

@Freax13 Freax13 commented Apr 17, 2020

Copy link
Copy Markdown
Member
  • detect doctests as tests

@phil-opp

Copy link
Copy Markdown
Member

Thanks for the PR! Could you clarify how you're using doc tests with bootimage? As far as I know, doc tests don't work in combination with custom test frameworks.

@Freax13

Freax13 commented Apr 17, 2020

Copy link
Copy Markdown
Member Author

first of all I should note that this isn't working rn because of a bug in cargo (rust-lang/cargo#8094)

i'm using something similar to cargo xtest --target bare_x86_64.json -Z doctest-xcompile to run the doctests

doctests don't work with custom test frameworks. rustdoc basically just individually wraps the code for each test in a main method (unless you provide your own) and compiles it.

example from my code:

/// acquire the lock
/// ```
/// # #![cfg_attr(target_os = "none", no_std, no_main)]
/// # lemon_std::entry_point!(test);
/// # async fn test() {
/// # use lemon_std::sync::SpinMutex;
/// let lock = SpinMutex::new("Foo");
/// lock.lock();
/// # lemon_std::arch::exit(true);
/// # }
/// # main();
/// ```
pub fn lock(&self) -> SpinMutexGuard<'_, D> {

@phil-opp

Copy link
Copy Markdown
Member

Thanks for the clarification! I wasn't aware of the -Z doctest-xcompile, but it's great to see that docstests are coming to no_std applications.

doctests don't work with custom test frameworks. rustdoc basically just individually wraps the code for each test in a main method (unless you provide your own) and compiles it.

So they're basically integration tests with disabled test harness (as described in https://os.phil-opp.com/testing/#no-harness-tests)?

first of all I should note that this isn't working rn because of a bug in cargo (rust-lang/cargo#8094)

I think it might make sense to delay merging this PR until this cargo bug is resolved and we can actually try whether this PR works. It might be also a good idea to add an automated test for this then to check the behavior on CI and ensure that we don't break it on future changes. Would that be okay with you?

@Freax13

Freax13 commented Apr 23, 2020

Copy link
Copy Markdown
Member Author

So they're basically integration tests with disabled test harness (as described in https://os.phil-opp.com/testing/#no-harness-tests)?

pretty much, yeah

I think it might make sense to delay merging this PR until this cargo bug is resolved and we can actually try whether this PR works.

rust 1.43 just got released, so the latest cargo on nightly finally contains the fix. do you want me to write an example for doctests (probably something similar to test-basic-boot)?

@Freax13

Freax13 commented Apr 29, 2020

Copy link
Copy Markdown
Member Author

?

@phil-opp

Copy link
Copy Markdown
Member

Sorry for the delay! Yes, I think some example that is tested on CI would be great.

@phil-opp

Copy link
Copy Markdown
Member

There are a few warnings for the new doctest test, otherwise this looks very good.

@Freax13

Freax13 commented Apr 29, 2020

Copy link
Copy Markdown
Member Author

that should have got rid of the warning

@phil-opp phil-opp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks a lot!

@phil-opp
phil-opp merged commit d2936f9 into rust-osdev:master Apr 30, 2020
@phil-opp phil-opp changed the title add detection for doctests Add support for doctests Apr 30, 2020
phil-opp added a commit that referenced this pull request Apr 30, 2020
@phil-opp

Copy link
Copy Markdown
Member

Published as v0.7.10

MiscStuff839 pushed a commit to MiscStuff839/bootimage-wasm that referenced this pull request Nov 16, 2025
MiscStuff839 pushed a commit to MiscStuff839/bootimage-wasm that referenced this pull request Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants