-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from BinaryBirds/dev
- md & junit output format support
- Loading branch information
Showing
55 changed files
with
3,027 additions
and
206 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
install: | ||
release: | ||
swift package update && swift build -c release | ||
install .build/Release/testify-cli /usr/local/bin/testify | ||
|
||
install: release | ||
install .build/Release/testify /usr/local/bin/testify | ||
|
||
uninstall: | ||
rm /usr/local/bin/testify |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
// swift-tools-version:5.5 | ||
// swift-tools-version:5.7 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Testify", | ||
name: "testify", | ||
platforms: [ | ||
.macOS(.v10_15), | ||
], | ||
products: [ | ||
.library(name: "Testify", targets: ["Testify"]), | ||
.executable(name: "testify-cli", targets: ["testify-cli"]) | ||
.executable(name: "testify", targets: ["testify"]), | ||
.library(name: "TestifySDK", targets: ["TestifySDK"]) | ||
], | ||
targets: [ | ||
.executableTarget(name: "testify-cli", dependencies: ["Testify"], path: "./Sources/cli"), | ||
.target(name: "Testify", dependencies: [], path: "./Sources/lib"), | ||
.testTarget(name: "TestifyTests", dependencies: ["Testify"]), | ||
.executableTarget( | ||
name: "testify", | ||
dependencies: [ | ||
.target(name: "TestifySDK") | ||
] | ||
), | ||
|
||
// MARK: - targets | ||
|
||
.target( | ||
name: "TestifySDK", | ||
dependencies: [] | ||
), | ||
|
||
// MARK: - test targets | ||
|
||
.testTarget( | ||
name: "TestifySDKTests", | ||
dependencies: [ | ||
.target(name: "TestifySDK"), | ||
] | ||
), | ||
] | ||
) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// TestResultCodable.swift | ||
// Testify | ||
// | ||
// Created by Tibor Bodecs on 2023. 02. 12.. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum TestResultEncoderError: Error { | ||
case unknown | ||
} | ||
|
||
public enum TestResultDecoderError: Error { | ||
case unknown | ||
} | ||
|
||
public protocol TestResultEncoder { | ||
func encode(_: TestSuite) throws -> String | ||
} | ||
|
||
public protocol TestResultDecoder { | ||
func decode(_: String) throws -> TestSuite | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Tibor Bodecs on 2023. 02. 12.. | ||
// | ||
|
||
import Foundation | ||
|
||
struct TestResultJSONEncoder: TestResultEncoder { | ||
|
||
func encode(_ suite: TestSuite) throws -> String { | ||
let encoder = JSONEncoder() | ||
let data = try encoder.encode(suite) | ||
guard let value = String(data: data, encoding: .utf8) else { | ||
throw TestResultEncoderError.unknown | ||
} | ||
return value | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Lengyel Gábor on 2023. 02. 15.. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct TestResultJunitEncoder: TestResultEncoder { | ||
|
||
public init() { | ||
|
||
} | ||
|
||
public func encode(_ input: TestSuite) throws -> String { | ||
var restOfResult = "" | ||
var allTests = 0 | ||
var allTimes = 0.0 | ||
var allFails = 0 | ||
|
||
let suites: [TestSuite] = input.children.reduce([]) { $0 + $1.children } | ||
for suite in suites { | ||
let start = suite.startDate | ||
let name = suite.name | ||
let tests = suite.cases.count | ||
let time = suite.cases.reduce(0) { $0 + $1.duration } | ||
let failureCount = suite.cases.reduce(0) { $0 + ($1.outcome == .failure ? 1 : 0) } | ||
allTests += tests | ||
allTimes += time | ||
allFails += failureCount | ||
restOfResult += "<testsuite id=\"\(name)\" name=\"\(name)\" tests=\"\(tests)\" skipped=\"0\" failures=\"\(failureCount)\" errors=\"0\" timestamp=\"\(start)\" hostname=\"JunitEncoder\" time=\"\(time)\">\n" | ||
|
||
for testCase in suite.cases { | ||
let name = testCase.testName | ||
let className = testCase.className | ||
let success = testCase.outcome == .success | ||
let time = testCase.duration | ||
let failLine = testCase.failureInfo?.line | ||
let failReason = testCase.failureInfo?.reason | ||
|
||
restOfResult += "<testcase name=\"\(name)\" classname=\"\(className)\" time=\"\(time)\"" | ||
if (success) { | ||
restOfResult += "/>\n" | ||
} else { | ||
if (testCase.failureInfo != nil) { | ||
restOfResult += ">\n" | ||
restOfResult += "<failure message=\"\(failLine ?? -1)\" type=\"type\">\n" | ||
restOfResult += "\(failReason ?? "")\n" | ||
restOfResult += "</failure>\n" | ||
restOfResult += "</testcase>\n" | ||
} else { | ||
restOfResult += "/>\n" | ||
} | ||
} | ||
} | ||
restOfResult += "</testsuite>\n" | ||
} | ||
restOfResult += "</testsuites>\n" | ||
|
||
let formatter = DateFormatter() | ||
formatter.dateFormat = "yyyyMMdd_HHmmss" | ||
var startResult = "\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
startResult += "<testsuites id=\"\(formatter.string(from: input.startDate))\" name=\"\(input.name)\" tests=\"\(allTests)\" failures=\"\(allFails)\" time=\"\(allTimes)\">\n" | ||
|
||
return startResult + restOfResult | ||
} | ||
} |
Oops, something went wrong.