Skip to content

Commit 047a215

Browse files
Set rustdoc --test files' path relative to the current directory
1 parent 62eb605 commit 047a215

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/librustdoc/test.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::env;
1212
use std::ffi::OsString;
1313
use std::io::prelude::*;
1414
use std::io;
15-
use std::path::PathBuf;
15+
use std::path::{Path, PathBuf};
1616
use std::panic::{self, AssertUnwindSafe};
1717
use std::process::Command;
1818
use std::rc::Rc;
@@ -485,7 +485,15 @@ impl Collector {
485485

486486
pub fn get_filename(&self) -> String {
487487
if let Some(ref codemap) = self.codemap {
488-
codemap.span_to_filename(self.position)
488+
let filename = codemap.span_to_filename(self.position);
489+
if let Ok(cur_dir) = env::current_dir() {
490+
if let Ok(path) = Path::new(&filename).strip_prefix(&cur_dir) {
491+
if let Some(path) = path.to_str() {
492+
return path.to_owned();
493+
}
494+
}
495+
}
496+
filename
489497
} else if let Some(ref filename) = self.filename {
490498
filename.clone()
491499
} else {

0 commit comments

Comments
 (0)