Skip to content

Commit 81df4a6

Browse files
committed
added feature gate enable-per-target-ignores
updated and augmented tests in html/markdown.rs
1 parent aa8f0d9 commit 81df4a6

File tree

6 files changed

+39
-14
lines changed

6 files changed

+39
-14
lines changed

src/librustdoc/config.rs

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ pub struct Options {
7575
pub runtool: Option<String>,
7676
/// Arguments to pass to the runtool
7777
pub runtool_args: Vec<String>,
78+
/// Whether to allow ignoring doctests on a per-target basis
79+
/// For example, using ignore-foo to ignore running the doctest on any target that
80+
/// contains "foo" as a substring
81+
pub enable_per_target_ignores: bool,
7882

7983
// Options that affect the documentation process
8084

@@ -140,6 +144,7 @@ impl fmt::Debug for Options {
140144
.field("render_options", &self.render_options)
141145
.field("runtool", &self.runtool)
142146
.field("runtool_args", &self.runtool_args)
147+
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
143148
.finish()
144149
}
145150
}
@@ -484,6 +489,7 @@ impl Options {
484489
let generate_redirect_pages = matches.opt_present("generate-redirect-pages");
485490
let runtool = matches.opt_str("runtool");
486491
let runtool_args = matches.opt_strs("runtool-arg");
492+
let enable_per_target_ignores = matches.opt_present("enable-per-target-ignores");
487493

488494
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
489495

@@ -513,6 +519,7 @@ impl Options {
513519
persist_doctests,
514520
runtool,
515521
runtool_args,
522+
enable_per_target_ignores,
516523
render_options: RenderOptions {
517524
output,
518525
external_html,

src/librustdoc/html/markdown.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> {
184184
let ignore;
185185
let edition;
186186
if let Some(Event::Start(Tag::CodeBlock(lang))) = event {
187-
let parse_result = LangString::parse(&lang, self.check_error_codes);
187+
let parse_result = LangString::parse(&lang, self.check_error_codes, false);
188188
if !parse_result.rust {
189189
return Some(Event::Start(Tag::CodeBlock(lang)));
190190
}
@@ -536,7 +536,8 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for Footnotes<'a, I> {
536536
}
537537
}
538538

539-
pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes: ErrorCodes) {
539+
pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes: ErrorCodes,
540+
enable_per_target_ignores: bool) {
540541
let mut parser = Parser::new(doc);
541542
let mut prev_offset = 0;
542543
let mut nb_lines = 0;
@@ -549,7 +550,7 @@ pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes
549550
let block_info = if s.is_empty() {
550551
LangString::all_false()
551552
} else {
552-
LangString::parse(&*s, error_codes)
553+
LangString::parse(&*s, error_codes, enable_per_target_ignores)
553554
};
554555
if !block_info.rust {
555556
continue;
@@ -624,7 +625,11 @@ impl LangString {
624625
}
625626
}
626627

627-
fn parse(string: &str, allow_error_code_check: ErrorCodes) -> LangString {
628+
fn parse(
629+
string: &str,
630+
allow_error_code_check: ErrorCodes,
631+
enable_per_target_ignores: bool
632+
) -> LangString {
628633
let allow_error_code_check = allow_error_code_check.as_bool();
629634
let mut seen_rust_tags = false;
630635
let mut seen_other_tags = false;
@@ -645,7 +650,7 @@ impl LangString {
645650
}
646651
"no_run" => { data.no_run = true; seen_rust_tags = !seen_other_tags; }
647652
"ignore" => { data.ignore = Ignore::All; seen_rust_tags = !seen_other_tags; }
648-
x if x.starts_with("ignore-") => {
653+
x if enable_per_target_ignores && x.starts_with("ignore-") => {
649654
ignores.push(x.trim_start_matches("ignore-").to_owned());
650655
seen_rust_tags = !seen_other_tags;
651656
}
@@ -949,7 +954,7 @@ crate fn rust_code_blocks(md: &str) -> Vec<RustCodeBlock> {
949954
let lang_string = if syntax.is_empty() {
950955
LangString::all_false()
951956
} else {
952-
LangString::parse(&*syntax, ErrorCodes::Yes)
957+
LangString::parse(&*syntax, ErrorCodes::Yes, false)
953958
};
954959

955960
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

+5-4
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,14 @@ pub fn test(mut options: Options, diag: &errors::Handler) -> i32 {
145145
let mut collector = Collector::new(options.input.display().to_string(), options.cfgs,
146146
options.libs, options.codegen_options, options.externs,
147147
true, opts, options.maybe_sysroot, None,
148-
Some(options.input),
149-
options.linker, options.edition, options.persist_doctests,
150-
options.runtool, options.runtool_args, options.target);
148+
Some(options.input), options.linker, options.edition,
149+
options.persist_doctests, options.runtool,
150+
options.runtool_args, options.target,
151+
options.enable_per_target_ignores);
151152
collector.set_position(DUMMY_SP);
152153
let codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build());
153154

154-
find_testable_code(&input_str, &mut collector, codes);
155+
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores);
155156

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

src/librustdoc/passes/mod.rs

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

338-
find_testable_code(&dox, &mut tests, ErrorCodes::No);
338+
find_testable_code(&dox, &mut tests, ErrorCodes::No, false);
339339

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

src/librustdoc/test.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub fn run(options: Options) -> i32 {
100100
options.runtool,
101101
options.runtool_args,
102102
options.target.clone(),
103+
options.enable_per_target_ignores,
103104
);
104105

105106
let mut global_ctxt = compiler.global_ctxt()?.take();
@@ -376,7 +377,7 @@ fn run_test(
376377
cmd = Command::new(tool);
377378
cmd.arg(output_file);
378379
cmd.args(runtool_args);
379-
}else{
380+
} else {
380381
cmd = Command::new(output_file);
381382
}
382383

@@ -686,6 +687,7 @@ pub struct Collector {
686687
runtool: Option<String>,
687688
runtool_args: Vec<String>,
688689
target: Option<TargetTriple>,
690+
pub enable_per_target_ignores: bool,
689691
}
690692

691693
impl Collector {
@@ -694,7 +696,8 @@ impl Collector {
694696
maybe_sysroot: Option<PathBuf>, source_map: Option<Lrc<SourceMap>>,
695697
filename: Option<PathBuf>, linker: Option<PathBuf>, edition: Edition,
696698
persist_doctests: Option<PathBuf>, runtool: Option<String>,
697-
runtool_args: Vec<String>, target: Option<TargetTriple>) -> Collector {
699+
runtool_args: Vec<String>, target: Option<TargetTriple>,
700+
enable_per_target_ignores: bool) -> Collector {
698701
Collector {
699702
tests: Vec::new(),
700703
names: Vec::new(),
@@ -715,6 +718,7 @@ impl Collector {
715718
runtool,
716719
runtool_args,
717720
target,
721+
enable_per_target_ignores,
718722
}
719723
}
720724

@@ -945,7 +949,10 @@ impl<'a, 'hir> HirCollector<'a, 'hir> {
945949
// anything else, this will combine them for us.
946950
if let Some(doc) = attrs.collapsed_doc_value() {
947951
self.collector.set_position(attrs.span.unwrap_or(DUMMY_SP));
948-
markdown::find_testable_code(&doc, self.collector, self.codes);
952+
markdown::find_testable_code(&doc,
953+
self.collector,
954+
self.codes,
955+
self.collector.enable_per_target_ignores);
949956
}
950957

951958
nested(self);

0 commit comments

Comments
 (0)