Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add filename when running rustdoc --test on a markdown file #39788

Merged
merged 1 commit into from
Feb 15, 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
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