Skip to content
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

Set rustdoc --test files' path relative to the current directory #39859

Merged
merged 3 commits into from
Feb 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 14 additions & 3 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,12 +1986,22 @@ actual:\n\
fn check_rustdoc_test_option(&self, res: ProcRes) {
let mut other_files = Vec::new();
let mut files: HashMap<String, Vec<usize>> = 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()
.replace('\\', "/"),
self.get_lines(&path, None));
}

let mut tested = 0;
Expand All @@ -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();
Expand Down