Updated JUnit reporter (#4725)
This commit is contained in:
parent
500f143c7d
commit
651b00eb70
|
@ -73,6 +73,10 @@
|
|||
[SimplyDanny](https://github.com/SimplyDanny)
|
||||
[#4121](https://github.com/realm/SwiftLint/issues/4121)
|
||||
|
||||
* Updated JUnit reporter to output error count and warning count.
|
||||
[patricks](https://github.com/patricks)
|
||||
[#4725](https://github.com/realm/SwiftLint/pull/4725)
|
||||
|
||||
## 0.50.3: Bundle of Towels
|
||||
|
||||
#### Breaking
|
||||
|
|
|
@ -10,17 +10,30 @@ public struct JUnitReporter: Reporter {
|
|||
}
|
||||
|
||||
public static func generateReport(_ violations: [StyleViolation]) -> String {
|
||||
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<testsuites><testsuite>" +
|
||||
violations.map({ violation -> String in
|
||||
let fileName = (violation.location.file ?? "<nopath>").escapedForXML()
|
||||
let severity = violation.severity.rawValue + ":\n"
|
||||
let message = severity + "Line:" + String(violation.location.line ?? 0) + " "
|
||||
let reason = violation.reason.escapedForXML()
|
||||
let warningCount = violations.filter({ $0.severity == .warning }).count
|
||||
let errorCount = violations.filter({ $0.severity == .error }).count
|
||||
|
||||
return [
|
||||
"\n\t<testcase classname='Formatting Test' name='\(fileName)\'>\n",
|
||||
"<failure message='\(reason)\'>" + message + "</failure>",
|
||||
"\t</testcase>"
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
|
||||
"<testsuites failures=\"\(warningCount)\" errors=\"\(errorCount)\">\n",
|
||||
"\t<testsuite failures=\"\(warningCount)\" errors=\"\(errorCount)\">",
|
||||
violations.map({ testCase(for: $0) }).joined(),
|
||||
"\n\t</testsuite>\n",
|
||||
"</testsuites>"
|
||||
].joined()
|
||||
}
|
||||
|
||||
private static func testCase(for violation: StyleViolation) -> String {
|
||||
let fileName = (violation.location.file ?? "<nopath>").escapedForXML()
|
||||
let reason = violation.reason.escapedForXML()
|
||||
let severity = violation.severity.rawValue.capitalized
|
||||
let lineNumber = String(violation.location.line ?? 0)
|
||||
let message = severity + ":" + "Line:" + lineNumber
|
||||
|
||||
return [
|
||||
"\n\t\t<testcase classname='Formatting Test' name='\(fileName)\'>",
|
||||
"\n\t\t\t<failure message='\(reason)\'>" + message + "</failure>",
|
||||
"\n\t\t</testcase>"
|
||||
].joined()
|
||||
}).joined() + "\n</testsuite></testsuites>"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<testsuites><testsuite>
|
||||
<testsuites failures="1" errors="3">
|
||||
<testsuite failures="1" errors="3">
|
||||
<testcase classname='Formatting Test' name='filename'>
|
||||
<failure message='Violation Reason'>warning:
|
||||
Line:1 </failure> </testcase>
|
||||
<failure message='Violation Reason'>Warning:Line:1</failure>
|
||||
</testcase>
|
||||
<testcase classname='Formatting Test' name='filename'>
|
||||
<failure message='Violation Reason'>error:
|
||||
Line:1 </failure> </testcase>
|
||||
<failure message='Violation Reason'>Error:Line:1</failure>
|
||||
</testcase>
|
||||
<testcase classname='Formatting Test' name='filename'>
|
||||
<failure message='Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>'>error:
|
||||
Line:1 </failure> </testcase>
|
||||
<failure message='Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>'>Error:Line:1</failure>
|
||||
</testcase>
|
||||
<testcase classname='Formatting Test' name='<nopath>'>
|
||||
<failure message='Colons should be next to the identifier when specifying a type and next to the key in dictionary literals'>error:
|
||||
Line:0 </failure> </testcase>
|
||||
</testsuite></testsuites>
|
||||
<failure message='Colons should be next to the identifier when specifying a type and next to the key in dictionary literals'>Error:Line:0</failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuites>
|
Loading…
Reference in New Issue