-
Notifications
You must be signed in to change notification settings - Fork 22
Seperate doc tests into separate stages #218
base: master
Are you sure you want to change the base?
Conversation
Nice, I really like the direction this PR is taking! A couple of things:
|
let program = tokens.to_string(); | ||
|
||
program | ||
} else { | ||
// If we couldn't parse the crate, then test compilation will fail anyways. Just wrap | ||
// everything in a main function. | ||
format!("fn main() {{\n{}\n}}", test) | ||
// everything in a test function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this backwards-compatible? This is a deviation from what the current rustdoc does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to make it backwards compatible, but am running into some challenges. There were two things, single binary and actual tests, that I was trying to accomplish. I may have to land this PR and tackle turning them into tests later.
src/lib.rs
Outdated
@@ -213,82 +211,11 @@ pub fn test(config: &Config) -> Result<()> { | |||
})?; | |||
let docs: Documentation = serde_json::from_reader(doc_json)?; | |||
|
|||
let krate = docs.data.as_ref().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
// TODO make this a different function | ||
// filter test names into valid identifiers that can be put into `mod #ident` | ||
let name = name.replace("::", "_"); | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray comment markers
Thank you for the review!
There seems to be a bug where the tests do not get parsed out into a file. I am working on tracking it down.
Yes, great idea. I will do this. |
this is gonna need a rebase |
@steveklabnik yup. i have also made some changes and am in the process of tracking down a bug where the tests do not get built every time. seems to be there prior to this patch too. beyond that, are we good with changing the doc tests into actual tests? as @euclio mentioned, it is a change to the way existing rustdoc works. |
I'm happy with not worrying about compatibility right now. We can work on that later. |
Oh one more thing: it seems that master's tests are failing, dunno whats up with that. If you get CI in the same place, we can and fix those issues some other way. |
I pushed some more commits. Give me another pass to make sure this change is sound and then we can merge and work on the edge cases, etc. |
@steveklabnik This change is working pretty well. There are some outstanding issues listed below. If we land this PR, then I will make an issue for each and start working on them. Otherwise, I can try to address those issues in this PR. Outstanding issues I will open issues for and fix:
|
When generating documentation tests, the following stages will happen: - tests will be gathered from the docs as a list of strings - tests will be saved to target/doc/tests as individual files - tests will be compiled into a single binary called "rustdoc-test" - tests will be run by executing the "rustdoc-test" binary Doc tests are now actual tests. This allows us to take advantage of the existing test infrastructure supplied by rustc. Fixes steveklabnik#32, steveklabnik#54, steveklabnik#219
Now that https://github.com/dtolnay/syn is on |
When generating documentation tests, the following stages will happen:
Doc tests are now actual tests. This allows us to take advantage of the
existing test infrastructure supplied by rustc.
Fixes #32, #54