From 63568dc3ad9dc478eac800fb5a5aba3d749f880a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Wed, 17 Feb 2021 21:31:59 +0100 Subject: make the assert_errs output way clearer --- src/lib.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index ee176e5..69508cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -730,9 +730,14 @@ mod tests { #[macro_export] macro_rules! assert_errs { ($result:expr, [ $( $kind:pat ),* ]) => { - eprintln!("{} => {:?}", stringify!($result), $result); - assert!(matches!( - $result.unwrap_err().as_slice(), + let errs = if let Err(errs) = $result { + errs + } else { + eprintln!(" PROGRAM SUCCEEDED, WHEN IT SHOULD FAIL!"); + unreachable!(); + }; + if !matches!( + errs.as_slice(), &[$($crate::error::Error { kind: $kind, file: _, @@ -740,7 +745,19 @@ mod tests { message: _, }, )*] - )) + ) { + eprintln!("UNEXPECTED ERRORS"); + eprint!(" GOT: ["); + for err in errs { + eprint!(" ErrorKind::{:?} ", err.kind); + } + eprint!("]\n WANT: ["); + $( + eprint!(" {} ", stringify!($kind)); + )* + eprintln!("]"); + assert!(false); + } }; } @@ -823,6 +840,11 @@ mod tests { assert_errs!(run_string("a :: 2\nq :: fn { a = 2 }\n", true, Vec::new()), [ErrorKind::SyntaxError(_, _)]); } + #[test] + fn assign_to_constant_upvalue2() { + assert_errs!(run_string("a :: 2\nq :: fn { a = 2 }\n", true, Vec::new()), [ErrorKind::InvalidProgram]); + } + macro_rules! test_multiple { ($mod:ident, $( $fn:ident : $prog:literal ),+ $( , )? ) => { mod $mod { -- cgit v1.2.1 From 326b39b027a415e767fcdb9d40585bb68544c7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Wed, 17 Feb 2021 21:35:14 +0100 Subject: write testfails on stderr --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 69508cf..153b2a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -797,8 +797,8 @@ mod tests { for e in errs.iter() { println!("{}", e); } - println!(" {} - FAILED\n", stringify!($fn)); - panic!(); + eprintln!(" {} - FAILED\n", stringify!($fn)); + unreachable!(); } } }); -- cgit v1.2.1 From 946828d4cd281c073663f3c5b078c1cf5ed1ddde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Wed, 17 Feb 2021 21:35:43 +0100 Subject: remove test-testcase --- src/lib.rs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 153b2a7..3fa4cb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -840,11 +840,6 @@ mod tests { assert_errs!(run_string("a :: 2\nq :: fn { a = 2 }\n", true, Vec::new()), [ErrorKind::SyntaxError(_, _)]); } - #[test] - fn assign_to_constant_upvalue2() { - assert_errs!(run_string("a :: 2\nq :: fn { a = 2 }\n", true, Vec::new()), [ErrorKind::InvalidProgram]); - } - macro_rules! test_multiple { ($mod:ident, $( $fn:ident : $prog:literal ),+ $( , )? ) => { mod $mod { -- cgit v1.2.1 From 33e87da47b0d7dedc0b88d7e732f398fc602deca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Thu, 18 Feb 2021 20:03:39 +0100 Subject: stop scrreaming on errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gustav Sörnäs --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 3fa4cb6..d387316 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -733,7 +733,7 @@ mod tests { let errs = if let Err(errs) = $result { errs } else { - eprintln!(" PROGRAM SUCCEEDED, WHEN IT SHOULD FAIL!"); + eprintln!(" Program succeeded when it should've failed"); unreachable!(); }; if !matches!( @@ -746,12 +746,12 @@ mod tests { }, )*] ) { - eprintln!("UNEXPECTED ERRORS"); - eprint!(" GOT: ["); + eprintln!("Unexpected errors"); + eprint!(" Got: ["); for err in errs { eprint!(" ErrorKind::{:?} ", err.kind); } - eprint!("]\n WANT: ["); + eprint!("]\n Want: ["); $( eprint!(" {} ", stringify!($kind)); )* @@ -797,7 +797,7 @@ mod tests { for e in errs.iter() { println!("{}", e); } - eprintln!(" {} - FAILED\n", stringify!($fn)); + eprintln!(" {} - failed\n", stringify!($fn)); unreachable!(); } } -- cgit v1.2.1