-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 specific assertion helpers #1001
Add Kotlin specific assertion helpers #1001
Conversation
6ff9cd8
to
d8d7136
Compare
@@ -434,6 +439,13 @@ subprojects { subproj -> | |||
replaceRegex 'Empty line between last method and class closure', /\n([\s]+)}\n}\n$/, '\n$1}\n\n}\n' | |||
replaceRegex 'Remove line breaks between consecutive closing parentheses', /\)\n[\s]+\)\n/, '))\n' | |||
} | |||
|
|||
kotlin { | |||
ktlint("0.9.0") |
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.
ktlint is the only kotlin linter that exists at present. I use it for all of my projects and it's pretty nice.
If you want to have it use tabs instead of spaces for indentation it can be configured using an .editorconfig
file in the root directory of the project.
Somethings up with JKD9 that I'll try to solve tomorrow. |
* Example usage: | ||
* ```kotlin | ||
* val exception = assertThrows<IllegalArgumentException> { | ||
* throw IllegalArgumentException("Talk to a 🦆") |
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.
@JLLeitschuh On my phone, this particular sentence renders as
throw IllegalArgumentException("Talk to the <box-shape>")
where "<box-shape>" renders as a box-shaped character.
Was this intended?
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.
Its an emoji 🦆 (duck) character.
https://en.wikipedia.org/wiki/Rubber_duck_debugging
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.
Okay, thanks @JLLeitschuh.
It renders correctly as a duck emoji on my copy of Chrome, but unfortunately it still renders as a box (the character an application displays when it cannot identify what a character is supposed to be) in Gmail and on my Android phone.
I wonder if it would be more maintainable to swap the duck emoji out for a non-emoji character or phrase.
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.
Sorry, I meant to say that the duck emoji 🦆 renders correctly for me in your comment at #1001 (comment), but that it fails to render as a duck emoji in the GitHub code view on Chrome.
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.
Only in your iPhone browser right? It shows up fine for me on macOS Chrome.
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 want me to change this to something that will render correctly on an IOS device?
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'd quite like it to be changed so it renders correctly on Windows and Android, if that's alright.
(I'm not sure if you saw my earlier comment, but I don't actually own an iOS device. My devices are Windows and Android. 😄)
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.
Right, totally misread your message 😆
Sure, I can fix that.
Question...
Does the emoji in this code example render correctly for you?
http://junit.org/junit5/docs/current/user-guide/#writing-tests-display-names
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.
Hi @JLLeitschuh, yes it does. Here's a screenshot of what it looks like for me on my Windows 7 machine.
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'd like to add a kotlin example to the |
I'm asking in the kotlin slack channel about the problem with the compiler on JDK 9. |
Related issue: |
You should add a helper method for |
The JDK 9 issue "Should be fixed in Kotlin 1.1.4" |
This is actually blocked on: I'm going to have to revert my changes to changing |
b7a3807
to
7c9102c
Compare
83c5bf6
to
43c956e
Compare
@JLLeitschuh Hmm. As far as I'm aware, there's nothing else stopping this PR from being merged. I can only assume that the JUnit 5 team are busy with IRL things and have prioritised other tasks like Java 9 compatibility over this PR. So I'm sorry to say that I don't know for sure why this PR is in limbo. :/ |
Sorry to keep you waiting! The current plan is to get 5.1 M1 out with JDK 9 module scanning/selector support and then reconsider open PRs and the 5.1 backlog. As I've stated in #924 (comment), we want to add support to make writing assertions in Kotlin easier. So, please bear with us a little longer. We'll eventually get to this. We do not expect you to keep this branch up-to-date every time we commit something on master. |
Thank you for this explanation. Really helpful. I would have loved to see this in I hadn't realized that you had made the team decision explicit in that comment. Thank you for pointing it out. Please let me know when you want me to update this PR to resolve merge conflicts in preparation for merging. |
Hi @JLLeitschuh, we've finally decided to merge this pull request. However, there are still a few problems that need to be fixed:
|
You can't make ktlint use tabs, it's only configured to use spaces. The only configuration that there seems to be is to use either two spaces or four. I'm going to go with the ktlint default of using four spaces.
|
@@ -0,0 +1,93 @@ | |||
/* |
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 compiler will generate a class called AssertionsKt
to store these methods inside of. Is this acceptable? We can rename the generated class if necessary.
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 that's fine
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.
Cool!
used in https://kotlinlang.org/[Kotlin]. All JUnit Jupiter Kotlin assertions are top-level | ||
functions in the `org.junit.jupiter.api` package. | ||
|
||
// TODO: Change to using kotlin language highlighting after switch to rouge syntax highlighter |
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.
What is the status of switching to the rouge syntax highlighter?
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.
Still blocked by asciidoctor/asciidoctor#1040.
This has been updated per your comments. Let me know if you have anything else you need me to resolve. |
@JLLeitschuh [*.{kt,kts}]
indent_size=unset |
@marcphilipp This is your project, it's up to you to decide. @shyiko It would be good if that were documented somewhere (site or readme). Thanks for jumping in here! |
@@ -94,6 +94,16 @@ are `static` methods in the `{Assertions}` class. | |||
include::{testDir}/example/AssertionsDemo.java[tags=user_guide] | |||
---- | |||
|
|||
Junit Jupiter also comes with a few assertion methods that lend themselves well to being |
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.
JUnit
* [Stream] of functions to be executed. | ||
*/ | ||
internal typealias ExecutableStream = Stream<() -> Unit> | ||
internal fun ExecutableStream.convert() = map { Executable(it) } |
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.
Can we make these private?
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.
Effectively they are. internal
is different from java's "package private".
"Package private" in java means that if I (a consumer) create a file in a package called org.junit.api
then I can access "package private" things. The same is not true in Kotlin for internal
.
Internal is internal
only to source code that is compiled together.
I can make them private if you wish though.
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.
So I was able to make them private.
I remember that in earlier versions of kotlin you couldn't call private
things inside of inline
functions. I'm not certain if that limitation still exists. But it doesn't seem to be a problem here.
This travis failure doesn't look like it's created by me:
|
Restarting didn't solve the issue -- seems related to https://issues.sonatype.org/browse/MVNCENTRAL-1369 |
Same setup using Gradle 4.3.1 on master does work: https://travis-ci.org/junit-team/junit5/builds/300986101#L643 I don't see any changes in this PR that might effect the SSL configuration. |
Same on master now... sigh |
https://issues.sonatype.org/browse/MVNCENTRAL-2870 is the issue on the Maven Central side, gradle/gradle#3463 is for Gradle to use the proper CDN URL. |
Merged in 27c9c0d and 75c3d17. Thanks for your perseverance, @JLLeitschuh! 👍 |
Wooot!!!! This makes me so happy!!! |
Overview
This adds several Kotlin friendly assertions to the standard JUnit assertion API.
Closes #924
What does this actually add?
The
Assertions.kt
file you see has top-level functions. When the compiler runs it actually creates a "hidden" class calledAssertionsKt
that contains these static methods. This name could be changed with an annotation to something likeKotlinAssertions
. This name will never actually show up in anyone's code but will end up in the compiled bytecode so changing the name of this file will be a breaking change (like changing the name of any class in Java).Documentation
Unfortunately, I was unable to get (Dokka)[https://github.com/Kotlin/dokka] to behave correctly so that it would generate JavaDocs. The best that we can do on this front is document these methods in the user guide and show how they can be imported.
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@API
annotations