Skip to content
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

Groovy 4 #240

Merged
merged 5 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Version compatibility:

| Java | Groovy | Spock | spock-reports |
|-------|--------|----------------|-------------------------|
| 8+ | 4.0+ | 2.3-groovy-4.0 | <b>2.4.0-groovy-4.0</b> |
| 17+ | 3.0.9+ | 2.1-groovy-3.0 | <b>2.3.2-groovy-3.0</b> |
| 11-16 | 3.0+ | 2.0-groovy-3.0 | <b>2.1.1-groovy-3.0</b> |
| 8+ | 2.5+ | 2.0-groovy-2.5 | <b>2.0-groovy-2.5</b> |
Expand Down Expand Up @@ -64,13 +65,13 @@ Add ``spock-reports`` to your ``<dependencies>``:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
<version>1.7.36</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
<version>1.7.36</version>
<scope>test</scope>
</dependency>
```
Expand All @@ -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'
}
```

Expand Down
24 changes: 12 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion news.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
5 changes: 5 additions & 0 deletions releases/Release_Notes.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -11,26 +13,28 @@ 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(
loadSpockConfig( spockConfig,
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() ) {
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 )
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"() {
Expand All @@ -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
Expand Down