Skip to content

Commit

Permalink
Rollup merge of #79413 - Swatinem:rustdoc-persist-crate, r=GuillaumeG…
Browse files Browse the repository at this point in the history
…omez

Fix persisted doctests on Windows / when using workspaces

When using the unstable `--persist-doctests` option,
Windows path separators were not escaped properly. Also when running
the command in a workspace, crate files can overwrite each other.

Before: `src\lib_rs_1_0\rust_out`
After: `\crate_a_src_lib_rs_1_0\rust_out`, `\crate_b_src_lib_rs_1_0\rust_out`
  • Loading branch information
jonas-schievink authored Nov 26, 2020
2 parents 7b72379 + 1d587d8 commit eb74eb7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,14 @@ impl Tester for Collector {
let folder_name = filename
.to_string()
.chars()
.map(|c| if c == '/' || c == '.' { '_' } else { c })
.map(|c| if c == '\\' || c == '/' || c == '.' { '_' } else { c })
.collect::<String>();

path.push(format!(
"{name}_{line}_{number}",
name = folder_name,
"{krate}_{file}_{line}_{number}",
krate = cratename,
file = folder_name,
line = line,
number = {
// Increases the current test number, if this file already
// exists or it creates a new entry with a test number of 0.
Expand All @@ -768,7 +770,6 @@ impl Tester for Collector {
.and_modify(|v| *v += 1)
.or_insert(0)
},
line = line,
));

std::fs::create_dir_all(&path)
Expand Down

0 comments on commit eb74eb7

Please sign in to comment.