Skip to content

Commit 3f76408

Browse files
committed
added feature gate enable-per-target-ignores
updated and augmented tests in html/markdown.rs
1 parent 98bd8fd commit 3f76408

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

src/librustdoc/config.rs

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ pub struct Options {
8181
pub runtool: Option<String>,
8282
/// Arguments to pass to the runtool
8383
pub runtool_args: Vec<String>,
84+
/// Whether to allow ignoring doctests on a per-target basis
85+
/// For example, using ignore-foo to ignore running the doctest on any target that
86+
/// contains "foo" as a substring
87+
pub enable_per_target_ignores: bool,
8488

8589
// Options that affect the documentation process
8690

@@ -146,6 +150,7 @@ impl fmt::Debug for Options {
146150
.field("render_options", &self.render_options)
147151
.field("runtool", &self.runtool)
148152
.field("runtool_args", &self.runtool_args)
153+
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
149154
.finish()
150155
}
151156
}
@@ -474,6 +479,7 @@ impl Options {
474479
let extern_strs = matches.opt_strs("extern");
475480
let runtool = matches.opt_str("runtool");
476481
let runtool_args = matches.opt_strs("runtool-arg");
482+
let enable_per_target_ignores = matches.opt_present("enable-per-target-ignores");
477483

478484
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
479485

@@ -506,6 +512,7 @@ impl Options {
506512
persist_doctests,
507513
runtool,
508514
runtool_args,
515+
enable_per_target_ignores,
509516
render_options: RenderOptions {
510517
output,
511518
external_html,

src/librustdoc/html/markdown.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
199199
let ignore;
200200
let edition;
201201
if let Some(Event::Start(Tag::CodeBlock(lang))) = event {
202-
let parse_result = LangString::parse(&lang, self.check_error_codes);
202+
let parse_result = LangString::parse(&lang, self.check_error_codes, false);
203203
if !parse_result.rust {
204204
return Some(Event::Start(Tag::CodeBlock(lang)));
205205
}
@@ -551,7 +551,8 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for Footnotes<'a, I> {
551551
}
552552
}
553553

554-
pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes: ErrorCodes) {
554+
pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes: ErrorCodes,
555+
enable_per_target_ignores: bool) {
555556
let mut parser = Parser::new(doc);
556557
let mut prev_offset = 0;
557558
let mut nb_lines = 0;
@@ -564,7 +565,7 @@ pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes
564565
let block_info = if s.is_empty() {
565566
LangString::all_false()
566567
} else {
567-
LangString::parse(&*s, error_codes)
568+
LangString::parse(&*s, error_codes, enable_per_target_ignores)
568569
};
569570
if !block_info.rust {
570571
continue;
@@ -639,7 +640,11 @@ impl LangString {
639640
}
640641
}
641642

642-
fn parse(string: &str, allow_error_code_check: ErrorCodes) -> LangString {
643+
fn parse(
644+
string: &str,
645+
allow_error_code_check: ErrorCodes,
646+
enable_per_target_ignores: bool
647+
) -> LangString {
643648
let allow_error_code_check = allow_error_code_check.as_bool();
644649
let mut seen_rust_tags = false;
645650
let mut seen_other_tags = false;
@@ -660,7 +665,7 @@ impl LangString {
660665
}
661666
"no_run" => { data.no_run = true; seen_rust_tags = !seen_other_tags; }
662667
"ignore" => { data.ignore = Ignore::All; seen_rust_tags = !seen_other_tags; }
663-
x if x.starts_with("ignore-") => {
668+
x if enable_per_target_ignores && x.starts_with("ignore-") => {
664669
ignores.push(x.trim_start_matches("ignore-").to_owned());
665670
seen_rust_tags = !seen_other_tags;
666671
}
@@ -941,7 +946,7 @@ crate fn rust_code_blocks(md: &str) -> Vec<RustCodeBlock> {
941946
let lang_string = if syntax.is_empty() {
942947
LangString::all_false()
943948
} else {
944-
LangString::parse(&*syntax, ErrorCodes::Yes)
949+
LangString::parse(&*syntax, ErrorCodes::Yes, false)
945950
};
946951

947952
if lang_string.rust {

src/librustdoc/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ fn opts() -> Vec<RustcOptGroup> {
355355
"show-coverage",
356356
"calculate percentage of public items with documentation")
357357
}),
358+
unstable("enable-per-target-ignores", |o| {
359+
o.optflag("",
360+
"enable-per-target-ignores",
361+
"parse ignore-foo for ignoring doctests on a per-target basis")
362+
}),
358363
unstable("runtool", |o| {
359364
o.optopt("",
360365
"runtool",

src/librustdoc/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn test(mut options: Options, diag: &errors::Handler) -> i32 {
147147
collector.set_position(DUMMY_SP);
148148
let codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build());
149149

150-
find_testable_code(&input_str, &mut collector, codes);
150+
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores);
151151

152152
options.test_args.insert(0, "rustdoctest".to_string());
153153
testing::test_main(&options.test_args, collector.tests,

src/librustdoc/passes/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ pub fn look_for_tests<'tcx>(
336336
found_tests: 0,
337337
};
338338

339-
find_testable_code(&dox, &mut tests, ErrorCodes::No);
339+
find_testable_code(&dox, &mut tests, ErrorCodes::No, false);
340340

341341
if check_missing_code == true && tests.found_tests == 0 {
342342
let sp = span_of_attrs(&item.attrs).substitute_dummy(item.source.span());

src/librustdoc/test.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn run_test(
325325
cmd = Command::new(tool);
326326
cmd.arg(output_file);
327327
cmd.args(runtool_args);
328-
}else{
328+
} else {
329329
cmd = Command::new(output_file);
330330
}
331331

@@ -857,7 +857,10 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
857857
// anything else, this will combine them for us.
858858
if let Some(doc) = attrs.collapsed_doc_value() {
859859
self.collector.set_position(attrs.span.unwrap_or(DUMMY_SP));
860-
markdown::find_testable_code(&doc, self.collector, self.codes);
860+
markdown::find_testable_code(&doc,
861+
self.collector,
862+
self.codes,
863+
self.collector.enable_per_target_ignores);
861864
}
862865

863866
nested(self);

0 commit comments

Comments
 (0)