-
Notifications
You must be signed in to change notification settings - Fork 20
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] Allowing/expecting a test case to fail/panic #108
Comments
cc @SupunS @turbolent |
I have come up with a draft for the following behavior: ➜ flow-merkle-proof git:(main) ✗ ~/Dev/forks/flow-cli/cmd/flow/flow-x86_64-linux- test --cover MerkleProof_test.cdc
Running tests...
Test results: "MerkleProof_test.cdc"
- PASS: testVerifyValidProof
- FAIL: testVerifyInvalidProof
Execution failed:
error: Expected error message to include: "not what I expected!". Found: Execution failed:
error: panic: invalid proof
--> ./contracts/MerkleProof.cdc:12:16
--> 7465737400000000000000000000000000000000000000000000000000000000:21:8
- PASS: testVerifyProofWithLowerLeaf
- PASS: testVerifyWithHigherLeaf
Coverage: 100.0% of statements
➜ flow-merkle-proof git:(main) ✗ ~/Dev/forks/flow-cli/cmd/flow/flow-x86_64-linux- test --cover MerkleProof_test.cdc
Running tests...
Test results: "MerkleProof_test.cdc"
- PASS: testVerifyValidProof
- PASS: testVerifyInvalidProof
- PASS: testVerifyProofWithLowerLeaf
- PASS: testVerifyWithHigherLeaf
Coverage: 100.0% of statements |
This sounds like a nice solution! 👌 Maybe the name of the function could be something like Going one step further, we could probably make the second parameter accept another string-matcher (rather than a string), so we could also support asserts like contains/startsWith/etc., for the error message. But of course, doesn't need to be in the first iteration, maybe a future improvement. |
Issue To Be Solved
Currently, there is no way to specify that a test is expected to fail/panic. For example:
For the
testVerifyInvalidProof
test case, theerror: panic: invalid proof
is the expected program behavior, however the test case is marked with aFAIL
status.Suggest A Solution
Add a built-in method/matcher, which wraps a method call execution and expects a panic with a certain error message.
Context
onflow/developer-grants#148
The text was updated successfully, but these errors were encountered: