Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
assert.fails
to check if a function fails. (#66)
Example: ```python def might_fail(input): if input < 10: fail("input is less than 10") else: return input def test_might_fail(t): t.assert.fails(might_fail, 3) # passes t.assert.fails(might_fail, 14) # assertion failure: function might_fail should have failed ```
- Loading branch information
1 parent
40659e5
commit dfe37ba
Showing
5 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package skycfg | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.starlark.net/starlark" | ||
) | ||
|
||
var Fail = starlark.NewBuiltin("fail", failImpl) | ||
|
||
func failImpl(t *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) { | ||
var msg string | ||
if err := starlark.UnpackPositionalArgs(fn.Name(), args, kwargs, 1, &msg); err != nil { | ||
return nil, err | ||
} | ||
callStack := t.CallStack() | ||
callStack.Pop() | ||
return nil, fmt.Errorf("[%s] %s\n%s", callStack.At(0).Pos, msg, callStack.String()) | ||
} |
This file contains 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