diff --git a/src/test/groovy/BuildPluginStepTests.groovy b/src/test/groovy/BuildPluginStepTests.groovy index 4bd8c6188..317ad3659 100644 --- a/src/test/groovy/BuildPluginStepTests.groovy +++ b/src/test/groovy/BuildPluginStepTests.groovy @@ -219,13 +219,30 @@ class BuildPluginStepTests extends BasePipelineTest { def script = loadScript(scriptName) script.call(tests: [skip: true]) printCallStack() - // then the junit step is disabled + // the junit step is disabled assertFalse(helper.callStack.any { call -> call.methodName == 'junit' }) assertJobStatusSuccess() } + @Test + void test_buildPlugin_with_build_error() throws Exception { + def script = loadScript(scriptName) + binding.setProperty('infra', new Infra(buildError: true)) + try { + script.call([:]) + } catch (ignored) { + // intentionally left empty + } + printCallStack() + // it runs the junit step + assertTrue(helper.callStack.any { call -> + call.methodName == 'junit' + }) + assertJobStatusFailure() + } + @Test void test_buildPlugin_with_defaults_with_gradle() throws Exception { def script = loadScript(scriptName) @@ -241,6 +258,25 @@ class BuildPluginStepTests extends BasePipelineTest { }) } + @Test + void test_buildPlugin_with_build_error_with_gradle() throws Exception { + def script = loadScript(scriptName) + binding.setProperty('infra', new Infra(buildError: true)) + // when running in a non maven project + helper.registerAllowedMethod('fileExists', [String.class], { s -> return !s.equals('pom.xml') }) + try { + script.call([:]) + } catch (ignored) { + // intentionally left empty + } + printCallStack() + // it runs the junit step + assertTrue(helper.callStack.any { call -> + call.methodName == 'junit' + }) + assertJobStatusFailure() + } + @Test void test_buildPlugin_with_failfast_and_unstable() throws Exception { def script = loadScript(scriptName) diff --git a/src/test/groovy/BuildPluginWithGradleStepTests.groovy b/src/test/groovy/BuildPluginWithGradleStepTests.groovy index 22a342fa6..736ab5dec 100644 --- a/src/test/groovy/BuildPluginWithGradleStepTests.groovy +++ b/src/test/groovy/BuildPluginWithGradleStepTests.groovy @@ -91,13 +91,30 @@ class BuildPluginWithGradleStepTests extends BasePipelineTest { def script = loadScript(scriptName) script.call(tests: [skip: true]) printCallStack() - // then the junit step is disabled + // the junit step is disabled assertFalse(helper.callStack.any { call -> call.methodName == 'junit' }) assertJobStatusSuccess() } + @Test + void test_buildPluginWithGradle_with_build_error() throws Exception { + def script = loadScript(scriptName) + binding.setProperty('infra', new Infra(buildError: true)) + try { + script.call([:]) + } catch (ignored) { + // intentionally left empty + } + printCallStack() + // it runs the junit step + assertTrue(helper.callStack.any { call -> + call.methodName == 'junit' + }) + assertJobStatusFailure() + } + @Test void test_buildPluginWithGradle_with_failfast_and_unstable() throws Exception { def script = loadScript(scriptName) diff --git a/src/test/groovy/mock/Infra.groovy b/src/test/groovy/mock/Infra.groovy index 854161471..34ef6b136 100644 --- a/src/test/groovy/mock/Infra.groovy +++ b/src/test/groovy/mock/Infra.groovy @@ -6,6 +6,7 @@ package mock class Infra implements Serializable { private boolean trusted + private boolean buildError public void checkout(String repo = null) { } @@ -23,7 +24,11 @@ class Infra implements Serializable { } public Object runWithJava(String command, String jdk = null, List extraEnv = null, Boolean addToolEnv = null) { - return command + if (buildError) { + throw new RuntimeException('build error') + } else { + return command + } } public boolean isTrusted() {