renatoathaydes / spock-reports

This project creates a global extension to Spock to create test reports.
Apache License 2.0
273 stars 68 forks source link

Error with customized template report creation #254

Closed ralbuh closed 1 year ago

ralbuh commented 1 year ago

We are using customized templates (actually an adoc conversion of provided md templates from this repo) for a while. Recently we upgraded to java 17 and newest springboot and the report generation started failing with the stated error.

We tried converting back to the included md templates in this repo (https://github.com/renatoathaydes/spock-reports/blob/master/src/main/resources/templateReportCreator/spec-template.md & https://github.com/renatoathaydes/spock-reports/blob/master/src/main/resources/templateReportCreator/summary-template.md) but same error there.

Our config:

spockReports {
  set 'com.athaydes.spockframework.report.IReportCreator': 'com.athaydes.spockframework.report.template.TemplateReportCreator'
  set 'com.athaydes.spockframework.report.template.TemplateReportCreator.specTemplateFile': '/templates/spec-template.md'
  set 'com.athaydes.spockframework.report.template.TemplateReportCreator.reportFileExtension': 'md'
  set 'com.athaydes.spockframework.report.template.TemplateReportCreator.summaryTemplateFile': '/templates/summary-template.md'
  set 'com.athaydes.spockframework.report.template.TemplateReportCreator.summaryFileName': 'index.md'
  set 'com.athaydes.spockframework.report.outputDir': 'src/main/asciidoc/spock-reports'
  set 'com.athaydes.spockframework.report.hideEmptyBlocks': false
}

Error:

2023-08-17 13:47:12.946  WARN [           main] c.a.s.r.t.TemplateReportCreator          : Unexpected error creating report
 java.lang.IllegalArgumentException: Cannot compare java.util.ArrayList with value '[]' and java.lang.Integer with value '0'
        at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.compareToWithEqualityCheck(DefaultTypeTransformation.java:824)
        at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.compareTo(DefaultTypeTransformation.java:753)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.compareTo(ScriptBytecodeAdapter.java:773)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.compareGreaterThan(ScriptBytecodeAdapter.java:856)
        at groovy.tmp.templates.GStringTemplateScript9$_getTemplate_closure1$_closure3.doCall(GStringTemplateScript9.groovy:34)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:328)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:279)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1006)
        at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
        at groovy.tmp.templates.GStringTemplateScript9$_getTemplate_closure1.doCall(GStringTemplateScript9.groovy:61)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:328)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:279)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1006)
        at groovy.lang.Closure.call(Closure.java:418)
        at groovy.lang.Closure$WritableClosure.writeTo(Closure.java:921)
        at groovy.lang.Closure$WritableClosure.toString(Closure.java:1064)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:198)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:75)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
        at com.athaydes.spockframework.report.template.TemplateReportCreator.reportFor(TemplateReportCreator.groovy:126)
        at com.athaydes.spockframework.report.template.TemplateReportCreator$reportFor.callCurrent(Unknown Source)
        at com.athaydes.spockframework.report.template.TemplateReportCreator.createReportFor(TemplateReportCreator.groovy:99)
        at com.athaydes.spockframework.report.IReportCreator$createReportFor.call(Unknown Source)
        at com.athaydes.spockframework.report.SpecInfoListener.createReport(SpockReportExtension.groovy:283)
        at com.athaydes.spockframework.report.SpecInfoListener.afterSpec(SpockReportExtension.groovy:194)
        at org.spockframework.runtime.MasterRunListener.afterSpec(MasterRunListener.java:64)
        at org.spockframework.runtime.MasterRunSupervisor.afterSpec(MasterRunSupervisor.java:128)
        at org.spockframework.runtime.PlatformSpecRunner.runSpec(PlatformSpecRunner.java:56)
        at org.spockframework.runtime.SpecNode.around(SpecNode.java:63)
        at org.spockframework.runtime.SpecNode.around(SpecNode.java:11)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
        at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
        at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
        at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
        at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
        at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
        at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:150)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
renatoathaydes commented 1 year ago

The default MD template is tested in every build. Are you sure there's an error even with the MD template from this repo? Are you on the latest version? Please make sure you are, because on Java 17, you need some fairly recent version... see the version matrix in the README page.

ralbuh commented 1 year ago

Yeah versions are correct afaik.

I just generated a dummy project from spring initializr and added minimal setup and one dummy test. Here you can see the same error. https://github.com/ralbuh/spock-report-issue-254

If you run a mvn clean install on that demo project you can see the same error message

renatoathaydes commented 1 year ago

The MD template seems to have a bug:

if ( feature.attachments.size > 0 )

On line 32 for me... Can you change that to this:

if ( feature.attachments.size() > 0 )

And try again?

ralbuh commented 1 year ago

Yeah that solved it. Very nice, thanks for you help again and you quick reply!

renatoathaydes commented 1 year ago

I will keep this open as I'll have to release a fix. There's another bug I wanted to fix as well so it's time for a release anyway. Glad it works for you.

renatoathaydes commented 1 year ago

This line has been the same since 2016. There seems to be tests that check this. I just don't understand how this could break now, or how it was actually working?!

The code is printing "See: " if that condition is true:

        if ( feature.attachments.size > 0 ) {
            out << '\n#### ' << 'See:' << '\n\n'

There's a test that checks this: https://github.com/renatoathaydes/spock-reports/blob/master/src/test/resources/FakeTest.md (look for "See:")

So, this is actually working on my tests :D.

My guess is that you used a specific version of Groovy that made size stop working! Can you check which version you had running @ralbuh ?

renatoathaydes commented 1 year ago

This fix is now released on versions 2.5.1-groovy-3.0 and 2.5.1-groovy-4.0.