-
Notifications
You must be signed in to change notification settings - Fork 12
Test function call semantics #104
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
Open
slushie
wants to merge
5
commits into
openllb:master
Choose a base branch
from
slushie:issue-87
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b7cff20
test cases for function calls
slushie cbc87e2
disable broken tests
slushie 0b05571
add a few more cases for call variants
slushie 7f822de
fill error types
slushie 9dd90fd
consolidate a few similar cases that shouldn't pass, but do
slushie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,14 @@ func cleanup(value string) string { | |
return result | ||
} | ||
|
||
func makePos(line, col int) lexer.Position { //nolint:unparam | ||
return lexer.Position{ | ||
Filename: "<stdin>", | ||
Line: line, | ||
Column: col, | ||
} | ||
} | ||
|
||
func TestChecker_Check(t *testing.T) { | ||
t.Parallel() | ||
|
||
|
@@ -297,15 +305,214 @@ func TestChecker_Check(t *testing.T) { | |
Name: "myFunction", | ||
}, | ||
}, | ||
}} { | ||
}, { | ||
"variadic options with bad type", | ||
` | ||
fs default() { | ||
myfunc "string" | ||
} | ||
fs myfunc(variadic option::run opts) { | ||
image "busybox" | ||
run "echo hi" with opts | ||
} | ||
`, | ||
ErrWrongArgType{ | ||
Pos: makePos(2, 8), | ||
Expected: "option::run", | ||
Found: "string", | ||
}, | ||
}, /*{ | ||
"variadic options with bad method type", | ||
` | ||
fs default() { | ||
myfunc option::run { | ||
copyOpt | ||
} | ||
} | ||
fs myfunc(variadic option::run opts) { | ||
image "busybox" | ||
run "echo hi" with opts | ||
} | ||
option::copy copyOpt() {} | ||
`, | ||
ErrWrongArgType{}, | ||
},*/{ | ||
"variadic options with mixed types", | ||
` | ||
fs default() { | ||
myfunc option::run {} "string" | ||
} | ||
fs myfunc(variadic option::run opts) { | ||
image "busybox" | ||
run "echo hi" with opts | ||
} | ||
`, | ||
ErrWrongArgType{ | ||
Pos: makePos(2, 23), | ||
Expected: "option::run", | ||
Found: "string", | ||
}, | ||
}, { | ||
"func call with bad arg count", | ||
` | ||
fs default() { | ||
myfunc "a" "b" | ||
} | ||
fs myfunc(string cmd) { | ||
image "busybox" | ||
run cmd | ||
} | ||
`, | ||
ErrNumArgs{ | ||
Expected: 1, | ||
CallStmt: &parser.CallStmt{ | ||
Pos: makePos(2, 1), | ||
Args: make([]*parser.Expr, 2), | ||
}, | ||
}, | ||
}, { | ||
"func call with bad arg type: basic literal", | ||
` | ||
fs default() { | ||
myfunc 1 | ||
} | ||
fs myfunc(string cmd) { | ||
image "busybox" | ||
run cmd | ||
} | ||
`, | ||
ErrWrongArgType{ | ||
Pos: makePos(2, 8), | ||
Expected: "string", | ||
Found: "int", | ||
}, | ||
}, /*{ | ||
"func call with bad arg: basic ident", | ||
` | ||
fs default() { | ||
myfunc s | ||
} | ||
string s() { value "string"; } | ||
int myfunc(int i) {} | ||
`, | ||
ErrWrongArgType{}, | ||
},*/ /*{ | ||
"func call with bad arg: func ident", | ||
` | ||
fs default() { | ||
myfunc foo | ||
} | ||
fs foo() {} | ||
fs myfunc(string cmd) { | ||
image "busybox" | ||
run cmd | ||
} | ||
`, | ||
ErrWrongArgType{}, | ||
},*/{ | ||
"func call with bad arg type: func literal", | ||
` | ||
fs default() { | ||
myfunc fs {} | ||
} | ||
fs myfunc(string cmd) { | ||
image "busybox" | ||
run cmd | ||
} | ||
`, | ||
ErrWrongArgType{ | ||
Pos: makePos(2, 8), | ||
Expected: "string", | ||
Found: "fs", | ||
}, | ||
}, { | ||
"func call with bad subtype", | ||
` | ||
fs default() { | ||
runOpt | ||
} | ||
option::run runOpt() {} | ||
fs myfunc(string cmd) { | ||
image "busybox" | ||
run cmd | ||
} | ||
`, | ||
ErrWrongArgType{ | ||
Pos: makePos(2, 1), | ||
Expected: "fs", | ||
Found: "option::run", | ||
}, | ||
}, { | ||
"func call with option", | ||
` | ||
fs default() { | ||
scratch | ||
run "foo" with option { | ||
mount fs { scratch; } "/" | ||
} | ||
} | ||
`, | ||
nil, | ||
}, { | ||
"func call with option: inline literal", | ||
` | ||
fs default() { | ||
scratch | ||
run "foo" with option { | ||
fooOpt | ||
} | ||
} | ||
option::run fooOpt() {} | ||
`, | ||
nil, | ||
}, { | ||
"func call with option: ident", | ||
` | ||
fs default() { | ||
scratch | ||
run "foo" with fooOpt | ||
} | ||
option::run fooOpt() {} | ||
`, | ||
nil, | ||
}, /*{ | ||
"func call with bad option: inline literal", | ||
` | ||
fs default() { | ||
scratch | ||
run "foo" with option { | ||
fooOpt | ||
} | ||
} | ||
option::copy fooOpt() {} | ||
`, | ||
ErrWrongArgType{}, | ||
},*/ /*{ | ||
"func call with bad option: ident", | ||
` | ||
fs default() { | ||
scratch | ||
run "foo" with fooOpt | ||
} | ||
option::copy fooOpt() {} | ||
`, | ||
ErrWrongArgType{}, | ||
}*/} { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
in := strings.NewReader(cleanup(tc.input)) | ||
|
||
mod, err := parser.Parse(in) | ||
require.NoError(t, err) | ||
|
||
err = Check(mod) | ||
var r interface{} | ||
func() { | ||
defer func() { | ||
r = recover() | ||
}() | ||
err = Check(mod) | ||
}() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably return |
||
require.Nil(t, r, "panic: %+v", r) | ||
validateError(t, tc.errType, err) | ||
}) | ||
} | ||
|
@@ -383,10 +590,10 @@ 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.Equal(t, expectedError.Error(), semErr.Errs[0].Error()) | ||
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) | ||
require.IsType(t, expectedError, actualError, "error: %v", actualError) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should abstract the testing away from these node positions? Or do you think they belong here?