Skip to content

Commit 482e229

Browse files
committed
Add more multi-prefix tests
1 parent b5cb540 commit 482e229

File tree

7 files changed

+93
-0
lines changed

7 files changed

+93
-0
lines changed

Sources/FileCheck/Pattern.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ final class Pattern {
162162
patternStr = String(patternStr[patternStr.index(end, offsetBy: 4)...])
163163

164164
// Get the regex name (e.g. "foo").
165+
#if os(macOS)
165166
let nameEnd = matchStr.range(of: ":")
167+
#else
168+
let nameEnd = String(matchStr).range(of: ":")
169+
#endif
166170
let name : String
167171
if let end = nameEnd?.lowerBound {
168172
name = String(matchStr[..<end])

Tests/FileCheckTests/DAGSpec.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,12 @@ class DAGSpec : XCTestCase {
143143
].joined(separator: "\n"))
144144
})
145145
}
146+
147+
#if !os(macOS)
148+
static var allTests = testCase([
149+
("testPrefixOrderInvariant", testPrefixOrderInvariant),
150+
("testDAGWithInst", testDAGWithInst),
151+
("testDAGXFailWithInst", testDAGXFailWithInst),
152+
])
153+
#endif
146154
}

Tests/FileCheckTests/EmptySpec.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,11 @@ class EmptySpec : XCTestCase {
1616
XCTAssert(fileCheckOutput(options: [.allowEmptyInput]) {})
1717
})
1818
}
19+
20+
#if !os(macOS)
21+
static var allTests = testCase([
22+
("testAllowEmpty", testAllowEmpty),
23+
("testEmptyError", testEmptyError),
24+
])
25+
#endif
1926
}

Tests/FileCheckTests/FileCheckSpec.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,39 @@ class FileCheckSpec : XCTestCase {
140140
})
141141
}
142142

143+
func testNotDiagInfo() {
144+
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["NOTDIAGINFO-TEXT"]) {
145+
// NOTDIAGINFO-TEXT: error: NOTDIAGINFO-NOT: string occurred!
146+
// NOTDIAGINFO-TEXT-NEXT: test
147+
// NOTDIAGINFO-TEXT-NEXT: note: NOTDIAGINFO-NOT: pattern specified here
148+
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["NOTDIAGINFO"], options: .disableColors) {
149+
// NOTDIAGINFO-NOT: test
150+
print("test")
151+
})
152+
})
153+
}
154+
155+
func testNonExistentPrefix() {
156+
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["CHECK-NONEXISTENT-PREFIX-ERR"]) {
157+
// CHECK-NONEXISTENT-PREFIX-ERR: error: no check strings found with prefixes
158+
// CHECK-NONEXISTENT-PREFIX-ERR-NEXT: CHECK-NONEXISTENT-PREFIX{{:}}
159+
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["CHECK-NONEXISTENT-PREFIX"], options: [.disableColors]) {
160+
// A-DIFFERENT-PREFIX: foobar
161+
print("foobar")
162+
})
163+
})
164+
}
165+
143166
#if !os(macOS)
144167
static var allTests = testCase([
145168
("testWhitespace", testWhitespace),
146169
("testSame", testSame),
170+
("testCheckDAG", testCheckDAG),
147171
("testImplicitCheckNot", testImplicitCheckNot),
148172
("testUndefinedVariablePattern", testUndefinedVariablePattern),
149173
("testNearestPattern", testNearestPattern),
174+
("testNotDiagInfo", testNotDiagInfo),
175+
("testNonExistentPrefix", testNonExistentPrefix),
150176
])
151177
#endif
152178
}

Tests/FileCheckTests/LabelSpec.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,12 @@ class LabelSpec : XCTestCase {
8282
print(["bar", "foo", "foo", "zed"].joined(separator: "\n"))
8383
})
8484
}
85+
86+
#if !os(macOS)
87+
static var allTests = testCase([
88+
("testLabels", testLabels),
89+
("testLabelFail", testLabelFail),
90+
("testLabelDAG", testLabelDAG),
91+
])
92+
#endif
8593
}

Tests/FileCheckTests/MultiPrefixSpec.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,41 @@ class MultiPrefixSpec : XCTestCase {
5252
})
5353
})
5454
}
55+
56+
func testMultiplePrefix2() {
57+
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["BAZ", "BAZQUUX", "QUUXBAZ"], options: [.disableColors]) {
58+
// BAZ
59+
// BAZQUUX
60+
// BAZQUUX: this is the {{match}}
61+
// QUUXBAZ: this is {{another}}
62+
print("""
63+
this is the match
64+
this is another
65+
""")
66+
})
67+
}
68+
69+
func testMultiplePrefixOverlap() {
70+
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["AAAOVERLAP", "OVERLAP"]) {
71+
// OVERLAP: fo{{o}}
72+
// AAAOVERLAP: ba{{r}}
73+
// OVERLAP: buz{{z}}
74+
print("""
75+
foo
76+
bar
77+
buzz
78+
""")
79+
})
80+
}
81+
82+
#if !os(macOS)
83+
static var allTests = testCase([
84+
("testMultiplePrefixSubstr", testMultiplePrefixSubstr),
85+
("testMultiPrefixMixed", testMultiPrefixMixed),
86+
("testMultiplePrefixNoMatch", testMultiplePrefixNoMatch),
87+
("testMultiplePrefix2", testMultiplePrefix2),
88+
("testMultiplePrefixOverlap", testMultiplePrefixOverlap),
89+
])
90+
#endif
5591
}
5692

Tests/LinuxMain.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import XCTest
44

55
#if !os(macOS)
66
XCTMain([
7+
DAGSpec.allTests,
8+
EmptySpec.allTests,
79
FileCheckSpec.allTests,
10+
LabelSpec.allTests,
811
LineCountSpec.allTests,
12+
MultiPrefixSpec.allTests,
913
])
1014
#endif

0 commit comments

Comments
 (0)