Skip to content

Commit

Permalink
Add tests for "always collect test results"
Browse files Browse the repository at this point in the history
This is a follow-up for commit b74236d,
which adapted the `buildPlugin` and `buildPluginWithGradle` steps.
  • Loading branch information
darxriggs committed Jan 14, 2020
1 parent b36e6ee commit 55bd877
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
38 changes: 37 additions & 1 deletion src/test/groovy/BuildPluginStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion src/test/groovy/BuildPluginWithGradleStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/test/groovy/mock/Infra.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package mock
class Infra implements Serializable {

private boolean trusted
private boolean buildError

public void checkout(String repo = null) { }

Expand All @@ -23,7 +24,11 @@ class Infra implements Serializable {
}

public Object runWithJava(String command, String jdk = null, List<String> extraEnv = null, Boolean addToolEnv = null) {
return command
if (buildError) {
throw new RuntimeException('build error')
} else {
return command
}
}

public boolean isTrusted() {
Expand Down

0 comments on commit 55bd877

Please sign in to comment.