Skip to content

Commit

Permalink
Fail tests if a test file fails to be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdeem committed Jan 21, 2023
1 parent bb770dc commit e7f13a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Tests/ScreamURITemplateTests/TestFileTests.swift
Expand Up @@ -80,7 +80,10 @@ class TestFileTests: XCTestCase {
return fileTestSuite
}

let testGroups = parseTestFile(URL: testURL)
guard let testGroups = parseTestFile(URL: testURL) else {
fileTestSuite.addTest(TestFileTests(selector: #selector(TestFileTests.testFileParseFailed)))
return fileTestSuite
}
for group in testGroups {
let groupTestSuite = XCTestSuite(name: "Group: \(group.name)")
for test in group.testcases {
Expand Down
4 changes: 2 additions & 2 deletions Tests/ScreamURITemplateTests/TestModels.swift
Expand Up @@ -135,11 +135,11 @@ extension TestCase {
}
}

public func parseTestFile(URL: URL) -> [TestGroup] {
public func parseTestFile(URL: URL) -> [TestGroup]? {
guard let testData = try? Data(contentsOf: URL),
let testCollection = try? JSONDecoder().decode(TestFile.self, from: testData) else {
print("Failed to decode test file \(URL)")
return []
return nil
}

return testCollection.map { testGroupName, testGroupData in
Expand Down

0 comments on commit e7f13a2

Please sign in to comment.