Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test exceptions messages #270

Merged
merged 1 commit into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/_007/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
30 changes: 25 additions & 5 deletions t/features/builtins/methods.t
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

{
Expand Down Expand Up @@ -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";
}

{
Expand Down Expand Up @@ -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";
}

{
Expand Down Expand Up @@ -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";
}

{
Expand All @@ -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";
}

{
Expand Down
48 changes: 40 additions & 8 deletions t/features/builtins/operators.t
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

{
Expand All @@ -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";
}

{
Expand Down Expand Up @@ -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";
}

{
Expand All @@ -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";
}

{
Expand All @@ -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 =>...)",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks odd and not expected, but I think I'm going to let it through for now, because the real fix would be #245.

"adding non-ints is an error";
}

{
Expand All @@ -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";
}

{
Expand All @@ -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";
}

{
Expand Down Expand Up @@ -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)";
}

{
Expand Down
6 changes: 5 additions & 1 deletion t/features/for-loop.t
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

{
Expand Down
19 changes: 16 additions & 3 deletions t/features/objects.t
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
}

{
Expand All @@ -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)";
}

{
Expand All @@ -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)";
}

Expand All @@ -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)";
}

{
Expand Down
6 changes: 5 additions & 1 deletion t/features/types.t
Original file line number Diff line number Diff line change
Expand Up @@ -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,
"<type Q::Literal> is abstract and uninstantiable",
"abstract Q types are uninstantiable (#140)";
}

{
Expand Down
6 changes: 5 additions & 1 deletion t/features/while-loop.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;