From c5f5b20d0e7c27b5ee8c2239660eac83cccf2d91 Mon Sep 17 00:00:00 2001 From: Renato Athaydes Date: Sun, 30 Oct 2022 19:29:40 +0100 Subject: [PATCH 1/3] Upgraded to Groovy 4. Various logging and necessary improvements. --- build.gradle | 24 +++++++------- releases/Release_Notes.txt | 5 +++ .../report/SpockReportExtension.groovy | 8 ++--- .../report/internal/ConfigLoader.groovy | 31 ++++++++++++------- .../spockframework/report/util/Utils.groovy | 5 ++- .../internal/HtmlReportAggregatorSpec.groovy | 4 --- .../internal/HtmlReportCreatorSpec.groovy | 6 ---- .../report/internal/TestHelper.groovy | 8 +++-- .../report/util/UtilsSpec.groovy | 4 ++- 9 files changed, 54 insertions(+), 41 deletions(-) diff --git a/build.gradle b/build.gradle index 96f896de..aa2dbdee 100644 --- a/build.gradle +++ b/build.gradle @@ -9,34 +9,34 @@ plugins { defaultTasks 'check' group = 'com.athaydes' -version = "2.3.1-groovy-3.0" +version = "2.4.0-groovy-4" description = 'This project is a global extension for Spock to create test (or, in Spock terms, Specifications) reports.' sourceCompatibility = '1.8' targetCompatibility = '1.8' -def groovyVersion = '3.0.9' -def spockVersion = '2.1-groovy-3.0' +def groovyVersion = '4.0.6' +def spockVersion = '2.3-groovy-4.0' repositories { mavenCentral() } dependencies { - api "org.codehaus.groovy:groovy:${groovyVersion}" - implementation "org.codehaus.groovy:groovy-xml:${groovyVersion}" - implementation "org.codehaus.groovy:groovy-json:${groovyVersion}" - implementation "org.codehaus.groovy:groovy-templates:${groovyVersion}" - api "org.spockframework:spock-core:${spockVersion}", { + api "org.apache.groovy:groovy:${groovyVersion}" + implementation "org.apache.groovy:groovy-xml:${groovyVersion}" + implementation "org.apache.groovy:groovy-json:${groovyVersion}" + implementation "org.apache.groovy:groovy-templates:${groovyVersion}" + implementation platform( "org.spockframework:spock-bom:$spockVersion" ) + api "org.spockframework:spock-core", { exclude group: 'org.codehaus.groovy' } - implementation 'org.slf4j:slf4j-api:1.7.30' - testImplementation platform( 'org.junit:junit-bom:5.7.0' ) + implementation 'org.slf4j:slf4j-api:1.7.36' + testImplementation platform( 'org.junit:junit-bom:5.9.1' ) testImplementation 'org.junit.platform:junit-platform-testkit' testImplementation 'org.junit.jupiter:junit-jupiter' - testImplementation "org.codehaus.groovy:groovy-test:${groovyVersion}" testImplementation "cglib:cglib-nodep:3.3.0" - testImplementation "org.slf4j:slf4j-simple:1.7.30" + testImplementation "org.slf4j:slf4j-simple:1.7.36" } test { diff --git a/releases/Release_Notes.txt b/releases/Release_Notes.txt index b96e3f2f..2153ebb3 100644 --- a/releases/Release_Notes.txt +++ b/releases/Release_Notes.txt @@ -1,3 +1,8 @@ +2.4.0-groovy-4 - 2022 Oct 30 + +* Upgrade Groovy version to 4.0.6. +* #235 Maintain source code indentation in Vivid report. + 2.3.1-groovy-3.0 - 2022 Aug 25 * #231 fixed disappearing blocks in vivid reports when spec uses annotations (thanks to @ArkiMargust). diff --git a/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy b/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy index f34dd2e1..b95adfb0 100644 --- a/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy +++ b/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy @@ -43,14 +43,14 @@ class SpockReportExtension implements IGlobalExtension { @Override void start() { if ( !initialized.getAndSet( true ) ) { - log.info( "Got configuration from Spock: {}", configuration ) - log.debug "Configuring ${this.class.name}" + log.debug( "Got configuration from Spock: {}", configuration ) + log.debug 'Configuring {}', this.class.name def config = configLoader.loadConfig( configuration ) // Read the class report property and exit if its not set String commaListOfReportClasses = config.remove( IReportCreator.name ) if ( !commaListOfReportClasses ) { - log.warn( "Missing property: ${IReportCreator.name} - no report classes defined" ) + log.warn( 'Missing property: {} - no report classes defined', IReportCreator.name ) return } @@ -78,7 +78,7 @@ class SpockReportExtension implements IGlobalExtension { if ( reportCreator != null ) { specInfo.addListener createListener() } else { - log.warn "Not creating report for ${specInfo.name} as reportCreator is null" + log.warn 'Not creating report for {} as reportCreator is null', specInfo.name } } diff --git a/src/main/groovy/com/athaydes/spockframework/report/internal/ConfigLoader.groovy b/src/main/groovy/com/athaydes/spockframework/report/internal/ConfigLoader.groovy index abd9a5a1..596e2097 100644 --- a/src/main/groovy/com/athaydes/spockframework/report/internal/ConfigLoader.groovy +++ b/src/main/groovy/com/athaydes/spockframework/report/internal/ConfigLoader.groovy @@ -2,6 +2,8 @@ package com.athaydes.spockframework.report.internal import com.athaydes.spockframework.report.IReportCreator import com.athaydes.spockframework.report.util.Utils +import groovy.transform.CompileDynamic +import groovy.transform.CompileStatic import groovy.util.logging.Slf4j import org.spockframework.runtime.RunContext import org.spockframework.util.Nullable @@ -11,11 +13,12 @@ import org.spockframework.util.Nullable * User: Renato */ @Slf4j +@CompileStatic class ConfigLoader { static final String SYS_PROPERTY_PREFIX = 'com.athaydes.spockframework.report.' - static final CUSTOM_CONFIG = "META-INF/services/${IReportCreator.class.name}.properties" + static final String CUSTOM_CONFIG = "META-INF/services/${IReportCreator.class.name}.properties" Properties loadConfig( @Nullable SpockReportsConfiguration spockConfig = null ) { def props = loadSystemProperties( @@ -23,14 +26,15 @@ class ConfigLoader { loadCustomProperties( loadDefaultProperties() ) ) ) - log.info( "SpockReports config loaded: {}", props ) + log.debug( "SpockReports config loaded: {}", props ) props } void apply( IReportCreator reportCreator, Properties config ) { - config.each { String key, value -> + config.each { keyObject, value -> + String key = keyObject.toString() int lastDotIndex = key.lastIndexOf( '.' ) if ( lastDotIndex > 0 && lastDotIndex + 1 < key.size() ) { @@ -42,14 +46,9 @@ class ConfigLoader { if ( metaProperty ) { def propertyType = metaProperty.type - try { - reportCreator."$propertyName" = Utils.convertProperty( value, propertyType ) - log.debug( "Property $propertyName set to $value" ) - } catch ( ignore ) { - log.warn( "Invalid property value for property '{}'", propertyName ) - } + setDynamic( reportCreator, propertyName, Utils.convertProperty( value, propertyType ) ) } else { - log.warn( "Property [{}] not acceptable by IReportCreator of type {}", + log.warn( "Property '{}' not acceptable by IReportCreator of type {}", propertyName, reportCreator.class.name ) } } else { @@ -60,6 +59,16 @@ class ConfigLoader { } } + @CompileDynamic + private static void setDynamic( receiver, String propertyName, value ) { + try { + receiver."$propertyName" = value + log.debug( "Property '{}' set to '{}'", propertyName, value ) + } catch ( ignore ) { + log.warn( "Invalid property value for property '{}'", propertyName ) + } + } + private Properties loadSystemProperties( Properties props ) { def filteredProps = System.properties.findAll { entry -> def key = entry.key @@ -74,7 +83,7 @@ class ConfigLoader { System.properties.findAll { entry -> def key = entry.key key instanceof String && key.startsWith( reportClassPrefix ) - }.each { String key, value -> + }.each { key, value -> filteredProps[ key ] = value } } diff --git a/src/main/groovy/com/athaydes/spockframework/report/util/Utils.groovy b/src/main/groovy/com/athaydes/spockframework/report/util/Utils.groovy index d935ea42..66d7670e 100644 --- a/src/main/groovy/com/athaydes/spockframework/report/util/Utils.groovy +++ b/src/main/groovy/com/athaydes/spockframework/report/util/Utils.groovy @@ -386,6 +386,7 @@ class Utils { case boolean: return Boolean.parseBoolean( value as String ) case Character: + // fallthrough case char: char convertedValue if ( value instanceof Character ) { @@ -400,8 +401,10 @@ class Utils { } else { return Character.valueOf( convertedValue ) } + case Object: + return value default: - throw new IllegalArgumentException( "Cannot convert to type: " + type ) + throw new IllegalArgumentException( "Cannot convert to type " + type.name + ": " + value ) } } diff --git a/src/test/groovy/com/athaydes/spockframework/report/internal/HtmlReportAggregatorSpec.groovy b/src/test/groovy/com/athaydes/spockframework/report/internal/HtmlReportAggregatorSpec.groovy index 089156de..e32d9eb5 100644 --- a/src/test/groovy/com/athaydes/spockframework/report/internal/HtmlReportAggregatorSpec.groovy +++ b/src/test/groovy/com/athaydes/spockframework/report/internal/HtmlReportAggregatorSpec.groovy @@ -13,10 +13,6 @@ import java.util.concurrent.TimeUnit import static com.athaydes.spockframework.report.internal.TestHelper.assertVerySimilar import static com.athaydes.spockframework.report.internal.TestHelper.minify -/** - * - * User: Renato - */ class HtmlReportAggregatorSpec extends ReportSpec { def """When a single spec data is provided to the HtmlReportAggregator it diff --git a/src/test/groovy/com/athaydes/spockframework/report/internal/HtmlReportCreatorSpec.groovy b/src/test/groovy/com/athaydes/spockframework/report/internal/HtmlReportCreatorSpec.groovy index cf65cec1..c772a593 100644 --- a/src/test/groovy/com/athaydes/spockframework/report/internal/HtmlReportCreatorSpec.groovy +++ b/src/test/groovy/com/athaydes/spockframework/report/internal/HtmlReportCreatorSpec.groovy @@ -10,7 +10,6 @@ import com.athaydes.spockframework.report.VividFakeTest import com.athaydes.spockframework.report.engine.CanRunSpockSpecs import com.athaydes.spockframework.report.util.Hasher import groovy.xml.MarkupBuilder -import org.junit.runner.Description import org.spockframework.runtime.model.SpecInfo import spock.lang.Unroll @@ -19,10 +18,6 @@ import java.nio.file.Paths import static com.athaydes.spockframework.report.internal.TestHelper.assertVerySimilar import static com.athaydes.spockframework.report.internal.TestHelper.minify -/** - * - * User: Renato - */ @Unroll class HtmlReportCreatorSpec extends ReportSpec implements CanRunSpockSpecs { @@ -139,7 +134,6 @@ class HtmlReportCreatorSpec extends ReportSpec "A mock report aggregator, a stubbed SpecData and an injected MarkupBuilder" def stubInfo = Stub( SpecInfo ) def stubSpecData = new SpecData( stubInfo ) - stubInfo.description >> Description.createTestDescription( this.class, 'ignore' ) def builder = new MarkupBuilder( Stub( Writer ) ) when: diff --git a/src/test/groovy/com/athaydes/spockframework/report/internal/TestHelper.groovy b/src/test/groovy/com/athaydes/spockframework/report/internal/TestHelper.groovy index 89b833b5..54831fef 100644 --- a/src/test/groovy/com/athaydes/spockframework/report/internal/TestHelper.groovy +++ b/src/test/groovy/com/athaydes/spockframework/report/internal/TestHelper.groovy @@ -1,6 +1,6 @@ package com.athaydes.spockframework.report.internal -import junit.framework.ComparisonFailure +import org.junit.jupiter.api.AssertionFailureBuilder import spock.lang.Narrative import spock.lang.Specification import spock.lang.Title @@ -40,7 +40,11 @@ class TestHelper extends Specification { def error = "\n\"$aPart\" != \"$bPart\"\n" + "${' ' * ( errorIndex + 1 )}^${' ' * ( aPart.size() + 5 )}^" - throw new ComparisonFailure( error, expected, actual ) + throw AssertionFailureBuilder.assertionFailure() + .message( error ) + .expected( expected ) + .actual( actual ) + .build() } assert expected == actual diff --git a/src/test/groovy/com/athaydes/spockframework/report/util/UtilsSpec.groovy b/src/test/groovy/com/athaydes/spockframework/report/util/UtilsSpec.groovy index e68c9a39..7c33b8ff 100644 --- a/src/test/groovy/com/athaydes/spockframework/report/util/UtilsSpec.groovy +++ b/src/test/groovy/com/athaydes/spockframework/report/util/UtilsSpec.groovy @@ -3,6 +3,8 @@ package com.athaydes.spockframework.report.util import spock.lang.Specification import spock.lang.Unroll +import static org.junit.jupiter.api.Assertions.assertEquals + class UtilsSpec extends Specification { def "The success rate for all specs should be correctly calculated given all results"() { @@ -12,7 +14,7 @@ class UtilsSpec extends Specification { then: "The expected result is obtained" - GroovyTestCase.assertEquals result, expectedSuccessRate, 1E-9 + assertEquals( result, expectedSuccessRate, 1E-9 ) where: total | reproved | expectedSuccessRate From 4d19c63ad6b085d53dce922efd5c054e254fc820 Mon Sep 17 00:00:00 2001 From: Renato Athaydes Date: Sun, 30 Oct 2022 19:38:55 +0100 Subject: [PATCH 2/3] Updates to documentation and release notes. --- README.md | 11 ++++++----- build.gradle | 2 +- releases/Release_Notes.txt | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dfaad60c..7a65395e 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ Version compatibility: | Java | Groovy | Spock | spock-reports | |-------|--------|----------------|-------------------------| -| 17+ | 3.0.9+ | 2.1-groovy-3.0 | 2.3.1-groovy-3.0 | +| 8+ | 4.0+ | 2.3-groovy-4.0 | 2.4.0-groovy-4.0 | +| 17+ | 3.0.9+ | 2.1-groovy-3.0 | 2.3.2-groovy-3.0 | | 11-16 | 3.0+ | 2.0-groovy-3.0 | 2.1.1-groovy-3.0 | | 8+ | 2.5+ | 2.0-groovy-2.5 | 2.0-groovy-2.5 | | 7, 8 | 2.4+ | 1.3+ | 1.8.0 | @@ -64,13 +65,13 @@ Add ``spock-reports`` to your ````: org.slf4j slf4j-api - 1.7.30 + 1.7.36 test org.slf4j slf4j-simple - 1.7.30 + 1.7.36 test ``` @@ -92,8 +93,8 @@ dependencies { transitive = false // this avoids affecting your version of Groovy/Spock } // if you don't already have slf4j-api and an implementation of it in the classpath, add this! - testImplementation 'org.slf4j:slf4j-api:1.7.30' - testRuntimeClasspath 'org.slf4j:slf4j-simple:1.7.30' + testImplementation 'org.slf4j:slf4j-api:1.7.36' + testRuntimeClasspath 'org.slf4j:slf4j-simple:1.7.36' } ``` diff --git a/build.gradle b/build.gradle index aa2dbdee..e6f6deb3 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { defaultTasks 'check' group = 'com.athaydes' -version = "2.4.0-groovy-4" +version = "2.4.0-groovy-4.0" description = 'This project is a global extension for Spock to create test (or, in Spock terms, Specifications) reports.' sourceCompatibility = '1.8' diff --git a/releases/Release_Notes.txt b/releases/Release_Notes.txt index 2153ebb3..0ca37e37 100644 --- a/releases/Release_Notes.txt +++ b/releases/Release_Notes.txt @@ -1,6 +1,10 @@ 2.4.0-groovy-4 - 2022 Oct 30 * Upgrade Groovy version to 4.0.6. +* Minor performance improvements and quieter logging. + +2.3.2-groovy-3.0 - 2022 Oct 30 + * #235 Maintain source code indentation in Vivid report. 2.3.1-groovy-3.0 - 2022 Aug 25 From e6845a4940fa01d4d98ae0ce5e50430aeafb0965 Mon Sep 17 00:00:00 2001 From: Renato Athaydes Date: Mon, 14 Nov 2022 19:02:45 +0100 Subject: [PATCH 3/3] Updated news. --- news.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/news.md b/news.md index 18a9dc95..32902d58 100644 --- a/news.md +++ b/news.md @@ -4,7 +4,13 @@ * `14th of November 2022` -A couple of nice improvements to "vivid" reports (that include source code). +Finally! Groovy 4 support is here!! + +spock-reports version `2.4.0-groovy-4.0` has just been released. +No major changes are included in this release, but it's nice to be able to use the latest and greatest Groovy version. + +On another note: version `2.3.2-groovy-3.0` was just released as well... it includes a couple of nice improvements +to "vivid" reports (reports that include source code). The Groovy 4 version also includes these improvements. * `25th of August 2022`