Remove dependency on error handling from find_testable_code
This commit is contained in:
parent
de5cebdba5
commit
03e34f8f81
3 changed files with 24 additions and 13 deletions
|
|
@ -34,10 +34,8 @@ use std::fmt::{self, Write};
|
|||
use std::borrow::Cow;
|
||||
use std::ops::Range;
|
||||
use std::str;
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
use syntax::codemap::Span;
|
||||
use errors;
|
||||
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
use html::render::derive_id;
|
||||
use html::toc::TocBuilder;
|
||||
use html::highlight;
|
||||
|
|
@ -469,10 +467,17 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for Footnotes<'a, I> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Span,
|
||||
handler: &errors::Handler) {
|
||||
tests.set_position(position);
|
||||
pub struct TestableCodeError(());
|
||||
|
||||
impl fmt::Display for TestableCodeError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "invalid start of a new code block")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_testable_code(
|
||||
doc: &str, tests: &mut test::Collector
|
||||
) -> Result<(), TestableCodeError> {
|
||||
let is_nightly = UnstableFeatures::from_environment().is_nightly_build();
|
||||
let mut parser = Parser::new(doc);
|
||||
let mut prev_offset = 0;
|
||||
|
|
@ -516,8 +521,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
|
|||
tests.add_test(text, block_info, line);
|
||||
prev_offset = offset;
|
||||
} else {
|
||||
handler.span_warn(position, "invalid start of a new code block");
|
||||
break;
|
||||
return Err(TestableCodeError(()));
|
||||
}
|
||||
}
|
||||
Event::Start(Tag::Header(level)) => {
|
||||
|
|
@ -535,6 +539,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug)]
|
||||
|
|
|
|||
|
|
@ -156,7 +156,11 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
|
|||
true, opts, maybe_sysroot, None,
|
||||
Some(PathBuf::from(input)),
|
||||
linker, edition);
|
||||
find_testable_code(&input_str, &mut collector, DUMMY_SP, diag);
|
||||
collector.set_position(DUMMY_SP);
|
||||
let res = find_testable_code(&input_str, &mut collector);
|
||||
if let Err(err) = res {
|
||||
diag.span_warn(DUMMY_SP, &err.to_string());
|
||||
}
|
||||
test_args.insert(0, "rustdoctest".to_string());
|
||||
testing::test_main(&test_args, collector.tests,
|
||||
testing::Options::new().display_output(display_warnings));
|
||||
|
|
|
|||
|
|
@ -687,10 +687,12 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
|
|||
// the collapse-docs pass won't combine sugared/raw doc attributes, or included files with
|
||||
// anything else, this will combine them for us
|
||||
if let Some(doc) = attrs.collapsed_doc_value() {
|
||||
markdown::find_testable_code(&doc,
|
||||
self.collector,
|
||||
attrs.span.unwrap_or(DUMMY_SP),
|
||||
self.sess.diagnostic());
|
||||
self.collector.set_position(attrs.span.unwrap_or(DUMMY_SP));
|
||||
let res = markdown::find_testable_code(&doc, self.collector);
|
||||
if let Err(err) = res {
|
||||
self.sess.diagnostic().span_warn(attrs.span.unwrap_or(DUMMY_SP),
|
||||
&err.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
nested(self);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue