From 047a215b4d9cf762d3704ee02b76467897bbbe21 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 15 Feb 2017 22:47:11 +0100 Subject: [PATCH 1/3] Set rustdoc --test files' path relative to the current directory --- src/librustdoc/test.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 1c37067d7f69d..c7000ee1e40e7 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -12,7 +12,7 @@ use std::env; use std::ffi::OsString; use std::io::prelude::*; use std::io; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::panic::{self, AssertUnwindSafe}; use std::process::Command; use std::rc::Rc; @@ -485,7 +485,15 @@ impl Collector { pub fn get_filename(&self) -> String { if let Some(ref codemap) = self.codemap { - codemap.span_to_filename(self.position) + let filename = codemap.span_to_filename(self.position); + if let Ok(cur_dir) = env::current_dir() { + if let Ok(path) = Path::new(&filename).strip_prefix(&cur_dir) { + if let Some(path) = path.to_str() { + return path.to_owned(); + } + } + } + filename } else if let Some(ref filename) = self.filename { filename.clone() } else { From e606a43320323e702ec8f606bbbb0a1c083eaa55 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 19 Feb 2017 16:30:49 +0100 Subject: [PATCH 2/3] Fix rustdoc test with new file path --- src/tools/compiletest/src/runtest.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index d0aba8a0b0a7e..636100ef503cf 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1986,12 +1986,22 @@ actual:\n\ fn check_rustdoc_test_option(&self, res: ProcRes) { let mut other_files = Vec::new(); let mut files: HashMap> = HashMap::new(); - files.insert(self.testpaths.file.to_str().unwrap().to_owned(), + let cwd = env::current_dir().unwrap(); + files.insert(self.testpaths.file.strip_prefix(&cwd) + .unwrap_or(&self.testpaths.file) + .to_str() + .unwrap() + .replace('\\', "/"), self.get_lines(&self.testpaths.file, Some(&mut other_files))); for other_file in other_files { let mut path = self.testpaths.file.clone(); path.set_file_name(&format!("{}.rs", other_file)); - files.insert(path.to_str().unwrap().to_owned(), self.get_lines(&path, None)); + files.insert(path.strip_prefix(&cwd) + .unwrap_or(&path) + .to_str() + .unwrap() + .to_owned(), + self.get_lines(&path, None)); } let mut tested = 0; @@ -2001,7 +2011,8 @@ actual:\n\ let tmp: Vec<&str> = s.split(" - ").collect(); if tmp.len() == 2 { let path = tmp[0].rsplit("test ").next().unwrap(); - if let Some(ref mut v) = files.get_mut(path) { + if let Some(ref mut v) = files.get_mut( + &path.replace('\\', "/")) { tested += 1; let mut iter = tmp[1].split("(line "); iter.next(); From 958fbc5d66ce3773cbeb81911e4c4d69486ad1a3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 22 Feb 2017 23:19:03 +0100 Subject: [PATCH 3/3] Make path separator replacement for subfiles as well --- src/tools/compiletest/src/runtest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 636100ef503cf..652eb640d11f8 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2000,7 +2000,7 @@ actual:\n\ .unwrap_or(&path) .to_str() .unwrap() - .to_owned(), + .replace('\\', "/"), self.get_lines(&path, None)); }