Skip to content

Commit

Permalink
fix: Make AWS SDK CLI test runner fail when tests fail (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Jun 22, 2023
1 parent da209be commit bfe12d8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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")
}
}
}

0 comments on commit bfe12d8

Please sign in to comment.