Skip to content

Commit de5cebd

Browse files
Provide test configuration through struct
This is far more sound than passing many different arguments of the same type.
1 parent ad40e45 commit de5cebd

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
513513
let text = lines.collect::<Vec<Cow<str>>>().join("\n");
514514
nb_lines += doc[prev_offset..offset].lines().count();
515515
let line = tests.get_line() + (nb_lines - 1);
516-
let filename = tests.get_filename();
517-
tests.add_test(text.to_owned(),
518-
block_info.should_panic, block_info.no_run,
519-
block_info.ignore, block_info.test_harness,
520-
block_info.compile_fail, block_info.error_codes,
521-
line, filename, block_info.allow_fail);
516+
tests.add_test(text, block_info, line);
522517
prev_offset = offset;
523518
} else {
524519
handler.span_warn(position, "invalid start of a new code block");
@@ -543,16 +538,16 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
543538
}
544539

545540
#[derive(Eq, PartialEq, Clone, Debug)]
546-
struct LangString {
541+
pub struct LangString {
547542
original: String,
548-
should_panic: bool,
549-
no_run: bool,
550-
ignore: bool,
551-
rust: bool,
552-
test_harness: bool,
553-
compile_fail: bool,
554-
error_codes: Vec<String>,
555-
allow_fail: bool,
543+
pub should_panic: bool,
544+
pub no_run: bool,
545+
pub ignore: bool,
546+
pub rust: bool,
547+
pub test_harness: bool,
548+
pub compile_fail: bool,
549+
pub error_codes: Vec<String>,
550+
pub allow_fail: bool,
556551
}
557552

558553
impl LangString {

src/librustdoc/test.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use errors;
4242
use errors::emitter::ColorConfig;
4343

4444
use clean::Attributes;
45-
use html::markdown;
45+
use html::markdown::{self, LangString};
4646

4747
#[derive(Clone, Default)]
4848
pub struct TestOptions {
@@ -533,10 +533,8 @@ impl Collector {
533533
format!("{} - {} (line {})", filename, self.names.join("::"), line)
534534
}
535535

536-
pub fn add_test(&mut self, test: String,
537-
should_panic: bool, no_run: bool, should_ignore: bool,
538-
as_test_harness: bool, compile_fail: bool, error_codes: Vec<String>,
539-
line: usize, filename: FileName, allow_fail: bool) {
536+
pub fn add_test(&mut self, test: String, config: LangString, line: usize) {
537+
let filename = self.get_filename();
540538
let name = self.generate_name(line, &filename);
541539
let cfgs = self.cfgs.clone();
542540
let libs = self.libs.clone();
@@ -551,10 +549,10 @@ impl Collector {
551549
self.tests.push(testing::TestDescAndFn {
552550
desc: testing::TestDesc {
553551
name: testing::DynTestName(name.clone()),
554-
ignore: should_ignore,
552+
ignore: config.ignore,
555553
// compiler failures are test failures
556554
should_panic: testing::ShouldPanic::No,
557-
allow_fail,
555+
allow_fail: config.allow_fail,
558556
},
559557
testfn: testing::DynTestFn(box move || {
560558
let panic = io::set_panic(None);
@@ -572,11 +570,11 @@ impl Collector {
572570
libs,
573571
cg,
574572
externs,
575-
should_panic,
576-
no_run,
577-
as_test_harness,
578-
compile_fail,
579-
error_codes,
573+
config.should_panic,
574+
config.no_run,
575+
config.test_harness,
576+
config.compile_fail,
577+
config.error_codes,
580578
&opts,
581579
maybe_sysroot,
582580
linker,
@@ -604,7 +602,7 @@ impl Collector {
604602
self.position = position;
605603
}
606604

607-
pub fn get_filename(&self) -> FileName {
605+
fn get_filename(&self) -> FileName {
608606
if let Some(ref codemap) = self.codemap {
609607
let filename = codemap.span_to_filename(self.position);
610608
if let FileName::Real(ref filename) = filename {

0 commit comments

Comments
 (0)