forked from jenkinsci/JenkinsPipelineUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jenkinsci#8 from lesfurets/feature_global_lib
Test scripts with Pipeline Shared Libraries
- Loading branch information
Showing
50 changed files
with
1,201 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/groovy/com/lesfurets/jenkins/unit/InterceptingGCL.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.lesfurets.jenkins.unit | ||
|
||
import org.codehaus.groovy.control.CompilationFailedException | ||
import org.codehaus.groovy.control.CompilerConfiguration | ||
|
||
class InterceptingGCL extends GroovyClassLoader { | ||
|
||
PipelineTestHelper helper | ||
|
||
InterceptingGCL(PipelineTestHelper helper, | ||
ClassLoader loader, | ||
CompilerConfiguration config) { | ||
super(loader, config) | ||
this.helper = helper | ||
} | ||
|
||
@Override | ||
Class parseClass(GroovyCodeSource codeSource, boolean shouldCacheSource) | ||
throws CompilationFailedException { | ||
Class clazz = super.parseClass(codeSource, shouldCacheSource) | ||
clazz.metaClass.invokeMethod = helper.getMethodInterceptor() | ||
clazz.metaClass.static.invokeMethod = helper.getMethodInterceptor() | ||
clazz.metaClass.methodMissing = helper.getMethodMissingInterceptor() | ||
return clazz | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 3 additions & 27 deletions
30
src/main/groovy/com/lesfurets/jenkins/unit/MockPipelineScript.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,8 @@ | ||
package com.lesfurets.jenkins.unit | ||
|
||
/** | ||
* This class seems useless now | ||
*/ | ||
abstract class MockPipelineScript extends Script { | ||
|
||
def methodMissing(String name, args) { | ||
if (this._TEST_HELPER.isMethodAllowed(name, args)) { | ||
def result = null | ||
if (args != null) { | ||
for (argument in args) { | ||
result = callIfClosure(argument, result) | ||
if (argument instanceof Map) { | ||
argument.each { k, v -> | ||
result = callIfClosure(k, result) | ||
result = callIfClosure(v, result) | ||
} | ||
} | ||
} | ||
} | ||
return result | ||
} else { | ||
throw new MissingMethodException(name, this.class, args) | ||
} | ||
} | ||
|
||
def callIfClosure(Object closure, Object currentResult) { | ||
if (closure instanceof Closure) { | ||
currentResult = closure.call() | ||
} | ||
return currentResult | ||
} | ||
|
||
} |
Oops, something went wrong.