Last active
May 20, 2021 18:36
-
-
Save yawillianpsb/8773ff01cb1f9390d5a03d54de27a508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
guard CommandLine.argc > 0 else { exit(-1) } | |
let schemes = CommandLine.arguments | |
.first { $0.starts(with: "schemes_") }? | |
.dropFirst(8) | |
.split(separator: ",") ?? [] | |
let junitUrls = schemes | |
.compactMap { URL(string: "file://"+FileManager.default.currentDirectoryPath+"/tests/\($0)_report/report.junit") } | |
var allTests = 0 | |
var allFailures = 0 | |
var failedSchemes: [String: Int] = [:] | |
class ParserDelegate: NSObject, XMLParserDelegate { | |
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String: String] = [:]) { | |
guard elementName == "testsuite", | |
let name = attributeDict["name"], | |
let failures = attributeDict["failures"], | |
let tests = attributeDict["tests"], | |
let failuresInt = Int(failures), | |
let testsInt = Int(tests) | |
else { return } | |
allTests += testsInt | |
allFailures += failuresInt | |
if failuresInt > 0, | |
let targetName = name.split(separator: ".").map(String.init).first { | |
let count = failedSchemes.contains { $0.key == targetName } | |
? failedSchemes[targetName]! + failuresInt | |
: failuresInt | |
failedSchemes[targetName] = count | |
} | |
} | |
} | |
for (url) in junitUrls { | |
let delegate = ParserDelegate() | |
let p = XMLParser(contentsOf: url) | |
p?.delegate = delegate | |
p?.parse() | |
} | |
let failedInSchemes = failedSchemes.map({ "\($0.key): \($0.value)" }).joined(separator: ", ") | |
var testsDone = allFailures == 0 | |
? "💹 Все тесты прошли успешно." | |
+ "\n♻️ Всего тестов: \(allTests)" | |
: "❗ Тесты завершены с ошибками." | |
+ "\n❗ Ошибки в схемах \(failedInSchemes)." | |
+ "\n❗ Всего: \(allTests)" | |
+ "\n❗ Провалено: \(allFailures)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment