Skip to content

Commit

Permalink
Add more multi-prefix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CodaFi committed Sep 20, 2017
1 parent b5cb540 commit 482e229
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/FileCheck/Pattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ final class Pattern {
patternStr = String(patternStr[patternStr.index(end, offsetBy: 4)...])

// Get the regex name (e.g. "foo").
#if os(macOS)
let nameEnd = matchStr.range(of: ":")
#else
let nameEnd = String(matchStr).range(of: ":")
#endif
let name : String
if let end = nameEnd?.lowerBound {
name = String(matchStr[..<end])
Expand Down
8 changes: 8 additions & 0 deletions Tests/FileCheckTests/DAGSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,12 @@ class DAGSpec : XCTestCase {
].joined(separator: "\n"))
})
}

#if !os(macOS)
static var allTests = testCase([
("testPrefixOrderInvariant", testPrefixOrderInvariant),
("testDAGWithInst", testDAGWithInst),
("testDAGXFailWithInst", testDAGXFailWithInst),
])
#endif
}
7 changes: 7 additions & 0 deletions Tests/FileCheckTests/EmptySpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ class EmptySpec : XCTestCase {
XCTAssert(fileCheckOutput(options: [.allowEmptyInput]) {})
})
}

#if !os(macOS)
static var allTests = testCase([
("testAllowEmpty", testAllowEmpty),
("testEmptyError", testEmptyError),
])
#endif
}
26 changes: 26 additions & 0 deletions Tests/FileCheckTests/FileCheckSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,39 @@ class FileCheckSpec : XCTestCase {
})
}

func testNotDiagInfo() {
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["NOTDIAGINFO-TEXT"]) {
// NOTDIAGINFO-TEXT: error: NOTDIAGINFO-NOT: string occurred!
// NOTDIAGINFO-TEXT-NEXT: test
// NOTDIAGINFO-TEXT-NEXT: note: NOTDIAGINFO-NOT: pattern specified here
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["NOTDIAGINFO"], options: .disableColors) {
// NOTDIAGINFO-NOT: test
print("test")
})
})
}

func testNonExistentPrefix() {
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["CHECK-NONEXISTENT-PREFIX-ERR"]) {
// CHECK-NONEXISTENT-PREFIX-ERR: error: no check strings found with prefixes
// CHECK-NONEXISTENT-PREFIX-ERR-NEXT: CHECK-NONEXISTENT-PREFIX{{:}}
XCTAssertFalse(fileCheckOutput(of: .stdout, withPrefixes: ["CHECK-NONEXISTENT-PREFIX"], options: [.disableColors]) {
// A-DIFFERENT-PREFIX: foobar
print("foobar")
})
})
}

#if !os(macOS)
static var allTests = testCase([
("testWhitespace", testWhitespace),
("testSame", testSame),
("testCheckDAG", testCheckDAG),
("testImplicitCheckNot", testImplicitCheckNot),
("testUndefinedVariablePattern", testUndefinedVariablePattern),
("testNearestPattern", testNearestPattern),
("testNotDiagInfo", testNotDiagInfo),
("testNonExistentPrefix", testNonExistentPrefix),
])
#endif
}
8 changes: 8 additions & 0 deletions Tests/FileCheckTests/LabelSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,12 @@ class LabelSpec : XCTestCase {
print(["bar", "foo", "foo", "zed"].joined(separator: "\n"))
})
}

#if !os(macOS)
static var allTests = testCase([
("testLabels", testLabels),
("testLabelFail", testLabelFail),
("testLabelDAG", testLabelDAG),
])
#endif
}
36 changes: 36 additions & 0 deletions Tests/FileCheckTests/MultiPrefixSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,41 @@ class MultiPrefixSpec : XCTestCase {
})
})
}

func testMultiplePrefix2() {
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["BAZ", "BAZQUUX", "QUUXBAZ"], options: [.disableColors]) {
// BAZ
// BAZQUUX
// BAZQUUX: this is the {{match}}
// QUUXBAZ: this is {{another}}
print("""
this is the match
this is another
""")
})
}

func testMultiplePrefixOverlap() {
XCTAssert(fileCheckOutput(of: .stdout, withPrefixes: ["AAAOVERLAP", "OVERLAP"]) {
// OVERLAP: fo{{o}}
// AAAOVERLAP: ba{{r}}
// OVERLAP: buz{{z}}
print("""
foo
bar
buzz
""")
})
}

#if !os(macOS)
static var allTests = testCase([
("testMultiplePrefixSubstr", testMultiplePrefixSubstr),
("testMultiPrefixMixed", testMultiPrefixMixed),
("testMultiplePrefixNoMatch", testMultiplePrefixNoMatch),
("testMultiplePrefix2", testMultiplePrefix2),
("testMultiplePrefixOverlap", testMultiplePrefixOverlap),
])
#endif
}

4 changes: 4 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import XCTest

#if !os(macOS)
XCTMain([
DAGSpec.allTests,
EmptySpec.allTests,
FileCheckSpec.allTests,
LabelSpec.allTests,
LineCountSpec.allTests,
MultiPrefixSpec.allTests,
])
#endif

0 comments on commit 482e229

Please sign in to comment.