added feature gate enable-per-target-ignores
updated and augmented tests in html/markdown.rs
This commit is contained in:
parent
98bd8fd88c
commit
3f76408841
6 changed files with 30 additions and 10 deletions
|
|
@ -81,6 +81,10 @@ pub struct Options {
|
|||
pub runtool: Option<String>,
|
||||
/// Arguments to pass to the runtool
|
||||
pub runtool_args: Vec<String>,
|
||||
/// Whether to allow ignoring doctests on a per-target basis
|
||||
/// For example, using ignore-foo to ignore running the doctest on any target that
|
||||
/// contains "foo" as a substring
|
||||
pub enable_per_target_ignores: bool,
|
||||
|
||||
// Options that affect the documentation process
|
||||
|
||||
|
|
@ -146,6 +150,7 @@ impl fmt::Debug for Options {
|
|||
.field("render_options", &self.render_options)
|
||||
.field("runtool", &self.runtool)
|
||||
.field("runtool_args", &self.runtool_args)
|
||||
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
@ -474,6 +479,7 @@ impl Options {
|
|||
let extern_strs = matches.opt_strs("extern");
|
||||
let runtool = matches.opt_str("runtool");
|
||||
let runtool_args = matches.opt_strs("runtool-arg");
|
||||
let enable_per_target_ignores = matches.opt_present("enable-per-target-ignores");
|
||||
|
||||
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
|
||||
|
||||
|
|
@ -506,6 +512,7 @@ impl Options {
|
|||
persist_doctests,
|
||||
runtool,
|
||||
runtool_args,
|
||||
enable_per_target_ignores,
|
||||
render_options: RenderOptions {
|
||||
output,
|
||||
external_html,
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
|
|||
let ignore;
|
||||
let edition;
|
||||
if let Some(Event::Start(Tag::CodeBlock(lang))) = event {
|
||||
let parse_result = LangString::parse(&lang, self.check_error_codes);
|
||||
let parse_result = LangString::parse(&lang, self.check_error_codes, false);
|
||||
if !parse_result.rust {
|
||||
return Some(Event::Start(Tag::CodeBlock(lang)));
|
||||
}
|
||||
|
|
@ -551,7 +551,8 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for Footnotes<'a, I> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes: ErrorCodes) {
|
||||
pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes: ErrorCodes,
|
||||
enable_per_target_ignores: bool) {
|
||||
let mut parser = Parser::new(doc);
|
||||
let mut prev_offset = 0;
|
||||
let mut nb_lines = 0;
|
||||
|
|
@ -564,7 +565,7 @@ pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes
|
|||
let block_info = if s.is_empty() {
|
||||
LangString::all_false()
|
||||
} else {
|
||||
LangString::parse(&*s, error_codes)
|
||||
LangString::parse(&*s, error_codes, enable_per_target_ignores)
|
||||
};
|
||||
if !block_info.rust {
|
||||
continue;
|
||||
|
|
@ -639,7 +640,11 @@ impl LangString {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse(string: &str, allow_error_code_check: ErrorCodes) -> LangString {
|
||||
fn parse(
|
||||
string: &str,
|
||||
allow_error_code_check: ErrorCodes,
|
||||
enable_per_target_ignores: bool
|
||||
) -> LangString {
|
||||
let allow_error_code_check = allow_error_code_check.as_bool();
|
||||
let mut seen_rust_tags = false;
|
||||
let mut seen_other_tags = false;
|
||||
|
|
@ -660,7 +665,7 @@ impl LangString {
|
|||
}
|
||||
"no_run" => { data.no_run = true; seen_rust_tags = !seen_other_tags; }
|
||||
"ignore" => { data.ignore = Ignore::All; seen_rust_tags = !seen_other_tags; }
|
||||
x if x.starts_with("ignore-") => {
|
||||
x if enable_per_target_ignores && x.starts_with("ignore-") => {
|
||||
ignores.push(x.trim_start_matches("ignore-").to_owned());
|
||||
seen_rust_tags = !seen_other_tags;
|
||||
}
|
||||
|
|
@ -941,7 +946,7 @@ crate fn rust_code_blocks(md: &str) -> Vec<RustCodeBlock> {
|
|||
let lang_string = if syntax.is_empty() {
|
||||
LangString::all_false()
|
||||
} else {
|
||||
LangString::parse(&*syntax, ErrorCodes::Yes)
|
||||
LangString::parse(&*syntax, ErrorCodes::Yes, false)
|
||||
};
|
||||
|
||||
if lang_string.rust {
|
||||
|
|
|
|||
|
|
@ -355,6 +355,11 @@ fn opts() -> Vec<RustcOptGroup> {
|
|||
"show-coverage",
|
||||
"calculate percentage of public items with documentation")
|
||||
}),
|
||||
unstable("enable-per-target-ignores", |o| {
|
||||
o.optflag("",
|
||||
"enable-per-target-ignores",
|
||||
"parse ignore-foo for ignoring doctests on a per-target basis")
|
||||
}),
|
||||
unstable("runtool", |o| {
|
||||
o.optopt("",
|
||||
"runtool",
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ pub fn test(mut options: Options, diag: &errors::Handler) -> i32 {
|
|||
collector.set_position(DUMMY_SP);
|
||||
let codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build());
|
||||
|
||||
find_testable_code(&input_str, &mut collector, codes);
|
||||
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores);
|
||||
|
||||
options.test_args.insert(0, "rustdoctest".to_string());
|
||||
testing::test_main(&options.test_args, collector.tests,
|
||||
|
|
|
|||
|
|
@ -336,7 +336,7 @@ pub fn look_for_tests<'tcx>(
|
|||
found_tests: 0,
|
||||
};
|
||||
|
||||
find_testable_code(&dox, &mut tests, ErrorCodes::No);
|
||||
find_testable_code(&dox, &mut tests, ErrorCodes::No, false);
|
||||
|
||||
if check_missing_code == true && tests.found_tests == 0 {
|
||||
let sp = span_of_attrs(&item.attrs).substitute_dummy(item.source.span());
|
||||
|
|
|
|||
|
|
@ -325,7 +325,7 @@ fn run_test(
|
|||
cmd = Command::new(tool);
|
||||
cmd.arg(output_file);
|
||||
cmd.args(runtool_args);
|
||||
}else{
|
||||
} else {
|
||||
cmd = Command::new(output_file);
|
||||
}
|
||||
|
||||
|
|
@ -857,7 +857,10 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
|
|||
// anything else, this will combine them for us.
|
||||
if let Some(doc) = attrs.collapsed_doc_value() {
|
||||
self.collector.set_position(attrs.span.unwrap_or(DUMMY_SP));
|
||||
markdown::find_testable_code(&doc, self.collector, self.codes);
|
||||
markdown::find_testable_code(&doc,
|
||||
self.collector,
|
||||
self.codes,
|
||||
self.collector.enable_per_target_ignores);
|
||||
}
|
||||
|
||||
nested(self);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue