]> git.lizzy.rs Git - rust.git/commitdiff
Set rustdoc --test files' path relative to the current directory
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 15 Feb 2017 21:47:11 +0000 (22:47 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 16 Feb 2017 21:35:29 +0000 (22:35 +0100)
src/librustdoc/test.rs

index 1c37067d7f69d46f8914db8fd4ed496dec3eccd9..c7000ee1e40e764f5a79837cd2149cc24d891a71 100644 (file)
@@ -12,7 +12,7 @@
 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 @@ pub fn set_position(&mut self, position: Span) {
 
     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 {