jenkins-spock
jenkins-spock copied to clipboard
Cannot call methods in a script with an invalid name from other methods in that same script
Expected Behavior
Given a script with an invalid JVM name, like some-script.groovy
, and contents with multiple methods:
def one() {}
def two() {
one()
}
return this
I would expect to be able to call method two()
during a test, like this:
setup:
def script = loadPipelineScriptForTest( "some-script.groovy ")
when:
script.two()
then:
// some expectation
Actual Behavior
The fact that some-script.groovy
is compiled to a class file whose name is not valid to a JVM is a problem. Branch https://github.com/ExpediaGroup/jenkins-spock/tree/invalid-name-internal adds a unit test; the output is
[ERROR] can run methods in helper scripts whose names create invalid JVM class names from other methods in those scripts(com.homeaway.devtools.jenkins.testing.scripts.InvalidClassNameSpec) Time elapsed: 0.043 s <<< ERROR!
java.lang.ClassFormatError: Illegal class name "some-helper-script$internal_method" in class file some-helper-script$internal_method
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at some-helper-script.composed_method(some-helper-script.groovy:27)
at com.homeaway.devtools.jenkins.testing.InvalidlyNamedScriptWrapper.invokeMethod(InvalidlyNamedScriptWrapper.groovy:68)
at com.homeaway.devtools.jenkins.testing.scripts.InvalidClassNameSpec.can run methods in helper scripts whose names create invalid JVM class names from other methods in those scripts(InvalidClassNameSpec.groovy:96)
Steps to Reproduce
See the unit tests added in branch https://github.com/ExpediaGroup/jenkins-spock/tree/invalid-name-internal
Additional Information
This may just mean that the "invalid class name" handling needs to be improved.
This may be symptomatic of the script-loading mechanism being used incorrectly and may warrant looking into alternate implementations for this snippet: https://github.com/ExpediaGroup/jenkins-spock/blob/c864e4e2db15e8dca665b55c5e7a483bd00e19fa/src/main/groovy/com/homeaway/devtools/jenkins/testing/JenkinsPipelineSpecification.groovy#L886-L911
We should investigate and if it can be solved with the Wrapper, make sure that N & N+1 layers of nesting are solved, too.