Skip to content

Commit bcf40f5

Browse files
committed
Fix labelling indexing
1 parent 73c2430 commit bcf40f5

File tree

5 files changed

+105
-83
lines changed

5 files changed

+105
-83
lines changed

Sources/FileCheck/CheckString.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct CheckString {
8080
// Match itself from the last position after matching CHECK-DAG.
8181
let matchBuffer = buffer.substring(from: buffer.index(buffer.startIndex, offsetBy: lastPos))
8282
guard let (range, mutVariableTable) = self.pattern.match(matchBuffer, initialTable) else {
83-
diagnoseFailedCheck(initialTable, options, buffer)
83+
diagnoseFailedCheck(variableTable, options, buffer)
8484
return nil
8585
}
8686
let (matchPos, matchLen) = (range.location, range.length)
@@ -344,7 +344,7 @@ struct CheckString {
344344
)
345345
}
346346
} else {
347-
if let varDef = variableTable[varName] {
347+
if let varDef = self.pattern.variableDefs[varName] {
348348
diagnose(.note,
349349
at: self.loc,
350350
with: "with variable '\(varName)' equal to '\(varDef)'",

Sources/FileCheck/FileCheck.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ private func check(input b : String, against checkStrings : [CheckString], optio
475475

476476
// Scan to next CHECK-LABEL match, ignoring CHECK-NOT and CHECK-DAG
477477
guard let (range, mutVariableTable) = checkStr.check(buffer, true, variableTable, options) else {
478-
// Immediately bail of CHECK-LABEL fails, nothing else we can do.
478+
// Immediately bail if CHECK-LABEL fails, nothing else we can do.
479479
return false
480480
}
481481

@@ -492,7 +492,7 @@ private func check(input b : String, against checkStrings : [CheckString], optio
492492
// of any final CHECK-LABEL (to verify CHECK-NOT and CHECK-DAG)
493493
guard let (range, mutVarTable) = checkStrings[i].check(checkRegion, false, variableTable, options) else {
494494
failedChecks = true
495-
i = j
495+
i = j-1
496496
break
497497
}
498498
variableTable = mutVarTable

Sources/FileCheck/Pattern.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ final class Pattern {
336336
}
337337

338338
// Match the newly constructed regex.
339-
guard let r = try? NSRegularExpression(pattern: regExToMatch, options: []) else {
339+
guard let r = try? NSRegularExpression(pattern: regExToMatch, options: [.anchorsMatchLines]) else {
340340
return nil
341341
}
342342
let matchInfo = r.matches(in: buffer, options: [], range: NSRange(location: 0, length: buffer.utf8.count))

Tests/FileCheckTests/DAGSpec.swift

Lines changed: 58 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,36 @@ class DAGSpec : XCTestCase {
2929
// CHECK-INSTDAG-DAG: add [[REG2:r[0-9]+]], r3, r4
3030
// CHECK-INSTDAG-NOT: xor
3131
// CHECK-INSTDAG-DAG: mul r5, [[REG1]], [[REG2]]
32-
print("""
33-
add r10, r1, r2
34-
add r11, r3, r4
35-
mul r5, r10, r11
36-
37-
mul r11, r3, r4
38-
mul r10, r1, r2
39-
add r5, r10, r11
40-
41-
add r11, r3, r4
42-
add r10, r1, r2
43-
mul r5, r10, r11
44-
""")
32+
print([
33+
"add r10, r1, r2",
34+
"add r11, r3, r4",
35+
"mul r5, r10, r11",
36+
"",
37+
"mul r11, r3, r4",
38+
"mul r10, r1, r2",
39+
"add r5, r10, r11",
40+
"",
41+
"add r11, r3, r4",
42+
"add r10, r1, r2",
43+
"mul r5, r10, r11",
44+
].joined(separator: "\n"))
4545
})
4646
}
4747

48-
#if swift(>=4)
4948
func testDAGXFailWithInst() {
5049
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["INSTDAG-XFAIL1"]) {
5150
// INSTDAG-XFAIL1: __x1
5251
// INSTDAG-XFAIL1-DAG: add [[REG1:r[0-9]+]], r1, r2
5352
// INSTDAG-XFAIL1-DAG: add [[REG2:r[0-9]+]], r3, r4
5453
// INSTDAG-XFAIL1: mul r5, [[REG1]], [[REG2]]
5554
// INSTDAG-XFAIL1: __x1
56-
print("""
57-
__x1
58-
add r10, r1, r2
59-
add r11, r3, r4
60-
mul r5, r10, r12
61-
__x1
62-
""")
55+
print([
56+
"__x1",
57+
"add r10, r1, r2",
58+
"add r11, r3, r4",
59+
"mul r5, r10, r12",
60+
"__x1",
61+
].joined(separator: "\n"))
6362
})
6463

6564
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["INSTDAG-XFAIL2"]) {
@@ -68,13 +67,13 @@ class DAGSpec : XCTestCase {
6867
// INSTDAG-XFAIL2-DAG: mul [[REG2:r[0-9]+]], r3, r4
6968
// INSTDAG-XFAIL2: add r5, [[REG1]], [[REG2]]
7069
// INSTDAG-XFAIL2: __x2
71-
print("""
72-
__x2
73-
mul r11, r3, r4
74-
mul r10, r1, r2
75-
add r5, r11, r11
76-
__x2
77-
""")
70+
print([
71+
"__x2",
72+
"mul r11, r3, r4",
73+
"mul r10, r1, r2",
74+
"add r5, r11, r11",
75+
"__x2",
76+
].joined(separator: "\n"))
7877
})
7978

8079
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["INSTDAG-XFAIL3"]) {
@@ -83,13 +82,13 @@ class DAGSpec : XCTestCase {
8382
// INSTDAG-XFAIL3-DAG: add [[REG2:r[0-9]+]], r3, r4
8483
// INSTDAG-XFAIL3-DAG: mul r5, [[REG1]], [[REG2]]
8584
// INSTDAG-XFAIL3: __x3
86-
print("""
87-
__x3
88-
add r11, r3, r4
89-
add r12, r1, r2
90-
mul r5, r10, r11
91-
__x3
92-
""")
85+
print([
86+
"__x3",
87+
"add r11, r3, r4",
88+
"add r12, r1, r2",
89+
"mul r5, r10, r11",
90+
"__x3",
91+
].joined(separator: "\n"))
9392
})
9493

9594
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["INSTDAG-XFAIL4"]) {
@@ -99,14 +98,14 @@ class DAGSpec : XCTestCase {
9998
// INSTDAG-XFAIL4-NOT: not
10099
// INSTDAG-XFAIL4-DAG: mul r5, [[REG1]], [[REG2]]
101100
// INSTDAG-XFAIL4: __x4
102-
print("""
103-
__x4
104-
add r11, r3, r4
105-
add r12, r1, r2
106-
not
107-
mul r5, r12, r11
108-
__x4
109-
""")
101+
print([
102+
"__x4",
103+
"add r11, r3, r4",
104+
"add r12, r1, r2",
105+
"not",
106+
"mul r5, r12, r11",
107+
"__x4",
108+
].joined(separator: "\n"))
110109
})
111110

112111
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["INSTDAG-XFAIL5"]) {
@@ -116,14 +115,14 @@ class DAGSpec : XCTestCase {
116115
// INSTDAG-XFAIL5-NOT: not
117116
// INSTDAG-XFAIL5-DAG: mul r5, [[REG1]], [[REG2]]
118117
// INSTDAG-XFAIL5: __x5
119-
print("""
120-
__x5
121-
mul r5, r12, r11
122-
add r11, r3, r4
123-
add r12, r1, r2
124-
not
125-
__x5
126-
""")
118+
print([
119+
"__x5",
120+
"mul r5, r12, r11",
121+
"add r11, r3, r4",
122+
"add r12, r1, r2",
123+
"not",
124+
"__x5",
125+
].joined(separator: "\n"))
127126
})
128127

