-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
random doc tests fail with --persist-doctests
#69411
Comments
This seems to be an issue related to multi threading, because running this command
makes all tests succeed. |
I think I found the reason for the failure:
For example a doc-test in line 1 from So now imagine a crate structure like this src/ ├── lib.rs ├── module_1 │ ├── file.rs │ └── mod.rs └── module_2 ├── file.rs └── mod.rs where both Currently, they are treated like the same file, and they overwrite each other: target/doctests/ └── file_rs_1 └── rust_out The same issue is also caused in The problem is this piece of code let outdir = if let Some(mut path) = options.persist_doctests {
path.push(format!(
"{}_{}",
filename.to_string().rsplit('/').next().unwrap().replace(".", "_"),
line
));
std::fs::create_dir_all(&path).expect("Couldn't create directory for doctest executables");
DirState::Perm(path)
} Line 232 in 834bc56
An easy solution for the first problem would be to have folder names like this path.push(format!(
"{}_{}",
filename.to_string().replace("/", "_").replace(".", "_"),
line,
)); Then both tests would have unique names, I do not know how to fix the problem with the proc-macro. |
…ie27 improve folder name for persistent doc tests This partially fixes rust-lang#69411 by using the entire path as folder name, but I do not know how to deal with the proc-macro problem, where a doc test is forwarded to multiple generated functions, which have the same line for the doc test (origin). For example ```rust #[derive(ShortHand)] pub struct ExtXMedia { /// The [`MediaType`] associated with this tag. /// /// # Example /// -> /// ``` <- this line is given to `run_test` /// # use hls_m3u8::tags::ExtXMedia; /// use hls_m3u8::types::MediaType; /// /// let mut media = ExtXMedia::new(MediaType::Audio, "ag1", "english audio channel"); /// /// media.set_media_type(MediaType::Video); /// /// assert_eq!(media.media_type(), MediaType::Video); /// ``` /// /// # Note /// /// This attribute is required. #[shorthand(enable(copy))] media_type: MediaType, // the rest of the fields are omitted } ``` and my proc macro generates ```rust #[allow(dead_code)] impl ExtXMedia { /// The [`MediaType`] associated with this tag. /// /// # Example /// /// ``` /// # use hls_m3u8::tags::ExtXMedia; /// use hls_m3u8::types::MediaType; /// /// let mut media = ExtXMedia::new(MediaType::Audio, "ag1", "english audio channel"); /// /// media.set_media_type(MediaType::Video); /// /// assert_eq!(media.media_type(), MediaType::Video); /// ``` /// /// # Note /// /// This attribute is required. #[inline(always)] #[must_use] pub fn media_type(&self) -> MediaType { struct _AssertCopy where MediaType: ::std::marker::Copy; self.media_type } /// The [`MediaType`] associated with this tag. /// /// # Example /// /// ``` /// # use hls_m3u8::tags::ExtXMedia; /// use hls_m3u8::types::MediaType; /// /// let mut media = ExtXMedia::new(MediaType::Audio, "ag1", "english audio channel"); /// /// media.set_media_type(MediaType::Video); /// /// assert_eq!(media.media_type(), MediaType::Video); /// ``` /// /// # Note /// /// This attribute is required. #[inline(always)] pub fn set_media_type<VALUE: ::std::convert::Into<MediaType>>( &mut self, value: VALUE, ) -> &mut Self { self.media_type = value.into(); self } } ``` rustdoc then executes both tests with the same line (the line from the example above the field -> 2 different tests have the same name). We need a way to differentiate between the two tests generated by the proc-macro, so that they do not cause threading issues.
I have this repository: https://github.com/Luro02/hls_m3u8 and some time ago random doc tests started to fail with
cargo tarpaulin
(xd009642/tarpaulin#345).After some tinkering I narrowed it down to this command:
I would need some help with reducing the example :)
Meta
rustc --version --verbose
:Stdout
I think this is a bug of #56925
The text was updated successfully, but these errors were encountered: