Skip to content

Commit ba9195c

Browse files
committed
Add empty input tests
1 parent 900f08f commit ba9195c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Sources/FileCheck/FileCheck.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ public func fileCheckOutput(of FD : FileCheckFD = .stdout, withPrefixes prefixes
105105
}
106106

107107
let input = overrideFDAndCollectOutput(file: FD, of: block)
108-
if (input.isEmpty && !options.contains(.allowEmptyInput)) {
109-
print("FileCheck error: input from file descriptor \(FD) is empty.\n")
110-
return false
108+
if input.isEmpty {
109+
guard options.contains(.allowEmptyInput) else {
110+
print("FileCheck error: input from file descriptor \(FD) is empty.\n")
111+
return false
112+
}
113+
114+
return true
111115
}
112116

113117
guard let contents = try? String(contentsOfFile: file, encoding: .utf8) else {

Tests/FileCheckTests/EmptySpec.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import FileCheck
2+
import XCTest
3+
import Foundation
4+
5+
class EmptySpec : XCTestCase {
6+
// func testEmptyError() {
7+
// XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["EMPTY-ERR"]) {
8+
// // EMPTY-ERR: FileCheck error: input from file descriptor stdout is empty.
9+
// XCTAssertFalse(fileCheckOutput(options: [.disableColors]) {})
10+
// })
11+
// }
12+
13+
func testAllowEmpty() {
14+
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["ALLOW-EMPTY-ERR"], options: [.allowEmptyInput]) {
15+
// ALLOW-EMPTY-ERR-NOT: FileCheck error: input from file descriptor stdout is empty.
16+
XCTAssert(fileCheckOutput(options: [.allowEmptyInput]) {})
17+
})
18+
}
19+
}

0 commit comments

Comments
 (0)