diff --git a/lib/_007/Test.pm b/lib/_007/Test.pm index 90e4d6a4..9ab95dba 100644 --- a/lib/_007/Test.pm +++ b/lib/_007/Test.pm @@ -272,7 +272,7 @@ sub is-result($input, $expected, $desc = "MISSING TEST DESCRIPTION") is export { is $output.result, $expected, $desc; } -sub is-error($input, $expected-error, $desc = $expected-error.^name) is export { +sub is-error($input, $expected-error, $expected-msg, $desc = $expected-error.^name) is export { my $ast = read($input); my $output = StrOutput.new; my $runtime = _007.runtime(:$output); @@ -281,7 +281,7 @@ sub is-error($input, $expected-error, $desc = $expected-error.^name) is export { CATCH { when $expected-error { - pass $desc; + is .message, $expected-msg, $desc; } } flunk $desc; diff --git a/t/features/builtins/methods.t b/t/features/builtins/methods.t index 05ebb657..a5cf5a8d 100644 --- a/t/features/builtins/methods.t +++ b/t/features/builtins/methods.t @@ -189,7 +189,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (postfix:() (postfix:. (str "abc") (identifier "charat")) (argumentlist (int 3))))))) . - is-error $ast, X::Subscript::TooLarge, "charat() dies"; + is-error + $ast, + X::Subscript::TooLarge, + "Subscript (3) too large (array length 3)", + "charat() dies"; } { @@ -271,7 +275,11 @@ use _007::Test; (stexpr (postfix:() (postfix:. (identifier "a") (identifier "pop")) (argumentlist)))) . - is-error $ast, X::Cannot::Empty, "cannot Array.pop() an empty array"; + is-error + $ast, + X::Cannot::Empty, + "Cannot pop from an empty Val::Array", + "cannot Array.pop() an empty array"; } { @@ -304,7 +312,11 @@ use _007::Test; (stexpr (postfix:() (postfix:. (identifier "a") (identifier "shift")) (argumentlist)))) . - is-error $ast, X::Cannot::Empty, "cannot Array.shift() an empty array"; + is-error + $ast, + X::Cannot::Empty, + "Cannot pop from an empty Val::Array", + "cannot Array.shift() an empty array"; } { @@ -347,7 +359,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (postfix:() (postfix:. (identifier "r") (identifier "fullmatch")) (argumentlist (int 3))))))) . - is-error $ast, X::Regex::InvalidMatchType, "Regex.fullmatch() can only match strings"; + is-error + $ast, + X::Regex::InvalidMatchType, + "A regex can only match strings", + "Regex.fullmatch() can only match strings"; } { @@ -357,7 +373,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (postfix:() (postfix:. (identifier "r") (identifier "search")) (argumentlist (int 3))))))) . - is-error $ast, X::Regex::InvalidMatchType, "Regex.search() can only match strings"; + is-error + $ast, + X::Regex::InvalidMatchType, + "A regex can only match strings", + "Regex.search() can only match strings"; } { diff --git a/t/features/builtins/operators.t b/t/features/builtins/operators.t index 037f149b..20705f9c 100644 --- a/t/features/builtins/operators.t +++ b/t/features/builtins/operators.t @@ -53,7 +53,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (infix:% (int 5) (int 0)))))) . - is-error $ast, X::Numeric::DivideByZero, "dividing by 0 is an error"; + is-error + $ast, + X::Numeric::DivideByZero, + "Attempt to divide 5 by zero using %", + "dividing by 0 is an error"; } { @@ -74,7 +78,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (infix:%% (int 5) (int 0)))))) . - is-error $ast, X::Numeric::DivideByZero, "checking divisibility by 0 is an error"; + is-error + $ast, + X::Numeric::DivideByZero, + "Attempt to divide 5 by zero using %%", + "checking divisibility by 0 is an error"; } { @@ -410,7 +418,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (postfix:[] (identifier "ns") (prefix:- (int 2))))))) . - is-error $ast, X::Subscript::Negative, "negative array indexing is an error"; + is-error + $ast, + X::Subscript::Negative, + "Calculated index (-2) is negative, but Array allows only 0-based indexing", + "negative array indexing is an error"; } { @@ -420,7 +432,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (postfix:[] (identifier "ns") (int 19)))))) . - is-error $ast, X::Subscript::TooLarge, "indexing beyond the last element is an error"; + is-error + $ast, + X::Subscript::TooLarge, + "Subscript (19) too large (array length 2)", + "indexing beyond the last element is an error"; } { @@ -429,7 +445,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (infix:+ (int 38) (str "4")))))) . - is-error $ast, X::TypeCheck, "adding non-ints is an error"; + is-error + $ast, + X::TypeCheck, + "Type check failed in +; expected Val::Int but got Val::Str (Val::Str.new(value =>...)", + "adding non-ints is an error"; } { @@ -438,7 +458,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (infix:~ (int 38) (str "4")))))) . - is-error $ast, X::TypeCheck, "concatenating non-strs is an error"; + is-error + $ast, + X::TypeCheck, + "Type check failed in ~; expected Val::Str but got Val::Int (Val::Int.new(value =>...)", + "concatenating non-strs is an error"; } { @@ -448,7 +472,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (postfix:[] (identifier "ns") (int 0)))))) . - is-error $ast, X::TypeCheck, "indexing a non-array is an error"; + is-error + $ast, + X::TypeCheck, + "Type check failed in indexing; expected Val::Array but got Val::Str (Val::Str.new(value =>...)", + "indexing a non-array is an error"; } { @@ -593,7 +621,11 @@ use _007::Test; (stexpr (prefix:^ (str "Mr Bond")))) . - is-error $ast, X::TypeCheck, "can't upto a string (or other non-integer types)"; + is-error + $ast, + X::TypeCheck, + "Type check failed in ^; expected Val::Int but got Val::Str (Val::Str.new(value =>...)", + "can't upto a string (or other non-integer types)"; } { diff --git a/t/features/for-loop.t b/t/features/for-loop.t index 57117fbf..e6d5c15e 100644 --- a/t/features/for-loop.t +++ b/t/features/for-loop.t @@ -30,7 +30,11 @@ use _007::Test; (stexpr (postfix:() (identifier "say") (argumentlist (identifier "j")))))))) . - is-error $ast, X::ParameterMismatch, "for-loops with more parameters are not supported"; + is-error + $ast, + X::ParameterMismatch, + "For loop with 2 parameters called with 0 or 1 arguments", + "for-loops with more parameters are not supported"; } { diff --git a/t/features/objects.t b/t/features/objects.t index 22cda14c..0f634a4b 100644 --- a/t/features/objects.t +++ b/t/features/objects.t @@ -58,7 +58,11 @@ use _007::Test; (stexpr (postfix:. (identifier "o") (identifier "a")))) . - is-error $ast, X::Property::NotFound, "can't access non-existing property (dot syntax)"; + is-error + $ast, + X::Property::NotFound, + "Property 'a' not found on object of type Object", + "can't access non-existing property (dot syntax)"; } { @@ -67,7 +71,11 @@ use _007::Test; (stexpr (postfix:. (int 42) (identifier "a")))) . - is-error $ast, X::Property::NotFound, "can't access property on Val::Int (dot syntax)"; + is-error + $ast, + X::Property::NotFound, + "Property 'a' not found on object of type Int", + "can't access property on Val::Int (dot syntax)"; } { @@ -81,6 +89,7 @@ use _007::Test; is-error $ast, X::Property::Duplicate, + "The property 'foo' was declared more than once in a property list", "can't have duplicate properties (#85) (I)"; } @@ -102,7 +111,11 @@ use _007::Test; (stexpr (postfix:[] (identifier "o") (str "b")))) . - is-error $ast, X::Property::NotFound, "can't access non-existing property (brackets syntax)"; + is-error + $ast, + X::Property::NotFound, + "Property 'b' not found on object of type Object", + "can't access non-existing property (brackets syntax)"; } { diff --git a/t/features/types.t b/t/features/types.t index 6f0a7dc0..60c8f27f 100644 --- a/t/features/types.t +++ b/t/features/types.t @@ -67,7 +67,11 @@ use _007::Test; (stexpr (object (identifier "Q::Literal") (propertylist)))) . - is-error $ast, X::Uninstantiable, "abstract Q types are uninstantiable (#140)"; + is-error + $ast, + X::Uninstantiable, + " is abstract and uninstantiable", + "abstract Q types are uninstantiable (#140)"; } { diff --git a/t/features/while-loop.t b/t/features/while-loop.t index f19a1080..78a39fe3 100644 --- a/t/features/while-loop.t +++ b/t/features/while-loop.t @@ -62,7 +62,11 @@ use _007::Test; (stexpr (infix:= (identifier "u") (infix:+ (identifier "u") (prefix:- (int 1))))))))) . - is-error $ast, X::ParameterMismatch, "while loops don't accept more than one parameter"; + is-error + $ast, + X::ParameterMismatch, + "While loop with 3 parameters called with 0 or 1 arguments", + "while loops don't accept more than one parameter"; } done-testing;