From ab08f1beee118f490c79e5d5716aa2cf9b480045 Mon Sep 17 00:00:00 2001 From: Josh Leder Date: Tue, 21 Apr 2020 11:33:11 -0600 Subject: [PATCH] fill error types --- checker/checker_test.go | 56 +++++++++++++++++++++++++++++++++++------ checker/errors.go | 3 +++ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/checker/checker_test.go b/checker/checker_test.go index 755b0216..73a6ae8b 100644 --- a/checker/checker_test.go +++ b/checker/checker_test.go @@ -22,6 +22,21 @@ func cleanup(value string) string { return result } +func makeIdents(name string, line, col int) []*parser.Ident { + return []*parser.Ident{{ + Pos: makePos(line, col), + Name: name, + }} +} + +func makePos(line, col int) lexer.Position { + return lexer.Position{ + Filename: "", + Line: line, + Column: col, + } +} + func TestChecker_Check(t *testing.T) { t.Parallel() @@ -308,7 +323,11 @@ func TestChecker_Check(t *testing.T) { run "echo hi" with opts } `, - ErrWrongArgType{}, + ErrWrongArgType{ + Pos: makePos(2, 8), + Expected: "option::run", + Found: "string", + }, }, /*{ "variadic options with bad method type", ` @@ -335,7 +354,11 @@ func TestChecker_Check(t *testing.T) { run "echo hi" with opts } `, - ErrWrongArgType{}, + ErrWrongArgType{ + Pos: makePos(2, 23), + Expected: "option::run", + Found: "string", + }, }, { "func call with bad arg count", ` @@ -347,7 +370,13 @@ func TestChecker_Check(t *testing.T) { run cmd } `, - ErrNumArgs{}, + ErrNumArgs{ + Expected: 1, + CallStmt: &parser.CallStmt{ + Pos: makePos(2, 1), + Args: make([]*parser.Expr, 2), + }, + }, }, { "func call with bad arg type: basic literal", ` @@ -359,7 +388,11 @@ func TestChecker_Check(t *testing.T) { run cmd } `, - ErrWrongArgType{}, + ErrWrongArgType{ + Pos: makePos(2, 8), + Expected: "string", + Found: "int", + }, }, /*{ "func call with bad arg type: basic ident", ` @@ -394,7 +427,11 @@ func TestChecker_Check(t *testing.T) { run cmd } `, - ErrWrongArgType{}, + ErrWrongArgType{ + Pos: makePos(2, 8), + Expected: "string", + Found: "fs", + }, }, { "func call with bad subtype", ` @@ -407,7 +444,11 @@ func TestChecker_Check(t *testing.T) { run cmd } `, - ErrWrongArgType{}, + ErrWrongArgType{ + Pos: makePos(2, 1), + Expected: "fs", + Found: "option::run", + }, }, /*{ "func call with bad option type", ` @@ -499,7 +540,6 @@ func TestChecker_Check(t *testing.T) { } } - func TestChecker_CheckSelectors(t *testing.T) { t.Parallel() @@ -572,7 +612,7 @@ func validateError(t *testing.T, expectedError error, actualError error) { // assume if we got a semantic error we really want // to validate the underlying error if semErr, ok := actualError.(ErrSemantic); ok { - require.IsType(t, expectedError, semErr.Errs[0]) + require.IsType(t, expectedError, semErr.Errs[0], "type %T", semErr.Errs[0]) require.Equal(t, expectedError.Error(), semErr.Errs[0].Error(), "error: %v", actualError) } else { require.IsType(t, expectedError, actualError, "error: %v", actualError) diff --git a/checker/errors.go b/checker/errors.go index 7b3838f9..4e8a5d99 100644 --- a/checker/errors.go +++ b/checker/errors.go @@ -55,6 +55,9 @@ type ErrNumArgs struct { } func (e ErrNumArgs) Error() string { + if e.CallStmt == nil { + return "" + } return fmt.Sprintf("%s expected %d args, found %d", FormatPos(e.CallStmt.Pos), e.Expected, len(e.CallStmt.Args)) }