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

Add support for doctests #52

Merged
merged 6 commits into from
Apr 30, 2020
Merged

Add support for doctests #52

merged 6 commits into from
Apr 30, 2020

Conversation

Freax13
Copy link
Member

@Freax13 Freax13 commented Apr 17, 2020

  • detect doctests as tests

@phil-opp
Copy link
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
Copy link
Member Author

Freax13 commented Apr 17, 2020

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
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
Copy link
Member Author

Freax13 commented Apr 23, 2020

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
Copy link
Member Author

Freax13 commented Apr 29, 2020

?

@phil-opp
Copy link
Member

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

@phil-opp
Copy link
Member

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

@Freax13
Copy link
Member Author

Freax13 commented Apr 29, 2020

that should have got rid of the warning

Copy link
Member

@phil-opp phil-opp left a comment

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
Member

Published as v0.7.10

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