diff options
| author | ggomez <guillaume1.gomez@gmail.com> | 2016-09-07 16:43:18 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-02-03 11:08:19 +0100 |
| commit | 230234f3a8eb38dcfa26d086c9c6e61be48f46ac (patch) | |
| tree | 174e8a2e7eb4b7aaa26ab53ee4b0d7c6746f236d | |
| parent | 57ecd7aa4bc8dfd07fb0888479b25e53daf46140 (diff) | |
| download | rust-230234f3a8eb38dcfa26d086c9c6e61be48f46ac.tar.gz rust-230234f3a8eb38dcfa26d086c9c6e61be48f46ac.zip | |
Add information in case of markdown block code test failure
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 7 | ||||
| -rw-r--r-- | src/librustdoc/test.rs | 35 |
2 files changed, 27 insertions, 15 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 442a2f40742..3df476907d9 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -448,7 +448,8 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) { 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); + block_info.compile_fail, block_info.error_codes, + block_info.original); } } @@ -488,6 +489,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) { #[derive(Eq, PartialEq, Clone, Debug)] struct LangString { + original: String, should_panic: bool, no_run: bool, ignore: bool, @@ -500,6 +502,7 @@ struct LangString { impl LangString { fn all_false() -> LangString { LangString { + original: String::new(), should_panic: false, no_run: false, ignore: false, @@ -521,6 +524,7 @@ impl LangString { allow_error_code_check = true; } + data.original = string.to_owned(); let tokens = string.split(|c: char| !(c == '_' || c == '-' || c.is_alphanumeric()) ); @@ -647,6 +651,7 @@ mod tests { test_harness: test_harness, compile_fail: compile_fail, error_codes: error_codes, + original: s.to_owned(), }) } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index ab0ac02fd88..00327007dd0 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -161,13 +161,15 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs, should_panic: bool, no_run: bool, as_test_harness: bool, compile_fail: bool, mut error_codes: Vec<String>, opts: &TestOptions, - maybe_sysroot: Option<PathBuf>) { + maybe_sysroot: Option<PathBuf>, + original: &str) { // the test harness wants its own `main` & top level functions, so // never wrap the test in `fn main() { ... }` - let test = maketest(test, Some(cratename), as_test_harness, opts); + let new_test = maketest(test, Some(cratename), as_test_harness, opts); + let test = format!("```{}\n{}\n```\n", original, test); let input = config::Input::Str { name: driver::anon_src(), - input: test.to_owned(), + input: new_test.to_owned(), }; let outputs = OutputTypes::new(&[(OutputType::Exe, None)]); @@ -249,20 +251,22 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths, if count > 0 && !compile_fail { sess.fatal("aborting due to previous error(s)") } else if count == 0 && compile_fail { - panic!("test compiled while it wasn't supposed to") + panic!("test compiled while it wasn't supposed to:\n\n{}\n", test) } if count > 0 && error_codes.len() > 0 { let out = String::from_utf8(data.lock().unwrap().to_vec()).unwrap(); error_codes.retain(|err| !out.contains(err)); } } - Ok(()) if compile_fail => panic!("test compiled while it wasn't supposed to"), + Ok(()) if compile_fail => { + panic!("test compiled while it wasn't supposed to:\n\n{}\n", test) + } _ => {} } } Err(_) => { if !compile_fail { - panic!("couldn't compile the test"); + panic!("couldn't compile the test:\n\n{}\n", test); } if error_codes.len() > 0 { let out = String::from_utf8(data.lock().unwrap().to_vec()).unwrap(); @@ -272,7 +276,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths, } if error_codes.len() > 0 { - panic!("Some expected error codes were not found: {:?}", error_codes); + panic!("Some expected error codes were not found: {:?}\n\n{}\n", error_codes, test); } if no_run { return } @@ -294,17 +298,18 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths, cmd.env(var, &newpath); match cmd.output() { - Err(e) => panic!("couldn't run the test: {}{}", e, + Err(e) => panic!("couldn't run the test: {}{}\n\n{}\n", e, if e.kind() == io::ErrorKind::PermissionDenied { " - maybe your tempdir is mounted with noexec?" - } else { "" }), + } else { "" }, test), Ok(out) => { if should_panic && out.status.success() { - panic!("test executable succeeded when it should have failed"); + panic!("test executable succeeded when it should have failed\n\n{}\n", test); } else if !should_panic && !out.status.success() { - panic!("test executable failed:\n{}\n{}", + panic!("test executable failed:\n{}\n{}\n\n{}\n", str::from_utf8(&out.stdout).unwrap_or(""), - str::from_utf8(&out.stderr).unwrap_or("")); + str::from_utf8(&out.stderr).unwrap_or(""), + test); } } } @@ -406,7 +411,8 @@ impl Collector { 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>) { + as_test_harness: bool, compile_fail: bool, error_codes: Vec<String>, + original: String) { let name = if self.use_headers { let s = self.current_header.as_ref().map(|s| &**s).unwrap_or(""); format!("{}_{}", s, self.cnt) @@ -446,7 +452,8 @@ impl Collector { compile_fail, error_codes, &opts, - maybe_sysroot) + maybe_sysroot, + &original) }) } { Ok(()) => (), |
