WriteThemFirst / approvals-java

Approval testing library for Java. Alleviates the burden of hand-writing assertions.
GNU General Public License v3.0
8 stars 4 forks source link

Groovy support #86

Closed ggramlich closed 5 years ago

ggramlich commented 5 years ago

This pull request allows approvals to be used with Groovy projects.

Without these changes, the stacktrace is not interpreted correctly and the file paths calculated for the approval files refer to the Approvals class itself and not the test class.

I added a dependency to groovy 2.4.12, because that is the version for the project where I use approvals. Switching to a newer version of the groovy dependency for approvals-java causes my IDE (Eclipse) to have problems with the project that I am testing.

codecov[bot] commented 5 years ago

Codecov Report

Merging #86 into master will not change coverage. The diff coverage is 0%.

Impacted file tree graph

@@         Coverage Diff          @@
##           master   #86   +/-   ##
====================================
  Coverage       0%    0%           
====================================
  Files          22    22           
  Lines         535   544    +9     
  Branches       30    32    +2     
====================================
- Misses        535   544    +9
Impacted Files Coverage Δ
...hub/writethemfirst/approvals/utils/StackUtils.java 0% <0%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9bbe580...af8dc85. Read the comment docs.

ggramlich commented 5 years ago

@tyrcho Is there anything I can do, to make the travis buld green? The default-deploy fails with status code 401 (unauthorized).

tyrcho commented 5 years ago

Hi @ggramlich , thanks for the PR ! I'll have a look during the week.

I'm not keen on adding dependencies (to keep the library small and simple), but I've had similar issues with Kotlin and Scala (my main language) so I'm confident we can figure a solution for Groovy.

ggramlich commented 5 years ago

Thanks @tyrcho I totally understand that and I tried to keep the changes as small as possible. It would be awesome to be able to use approvals in Groovy without having to support my own fork.

tyrcho commented 5 years ago

I have created today approvals-scala for a similar purpose, would you submit a PR to approvals-groovy (currently empty) with a complete groovy project ?

I will help with bintray publishing but I've never worked with groovy before so I need you to handle the gradle (or whatever you like) setup.

ggramlich commented 5 years ago

Thanks @tyrcho I will try on thursday.

Actually, I am not sure yet, how to do it, since I would have to exchange both public static methods in StackUtils. These static methods are only called from the Approver class, so I might be able to make the Approver constructor not call the static method from StackUtils directly, but delegate to an instance method of Approver in approvals-java and then monkey patch the Approver in approvals-groovy.

Do you have any better idea?

ggramlich commented 5 years ago

I did not get far today. But I will continue on the weekend.

tyrcho commented 5 years ago

I finally took the time to look more deeply into your question ... I would suggest to use java SPI for this concern. https://docs.oracle.com/javase/tutorial/ext/basics/spi.html

Basically I would create an interface and default implementation in approvals-java and you would override it in approvals-groovy.

I think StackUtils.callerMethod would be the method in this interface so you could override it.

I'll try to make a POC in the next days and share it with you.

ggramlich commented 5 years ago

That's nice. Thank you.

New stuff to learn.

tyrcho commented 5 years ago

I've started the implementation. This side of the library seems OK (see the latest 2 ♻️ commits).

I'll try to show in the scala version how to use it so you have a model for groovy, but you can already find inspiration here, these 2 files are what you will need to provide in the groovy jar:

tyrcho commented 5 years ago

You can find a sample implementation in this commit

I've tested that it works in the demo app

tyrcho commented 5 years ago

I've finished the work on the scala project, it publishes on bintray (and should sync soon to maven central).

Tell me if you need more help with the groovy version !

ggramlich commented 5 years ago

Should the 0.12.0 already be available in maven central?

compile 'com.github.writethemfirst:approvals-java:0.11.1'

works for me, but not 0.12.0.

tyrcho commented 5 years ago

the sync from bintray to maven central is flaky ... it used to work OK but did not succeed this week :(

Can you configure groovy/gradle to download from bintray until sync is resolved ?

repositories {
    maven {
        url  "https://dl.bintray.com/writethemfirst/maven" 
    }
}

https://bintray.com/writethemfirst/maven/approvals-java (button "set me up")

tyrcho commented 5 years ago

it seems that Maven Central has big issues at the moment ... https://status.maven.org/?utm_source=embed

tyrcho commented 5 years ago

Seems that publication to Maven Central finally succeeded ! You should be able to proceed. Tell me if I can be of any help !

ggramlich commented 5 years ago

Thanks - yes I could retrieve 0.12.0 and I could also verify that the SPI mechanism works. I am at it - sorry for the slow progress.

ggramlich commented 5 years ago

@tyrcho I made some progress. https://github.com/ggramlich/approvals-groovy is functional so far. It still needs a README and a licence, I will add that similar to approvals-java.

Also I will probably go for an older version of groovy to allow better compatibility for users and I will add JUnit 5 tests (currently only JUnit 4). I had the impression, that test methods are called differently in both frameworks.

I have no idea how to publish to maven central, but as I understood, you can take care of that.

tyrcho commented 5 years ago

cool, it looks good ! I just merged it into https://github.com/WriteThemFirst/approvals-groovy so I can start hacking on it also.

To publish, we need first to publish on bintray, I think this plugin should do the job : https://github.com/bintray/gradle-bintray-plugin Can you try to configure it roughly and also provide either

tyrcho commented 5 years ago

I just gave you maintainer rights on https://github.com/WriteThemFirst/approvals-groovy so we can keep only one repository in the future.