|
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2022 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception
|
7 | 7 | //
|
8 | 8 | // See http://swift.org/LICENSE.txt for license information
|
@@ -40,4 +40,80 @@ class GitRepositoryProviderTests: XCTestCase {
|
40 | 40 | XCTAssertThrowsError(try provider.isValidDirectory(notGitChildPath))
|
41 | 41 | }
|
42 | 42 | }
|
| 43 | + |
| 44 | + func testIsValidDirectoryThrowsPrintableError() throws { |
| 45 | + try testWithTemporaryDirectory { temp in |
| 46 | + let provider = GitRepositoryProvider() |
| 47 | + let expectedErrorMessage = "not a git repository" |
| 48 | + XCTAssertThrowsError(try provider.isValidDirectory(temp)) { error in |
| 49 | + let errorString = String(describing: error) |
| 50 | + XCTAssertTrue( |
| 51 | + errorString.contains(expectedErrorMessage), |
| 52 | + "Error string '\(errorString)' should contain '\(expectedErrorMessage)'" |
| 53 | + ) |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + func testGitShellErrorIsPrintable() throws { |
| 59 | + let stdOut = "An error from Git - stdout" |
| 60 | + let stdErr = "An error from Git - stderr" |
| 61 | + let arguments = ["git", "error"] |
| 62 | + let command = "git error" |
| 63 | + let result = AsyncProcessResult( |
| 64 | + arguments: arguments, |
| 65 | + environment: [:], |
| 66 | + exitStatus: .terminated(code: 1), |
| 67 | + output: .success(Array(stdOut.utf8)), |
| 68 | + stderrOutput: .success(Array(stdErr.utf8)) |
| 69 | + ) |
| 70 | + let error = GitShellError(result: result) |
| 71 | + let errorString = "\(error)" |
| 72 | + XCTAssertTrue( |
| 73 | + errorString.contains(stdOut), |
| 74 | + "Error string '\(errorString)' should contain '\(stdOut)'" |
| 75 | + ) |
| 76 | + XCTAssertTrue( |
| 77 | + errorString.contains(stdErr), |
| 78 | + "Error string '\(errorString)' should contain '\(stdErr)'" |
| 79 | + ) |
| 80 | + XCTAssertTrue( |
| 81 | + errorString.contains(command), |
| 82 | + "Error string '\(errorString)' should contain '\(command)'" |
| 83 | + ) |
| 84 | + } |
| 85 | + |
| 86 | + func testGitShellErrorEmptyStdOut() throws { |
| 87 | + let stdErr = "An error from Git - stderr" |
| 88 | + let result = AsyncProcessResult( |
| 89 | + arguments: ["git", "error"], |
| 90 | + environment: [:], |
| 91 | + exitStatus: .terminated(code: 1), |
| 92 | + output: .success([]), |
| 93 | + stderrOutput: .success(Array(stdErr.utf8)) |
| 94 | + ) |
| 95 | + let error = GitShellError(result: result) |
| 96 | + let errorString = "\(error)" |
| 97 | + XCTAssertTrue( |
| 98 | + errorString.contains(stdErr), |
| 99 | + "Error string '\(errorString)' should contain '\(stdErr)'" |
| 100 | + ) |
| 101 | + } |
| 102 | + |
| 103 | + func testGitShellErrorEmptyStdErr() throws { |
| 104 | + let stdOut = "An error from Git - stdout" |
| 105 | + let result = AsyncProcessResult( |
| 106 | + arguments: ["git", "error"], |
| 107 | + environment: [:], |
| 108 | + exitStatus: .terminated(code: 1), |
| 109 | + output: .success(Array(stdOut.utf8)), |
| 110 | + stderrOutput: .success([]) |
| 111 | + ) |
| 112 | + let error = GitShellError(result: result) |
| 113 | + let errorString = "\(error)" |
| 114 | + XCTAssertTrue( |
| 115 | + errorString.contains(stdOut), |
| 116 | + "Error string '\(errorString)' should contain '\(stdOut)'" |
| 117 | + ) |
| 118 | + } |
43 | 119 | }
|
0 commit comments