Add filename when running rustdoc --test on a markdown file
This commit is contained in:
parent
717ac960b5
commit
cc8d455895
@ -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);
|
||||
|
@ -104,7 +104,8 @@ pub fn run(input: &str,
|
||||
false,
|
||||
opts,
|
||||
maybe_sysroot,
|
||||
Some(codemap));
|
||||
Some(codemap),
|
||||
None);
|
||||
|
||||
{
|
||||
let dep_graph = DepGraph::new(false);
|
||||
@ -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(),
|
||||
@ -411,6 +413,7 @@ pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: Ext
|
||||
maybe_sysroot: maybe_sysroot,
|
||||
position: DUMMY_SP,
|
||||
codemap: codemap,
|
||||
filename: filename,
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,6 +486,8 @@ 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)
|
||||
} else if let Some(ref filename) = self.filename {
|
||||
filename.clone()
|
||||
} else {
|
||||
"<input>".to_owned()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user