Skip to content

Commit

Permalink
Upgraded to Groovy 4.
Browse files Browse the repository at this point in the history
Various logging and necessary improvements.
  • Loading branch information
renatoathaydes committed Oct 30, 2022
1 parent 413e588 commit c5f5b20
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 41 deletions.
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.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 {
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.
* #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).
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

0 comments on commit c5f5b20

Please sign in to comment.