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

tarpaulin fails to run doc-test in readme #924

Open
danieleades opened this issue Jan 3, 2022 · 5 comments
Open

tarpaulin fails to run doc-test in readme #924

danieleades opened this issue Jan 3, 2022 · 5 comments
Assignees

Comments

@danieleades
Copy link
Contributor

danieleades commented Jan 3, 2022

I have a doc-test in my README, which i'm including like so-

// lib.rs
#![doc = include_str!("../README.md")]

this works a treat for making sure my readme stays aligned with the code, but tarpaulin doesn't seem to like it.

You can see the job output here- https://github.com/danieleades/config2/runs/4693934507?check_suite_focus=true

the code example has a no_run annotation, which cargo test is respecting, but tarpaulin apparently isn't

@danieleades
Copy link
Contributor Author

i'm sorry to keep popping up like this!

@danieleades
Copy link
Contributor Author

tried adding some test cases in #926, as i thought it was time you got a pull request from me instead of just issues. It's not a complete test though.

From the code I would imagine it should work, since you're just searching an entire file for the text 'no_run'. Shouldn't matter how the attributes are formatted.

Which i guess means the actual issue is a little more subtle

@xd009642
Copy link
Owner

xd009642 commented Jan 4, 2022

Ah I gave it a moments thought and I see what happened. So when you run cargo test for doc tests the no-run etc is chosen after it builds the doc tests. But I don't get that meta information. And the binary name for the generated doc test is generated from file name and line number of the doc test (with an addition number at the end as name collisions are possible). So I get a list of doc tests and from them work out potential source locations for the doc test. And then map the attributes at those locations to the guessed source location (guessed because there can be collisions).

Now obviously this doesn't currently handle include_str! - or indeed any include statement at all. Meaning those line counts will be wrong and no_run attributes can't be mapped back to the correct locations. The simple solution is probably to do a pass over the loaded files and spot any includes and do the includes manually on the file contents to create a post-processed file as I don't currently see a way to sort out that information using the tools cargo gives us for doc tests. It shouldn't be too difficult just mildly faffy.

Also, for generated code that may be in include!(concat!(env!("RUST_OUT"), "/generated.rs")); from libraries like prost any doc tests after the include statement will likely have an incorrect attribute mapping... But I think that's even harder to solve and may just be relegated to a TODO comment for now for the next time someone encounters this issue.

I won't have time today or tomorrow to work on this, but I'll aim to get to it during the week at some point. If you want to work on it though I'm fine with that just ideally let me know so there's not too much duplicated effort 😅

@danieleades
Copy link
Contributor Author

Any possibility of better upstream support from Cargo?

@xd009642
Copy link
Owner

xd009642 commented Jan 5, 2022

Potentially, I believe the code responsible for it is in rustc, it is an area which currently has no stability guarantees (to my knowledge). But I'll raise something this week and see if anyone has objections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants