Skip to content

Commit

Permalink
Add filename when running rustdoc --test on a markdown file
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Feb 13, 2017
1 parent 717ac96 commit cc8d455
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/librustdoc/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
let mut opts = TestOptions::default();
opts.no_crate_inject = true;
let mut collector = Collector::new(input.to_string(), cfgs, libs, externs,
true, opts, maybe_sysroot, None);
true, opts, maybe_sysroot, None,
Some(input.to_owned()));
find_testable_code(&input_str, &mut collector, DUMMY_SP);
test_args.insert(0, "rustdoctest".to_string());
testing::test_main(&test_args, collector.tests);
Expand Down
9 changes: 7 additions & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ pub fn run(input: &str,
false,
opts,
maybe_sysroot,
Some(codemap));
Some(codemap),
None);

{
let dep_graph = DepGraph::new(false);
Expand Down Expand Up @@ -391,12 +392,13 @@ pub struct Collector {
maybe_sysroot: Option<PathBuf>,
position: Span,
codemap: Option<Rc<CodeMap>>,
filename: Option<String>,
}

impl Collector {
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
use_headers: bool, opts: TestOptions, maybe_sysroot: Option<PathBuf>,
codemap: Option<Rc<CodeMap>>) -> Collector {
codemap: Option<Rc<CodeMap>>, filename: Option<String>) -> Collector {
Collector {
tests: Vec::new(),
names: Vec::new(),
Expand All @@ -411,6 +413,7 @@ impl Collector {
maybe_sysroot: maybe_sysroot,
position: DUMMY_SP,
codemap: codemap,
filename: filename,
}
}

Expand Down Expand Up @@ -483,6 +486,8 @@ impl Collector {
pub fn get_filename(&self) -> String {
if let Some(ref codemap) = self.codemap {
codemap.span_to_filename(self.position)
} else if let Some(ref filename) = self.filename {
filename.clone()
} else {
"<input>".to_owned()
}
Expand Down

0 comments on commit cc8d455

Please sign in to comment.