-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add Kotlin contracts to exposed Kotlin API #3259
Open
awelless
wants to merge
18
commits into
junit-team:main
Choose a base branch
from
awelless:main
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
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 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e3b3ac3
Added contracts for kotlin assertions
awelless edbe73f
Merge branch 'main' into main
awelless 252cad2
Mark new kotlin assetion methods as experimental
awelless 1d5811b
Adjust assertThrows contract
awelless 19922d6
Add contract for fail
awelless eccb259
Don't return a value from assertNotNull
awelless e427978
Increase API version
awelless 544b4e1
Add assertInstanceOf methods
awelless 437d29e
assertInstanceOf methods accept nullable values
awelless 43c08ea
Test for assertInstanceOf nullable upcast
awelless ff9fd39
Specify lambda InvocationKind explicitly for assertThrows methods
awelless 5a70965
Rename variable names in new assertion examples
awelless 666f73f
Add API annotation for new fail assertion
awelless 9920cf9
Make the comments be sentences
awelless 4d21486
Adjust contract for assertTimeoutPreemptively
awelless 30b9b78
Removed contracts for methods where lambdas may throw exceptions
awelless 41f00c0
Add more tests for methods with contracts
awelless 69e9c38
Merge branch 'main' into main
awelless File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Oops, something went wrong.
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.
I think
fun fail(message: (() -> String)?)
should also have a contract added to it?Also, can contracts be added to
vararg executables: () -> Unit
?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.
callsInPlace
supports only non-nullable arguments.It would be great to have something like:
but
if
is not allowed in a contract definition.Similar thing applies to
vararg executables: () -> Unit
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.
Could the
if
be partially resolved like this? So that more (most) calls end up using the contract description for analysis?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.
The method signatures are same from JVM perspective.
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.
Huh, I didn't get that when I tried. Anyway, @JvmName usually helps. The question is if this is a feasible solution to get contract in for most, and still keep supporting other edge cases. What's the use case for nullable lambda here?
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.
Yes, creating a separate method with a contract and non-nullable lambda allows kotlin compiler to carry out contract checks when it's sure the passed lambda is not null.
I assume, lambda is made nullable to resemble existing java api where
messageSupplier
can be nullableThere 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.
callsInPlace
forfail
method is also specified withInvocationKind.UNKNOWN
.If we set it to
EXACTLY_ONCE
the following code compiles:Here we reassign
value
albeit it isval
. I reckon it isn't desirable to allow this code to compile