]> git.lizzy.rs Git - rust.git/commitdiff
Provide test configuration through struct
authorMark Rousskov <mark.simulacrum@gmail.com>
Sat, 21 Jul 2018 22:54:30 +0000 (16:54 -0600)
committerMark Rousskov <mark.simulacrum@gmail.com>
Tue, 31 Jul 2018 17:37:21 +0000 (11:37 -0600)
This is far more sound than passing many different arguments of the same
type.

src/librustdoc/html/markdown.rs
src/librustdoc/test.rs

index 0774ce34718fba7e4f78da7fc5da6bad051f98f9..c73e6d4b3554f8c02b157a4e65254cf3f1d0584e 100644 (file)
@@ -513,12 +513,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
                     let text = lines.collect::<Vec<Cow<str>>>().join("\n");
                     nb_lines += doc[prev_offset..offset].lines().count();
                     let line = tests.get_line() + (nb_lines - 1);
-                    let filename = tests.get_filename();
-                    tests.add_test(text.to_owned(),
-                                   block_info.should_panic, block_info.no_run,
-                                   block_info.ignore, block_info.test_harness,
-                                   block_info.compile_fail, block_info.error_codes,
-                                   line, filename, block_info.allow_fail);
+                    tests.add_test(text, block_info, line);
                     prev_offset = offset;
                 } else {
                     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
 }
 
 #[derive(Eq, PartialEq, Clone, Debug)]
-struct LangString {
+pub struct LangString {
     original: String,
-    should_panic: bool,
-    no_run: bool,
-    ignore: bool,
-    rust: bool,
-    test_harness: bool,
-    compile_fail: bool,
-    error_codes: Vec<String>,
-    allow_fail: bool,
+    pub should_panic: bool,
+    pub no_run: bool,
+    pub ignore: bool,
+    pub rust: bool,
+    pub test_harness: bool,
+    pub compile_fail: bool,
+    pub error_codes: Vec<String>,
+    pub allow_fail: bool,
 }
 
 impl LangString {
index a6667e177285890cb8ad1c317278031525cf0897..2885ce615d246d7357f542ef205de8a09be6e3d4 100644 (file)
@@ -42,7 +42,7 @@
 use errors::emitter::ColorConfig;
 
 use clean::Attributes;
-use html::markdown;
+use html::markdown::{self, LangString};
 
 #[derive(Clone, Default)]
 pub struct TestOptions {
@@ -533,10 +533,8 @@ fn generate_name(&self, line: usize, filename: &FileName) -> String {
         format!("{} - {} (line {})", filename, self.names.join("::"), line)
     }
 
-    pub fn add_test(&mut self, test: String,
-                    should_panic: bool, no_run: bool, should_ignore: bool,
-                    as_test_harness: bool, compile_fail: bool, error_codes: Vec<String>,
-                    line: usize, filename: FileName, allow_fail: bool) {
+    pub fn add_test(&mut self, test: String, config: LangString, line: usize) {
+        let filename = self.get_filename();
         let name = self.generate_name(line, &filename);
         let cfgs = self.cfgs.clone();
         let libs = self.libs.clone();
@@ -551,10 +549,10 @@ pub fn add_test(&mut self, test: String,
         self.tests.push(testing::TestDescAndFn {
             desc: testing::TestDesc {
                 name: testing::DynTestName(name.clone()),
-                ignore: should_ignore,
+                ignore: config.ignore,
                 // compiler failures are test failures
                 should_panic: testing::ShouldPanic::No,
-                allow_fail,
+                allow_fail: config.allow_fail,
             },
             testfn: testing::DynTestFn(box move || {
                 let panic = io::set_panic(None);
@@ -572,11 +570,11 @@ pub fn add_test(&mut self, test: String,
                                  libs,
                                  cg,
                                  externs,
-                                 should_panic,
-                                 no_run,
-                                 as_test_harness,
-                                 compile_fail,
-                                 error_codes,
+                                 config.should_panic,
+                                 config.no_run,
+                                 config.test_harness,
+                                 config.compile_fail,
+                                 config.error_codes,
                                  &opts,
                                  maybe_sysroot,
                                  linker,
@@ -604,7 +602,7 @@ pub fn set_position(&mut self, position: Span) {
         self.position = position;
     }
 
-    pub fn get_filename(&self) -> FileName {
+    fn get_filename(&self) -> FileName {
         if let Some(ref codemap) = self.codemap {
             let filename = codemap.span_to_filename(self.position);
             if let FileName::Real(ref filename) = filename {