129128
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["INSTDAG-XFAIL6"]) {
@@ -134,15 +133,14 @@ class DAGSpec : XCTestCase {
134133
// INSTDAG-XFAIL6-DAG: mul r5, [[REG1]], [[REG2]]
135134
// INSTDAG-XFAIL6-DAG: mul r6, [[REG1]], [[REG2]]
136135
// INSTDAG-XFAIL6: __x6
137-
print("""
138-
__x6
139-
add r11, r3, r4
140-
mul r6, r12, r11
141-
add r12, r1, r2
142-
mul r5, r12, r11
143-
__x6
144-
""")
136+
print([
137+
"__x6",
138+
"add r11, r3, r4",
139+
"mul r6, r12, r11",
140+
"add r12, r1, r2",
141+
"mul r5, r12, r11",
142+
"__x6",
143+
].joined(separator: "\n"))
145144
})
146145
}
147-
#endif
148146
}

Tests/FileCheckTests/LabelSpec.swift

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ import FileCheck
22
import XCTest
33
import Foundation
44

5-
#if swift(>=4)
65
class LabelSpec : XCTestCase {
6+
let output = {
7+
print([
8+
"label0:",
9+
"a",
10+
"b",
11+
"",
12+
"label1:",
13+
"b",
14+
"c",
15+
"",
16+
"label2:",
17+
"a",
18+
"c",
19+
].joined(separator: "\n"))
20+
}
21+
722
func testLabels() {
8-
let output = {
9-
print("""
10-
label0:
11-
a
12-
b
13-
14-
label1:
15-
b
16-
c
17-
18-
label2:
19-
a
20-
c
21-
""")
22-
}
2323
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["CHECKOK"]) {
2424
// CHECKOK-LABEL: {{^}}label0:
2525
// CHECKOK: {{^}}a
@@ -34,8 +34,32 @@ class LabelSpec : XCTestCase {
3434
// CHECKOK: {{^}}c
3535
output()
3636
})
37+
}
3738

38-
39+
func labelFail() {
40+
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["CHECKERROR"]) {
41+
// CHECKERROR: error: CHECKFAIL: could not find a match for regex '(^)c' in input
42+
//
43+
// CHECKERROR: error: CHECKFAIL: could not find a match for regex '(^)a' in input
44+
//
45+
// CHECKERROR: error: CHECKFAIL: could not find a match for regex '(^)b' in input
46+
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["CHECKFAIL"], options: [.disableColors]) {
47+
// CHECKFAIL-LABEL: {{^}}label0:
48+
// CHECKFAIL: {{^}}a
49+
// CHECKFAIL: {{^}}b
50+
// CHECKFAIL: {{^}}c
51+
//
52+
// CHECKFAIL-LABEL: {{^}}label1:
53+
// CHECKFAIL: {{^}}a
54+
// CHECKFAIL: {{^}}b
55+
// CHECKFAIL: {{^}}c
56+
//
57+
// CHECKFAIL-LABEL: {{^}}label2:
58+
// CHECKFAIL: {{^}}a
59+
// CHECKFAIL: {{^}}b
60+
// CHECKFAIL: {{^}}c
61+
output()
62+
})
63+
})
3964
}
4065
}
41-
#endif

0 commit comments

Comments
 (0)