Skip to content

Commit c0da665

Browse files
author
Alan Christie
committed
- You can now write tests that cause the pipeline to exit
1 parent bfe8393 commit c0da665

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

pipeline.test.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@
118118
stderr: [ 'Computation = 4.5673' ],
119119
stdout: [ 'Result = SUCCESS' ],
120120

121+
// If your test causes the pipeline to exit with a non-zero exit code
122+
// you need to declare this with an `exit_error` block.
123+
// The block defines a string that is expected to be found on stderr.
124+
exit_error: 'Command-line error',
125+
121126
// Input files (optional)
122127
//
123128
// If your pipeline expects input files you can specify any file in

src/groovy/PipelineTester.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import org.apache.commons.cli.Option
3333

3434
// Version
3535
// Update with every change/release
36-
String version = '2.6.0'
36+
String version = '2.6.1'
3737

3838
println "+------------------+"
3939
println "| PipelineTester | v$version"

src/groovy/Tester.groovy

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ class Tester {
794794
def paramsBlock = section.value['params']
795795
def stderrBlock = section.value['stderr']
796796
def stdoutBlock = section.value['stdout']
797+
def exitErrorBlock = section.value['exit_error']
797798
def inputBlock = section.value['input']
798799
def createsBlock = section.value['creates']
799800
def metricsBlock = section.value['metrics']
@@ -923,6 +924,7 @@ class Tester {
923924
StringBuilder sout
924925
StringBuilder serr
925926
int exitValue
927+
boolean expectedExit // If we got a non-zero exit but it was expected
926928
boolean timeout
927929
if (imageName && inDocker) {
928930
Log.info('Docker', 'Yes')
@@ -1057,14 +1059,33 @@ class Tester {
10571059
}
10581060

10591061
} else {
1062+
1063+
expectedExit = false
10601064
if (timeout) {
10611065
Log.err("Execution was terminated" +
1062-
" (taking longer than ${testTimeoutSeconds}S)")
1066+
" (taking longer than ${testTimeoutSeconds}S)")
1067+
} else {
1068+
// Otherwise, was an 'exit_error' defined for this test?
1069+
if (exitErrorBlock != null) {
1070+
String stderrExpr = escapeString(exitErrorBlock)
1071+
def finder = (serr =~ /$stderrExpr/)
1072+
if (finder.count == 0) {
1073+
Log.err("Test failed." +
1074+
" This was expected but did not see '$exitErrorBlock'" +
1075+
" in the command's stderr")
1076+
} else {
1077+
expectedExit = true
1078+
}
1079+
}
1080+
}
1081+
1082+
if (!expectedExit) {
1083+
Log.err("Pipeline exitValue=$exitValue. <stderr> follows...")
10631084
}
1064-
Log.err("Pipeline exitValue=$exitValue. <stderr> follows...")
10651085
}
10661086

1067-
if (exitValue == 0 && validated) {
1087+
if (validated &&
1088+
(exitValue == 0 || (exitValue != 0 && expectedExit) )) {
10681089
testsPassed += 1
10691090
Log.info('Result', 'SUCCESS')
10701091
} else {

0 commit comments

Comments
 (0)