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

fix: Make AWS SDK CLI test runner fail when tests fail #1049

Merged
merged 3 commits into from
Jun 22, 2023
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 @@ -6,6 +6,7 @@
//

import Foundation
import ArgumentParser

extension Process {
/// Creates a process using `/usr/bin/env` as the executable
Expand Down Expand Up @@ -73,6 +74,10 @@ struct ProcessRunner {
log("Running process: \(process.commandString)")
try process.run()
process.waitUntilExit()
let exitCode = ExitCode(process.terminationStatus)
if !exitCode.isSuccess {
throw exitCode
}
}

#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

@testable import AWSSDKSwiftCLI
import PackageDescription
import ArgumentParser
import XCTest

class ProcessUtilsTests: XCTestCase {

func test_exit_itThrowsErrorWithErrorCode() {
let process = Process("false") // this refers to /usr/bin/false which always returns unsuccessfully
do {
try ProcessRunner.standard.run(process)
XCTFail("Process runner should have thrown")
} catch let exitCodeError as ExitCode {
XCTAssertTrue(exitCodeError.rawValue != 0)
} catch {
XCTFail("Process runner threw an unexpected type of error")
}
}
}