Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle default return correctly when returnStatus is used #267

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,9 @@ class PipelineTestHelper {

MockScriptOutput output = mockScriptOutputs[script]
if (!output) {
if (returnStatus) {
return 0
}
// If no output is given, we return these strings for backwards-compatibility. Ideally at some point in the
// future, we should make a breaking change and remove this special use-case and either raise an exception
// here or return an empty string.
Expand Down Expand Up @@ -680,6 +683,7 @@ class PipelineTestHelper {
if (exitValue != 0) {
throw new Exception('Script returned error code: ' + exitValue)
}
return null
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ class PipelineTestHelperTest {
Assertions.assertThat(output).isEqualTo('\nbbb\nccc\n')
}

@Test()
void runShWithoutMockOutputAndReturnStatus() throws Exception {
// given:
def helper = new PipelineTestHelper()

// when:
def output = helper.runSh(returnStatus: true, script: 'unregistered-mock-output')

// then:
Assertions.assertThat(output).isEqualTo(0)
}

@Test()
void runShWithoutMockOutputForGitRevParse() throws Exception {
// given:
Expand Down