diff --git a/README.md b/README.md index 7be451d..7a65395 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Version compatibility: | Java | Groovy | Spock | spock-reports | |-------|--------|----------------|-------------------------| +| 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 | @@ -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 89e7037..e6f6deb 100644 --- a/build.gradle +++ b/build.gradle @@ -9,34 +9,34 @@ plugins { defaultTasks 'check' group = 'com.athaydes' -version = "2.3.2-groovy-3.0" +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' 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/news.md b/news.md index 18a9dc9..32902d5 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` diff --git a/releases/Release_Notes.txt b/releases/Release_Notes.txt index 29adf11..0d0d61f 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. +* Minor performance improvements and quieter logging. + 2.3.2-groovy-3.0 - 2022 Nov 14 * #235 fixed indentation of source code in vivid reports. diff --git a/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy b/src/main/groovy/com/athaydes/spockframework/report/SpockReportExtension.groovy index f34dd2e..b95adfb 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 abd9a5a..596e209 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 d935ea4..66d7670 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 089156d..e32d9eb 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 cf65cec..c772a59 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 89b833b..54831fe 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 e68c9a3..7c33b8f 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