From e833650af06121af66ce13210fca8cb3c5445dee Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 12 Apr 2020 14:22:52 -0400 Subject: [PATCH] refactor test macros to handle new errors --- tests/imports.rs | 2 +- tests/macros.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/imports.rs b/tests/imports.rs index 0778abc..9294019 100644 --- a/tests/imports.rs +++ b/tests/imports.rs @@ -12,7 +12,7 @@ macro_rules! test_import { write!(f, $content).unwrap(); )* let mut buf = Vec::new(); - StyleSheet::new($input) + StyleSheet::new($input.to_string()) .expect(concat!("failed to parse in ")) .print_as_css(&mut buf) .expect(concat!("failed to pretty print on ", $input)); diff --git a/tests/macros.rs b/tests/macros.rs index 55d424d..0e19883 100644 --- a/tests/macros.rs +++ b/tests/macros.rs @@ -8,7 +8,7 @@ macro_rules! test { #[allow(non_snake_case)] fn $func() { let mut buf = Vec::new(); - grass::StyleSheet::new($input) + grass::StyleSheet::new($input.to_string()) .expect(concat!("failed to parse on ", $input)) .print_as_css(&mut buf) .expect(concat!("failed to pretty print on ", $input)); @@ -24,7 +24,7 @@ macro_rules! test { #[allow(non_snake_case)] fn $func() { let mut buf = Vec::new(); - grass::StyleSheet::new($input) + grass::StyleSheet::new($input.to_string()) .expect(concat!("failed to parse on ", $input)) .print_as_css(&mut buf) .expect(concat!("failed to pretty print on ", $input)); @@ -36,6 +36,8 @@ macro_rules! test { }; } +/// Verify the error *message* +/// Span and scope information are not yet tested #[macro_export] macro_rules! error { ($( #[$attr:meta] ),*$func:ident, $input:expr, $err:expr) => { @@ -43,9 +45,9 @@ macro_rules! error { #[test] #[allow(non_snake_case)] fn $func() { - match grass::StyleSheet::new($input) { + match grass::StyleSheet::new($input.to_string()) { Ok(..) => panic!("did not fail"), - Err(e) => assert_eq!($err, e.to_string().as_str()), + Err(e) => assert_eq!($err, e.to_string().chars().take_while(|c| *c != '\n').collect::().as_str()), } } };