-
Notifications
You must be signed in to change notification settings - Fork 131
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
Introduce the Test.expectFailure
function
#2468
Introduce the Test.expectFailure
function
#2468
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2468 +/- ##
==========================================
+ Coverage 78.28% 78.30% +0.01%
==========================================
Files 327 327
Lines 72773 72851 +78
==========================================
+ Hits 56971 57044 +73
- Misses 13707 13710 +3
- Partials 2095 2097 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
I will certainly add more tests, I just opened this up in order to bootstrap a conversation around the implementation details and desired functionality 🙏 |
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.
Looks great! 👍
@turbolent I have added more test cases, and fixed the scenario where a failure is expected, but there is none (946ffae#diff-4709f76365b48c2caca87b859afcc573afb62cb4e6186b9431d2b540972d402fR619) |
import Test
pub struct Foo {
priv let answer: UInt8
init(answer: UInt8) {
self.answer = answer
}
pub fun correctAnswer(_ input: UInt8): Bool {
if self.answer != input {
panic("wrong answer!")
}
return true
}
}
pub fun testOne() {
let foo = Foo(answer: 42)
Test.expectFailure(fun(): Void {
foo.correctAnswer(42)
}, errorMessageSubstring: "wrong answer")
}
pub fun testTwo() {
let foo = Foo(answer: 42)
Test.expectFailure(fun(): Void {
foo.correctAnswer(43)
}, errorMessageSubstring: "wrong answer!")
}
pub fun testThree() {
let foo = Foo(answer: 42)
Test.expectFailure(fun(): Void {
foo.correctAnswer(43)
}, errorMessageSubstring: "what is wrong?!")
} And the equivalent test execution results: ~/Dev/forks/flow-cli/cmd/flow/flow-x86_64-linux- test my_expect_failure_tests.cdc
Test results: "my_expect_failure_tests.cdc"
- FAIL: testOne
Execution failed:
error: Execution failed:
error: Expected a failure, but found none.
--> 7465737400000000000000000000000000000000000000000000000000000000:14:8
--> 7465737400000000000000000000000000000000000000000000000000000000:14:8
- PASS: testTwo
- FAIL: testThree
Execution failed:
error: Expected error message to include: "what is wrong?!". Found: Execution failed:
error: panic: wrong answer!
--> 7465737400000000000000000000000000000000000000000000000000000000:12:12
--> 7465737400000000000000000000000000000000000000000000000000000000:12:12 |
@m-Peter figured out what's wrong and also refactored the recover logic, but can't push the commits. Could you please allow commits from maintainers by checking the "Allow edits from maintainers" box? (see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) |
@turbolent It seems that it's not possible for organization repositories.. See https://github.com/orgs/community/discussions/5634 I am unable to find this option also.. |
@turbolent I have sent you an invitation as a collaborator, you should be able to do so now 🙏 |
@m-Peter Thank you! Pushed up the fix. The issue was that the |
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.
Nice! Thanks for adding this
d26ce3e
to
b1fb4c4
Compare
Oh, I see, great catch 💯 💯 💯 I tried locally the newest changes, but it seems that they affect the displayed error messages. For example: I have added a commit to make them less verbose: What do you think about it? I can drop the changes, if you want. |
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.
Looks better, nice!
b1fb4c4
to
cf7a943
Compare
cf7a943
to
246e5ef
Compare
@turbolent It was rather impossible to rebase on master, after #2403 was merged. So I had to reset the commits of this PR, manually apply the changes and then force-push. I have added you as co-author though 🙏 |
Co-Authored-By: Bastian Müller <bastian@axiomzen.co>
246e5ef
to
9eb2fac
Compare
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.
Nice!
Closes onflow/cadence-tools#108
Description
Introduces a new native function for allowing/expecting a test case to fail/panic, with a specified error message.
master
branchFiles changed
in the Github PR explorer