Skip to content

Commit 8534fe6

Browse files
committed
Fix @line variables
1 parent 7912e68 commit 8534fe6

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

Sources/FileCheck/FileCheck.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ public func fileCheckOutput(of FD : FileCheckFD = .stdout, withPrefixes prefixes
118118
let buf = contents.cString(using: .utf8)?.withUnsafeBufferPointer { buffer in
119119
return readCheckStrings(in: buffer, withPrefixes: validPrefixes, checkNot: checkNot, options: options, prefixRE)
120120
}
121-
guard let checkStrings = buf else {
121+
guard let checkStrings = buf, !checkStrings.isEmpty else {
122122
return false
123123
}
124+
124125
return check(input: input, against: checkStrings, options: options)
125126
}
126127

Sources/FileCheck/Pattern.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ final class Pattern {
178178
let diagLoc = CheckLoc.inBuffer(pattern.baseAddress!, buf)
179179
for (i, c) in name.characters.enumerated() {
180180
if i == 0 && c == "@" {
181-
if nameEnd == nil {
181+
if nameEnd != nil {
182182
diagnose(.error, at: diagLoc, with: "invalid name in named regex definition", options: options)
183183
return nil
184184
}

Tests/FileCheckTests/FileCheckSpec.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class FileCheckSpec : XCTestCase {
9292

9393
#if !os(macOS)
9494
static var allTests = testCase([
95+
("testWhitespace", testWhitespace),
96+
("testSame", testSame),
9597
("testImplicitCheckNot", testImplicitCheckNot),
9698
])
9799
#endif
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// THIS TEST IS LINE-COUNT DEPENDENT. DO NOT RE-INDENT.
2+
import FileCheck
3+
import XCTest
4+
import Foundation
5+
6+
class LineCountSpec : XCTestCase {
7+
func testLineCount() {
8+
let txt = [
9+
"9",
10+
"10 aaa",
11+
"11 bbb",
12+
"12 ccc",
13+
"13 CHECK-LINECOUNT: [[@LINE-3]] {{a}}aa",
14+
"14 CHECK-LINECOUNT: [[@LINE-3]] {{b}}bb",
15+
"15 CHECK-LINECOUNT: [[@LINE-3]] {{c}}cc",
16+
"16 foobar",
17+
"17 CHECK-LINECOUNT: [[@LINE-1]] {{foo}}bar",
18+
"18",
19+
"19 arst CHECK-LINECOUNT: [[@LINE]] {{a}}rst",
20+
"20",
21+
"21 BAD-CHECK-LINECOUNT: [[@LINE:cant-have-regex]]",
22+
].joined(separator: "\n")
23+
24+
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["CHECK-LINECOUNT"]) {
25+
print(txt)
26+
})
27+
28+
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["BAD-CHECK-LINECOUNT"]) {
29+
print(txt)
30+
})
31+
}
32+
#if !os(macOS)
33+
static var allTests = testCase([
34+
("testLineCount", testLineCount),
35+
])
36+
#endif
37+
}

Tests/LinuxMain.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import XCTest
55
#if !os(macOS)
66
XCTMain([
77
FileCheckSpec.allTests,
8+
LineCountSpec.allTests,
89
])
910
#endif

0 commit comments

Comments
 (0)