Skip to content

Commit

Permalink
Update Readme and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex da Franca committed Jun 7, 2024
1 parent e406cff commit 24285e7
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,20 @@ You should see the tool respond like this:
```
Error: Missing expected argument '<xcresult-file>'
OVERVIEW: xcresultparser 1.6.0
OVERVIEW: xcresultparser 1.6.1
Interpret binary .xcresult files and print summary in different formats: txt,
xml, html or colored cli output.
USAGE: xcresultparser [--output-format <output-format>] [--project-root <project-root>] [--coverage-targets <coverage-targets> ...] [--summary-fields <summary-fields>] [--coverage ...] [--no-test-result ...] [--failed-tests-only ...] [--quiet ...] [--target-info ...] [--version ...] [<xcresult-file>]
USAGE: xcresultparser [--coverage-report-format <coverage-report-format>] [--output-format <output-format>] [--project-root <project-root>] [--coverage-targets <coverage-targets> ...] [--summary-fields <summary-fields>] [--coverage ...] [--no-test-result ...] [--failed-tests-only ...] [--quiet ...] [--target-info ...] [--version ...] [<xcresult-file>]
ARGUMENTS:
<xcresult-file> The path to the .xcresult file.
OPTIONS:
--coverage-report-format <coverage-report-format>
The coverage report format. The Default is 'methods',
It can either be 'totals', 'targets', 'classes' or
'methods'
-o, --output-format <output-format>
The output format. It can be either 'txt', 'cli',
'html', 'md', 'xml', 'junit', 'cobertura',
Expand Down
97 changes: 97 additions & 0 deletions Tests/XcresultparserTests/XcresultparserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,74 @@ final class XcresultparserTests: XCTestCase {
XCTAssertTrue(resultParser.coverageDetails.starts(with: "Coverage report"))
XCTAssertEqual("", resultParser.documentSuffix)
}

func testTextResultFormatterTotalCoverageReportFormat() throws {
let xcresultFile = Bundle.module.url(forResource: "test", withExtension: "xcresult")!

guard let resultParser = XCResultFormatter(
with: xcresultFile,
formatter: TextResultFormatter(),
coverageTargets: [],
coverageReportFormat: .totals
) else {
XCTFail("Unable to create XCResultFormatter with \(xcresultFile)")
return
}
XCTAssertEqual("", resultParser.documentPrefix(title: "XCResults"))

let expectedSummary = """
Summary
Number of errors = 0
Number of warnings = 3
Number of analyzer warnings = 0
Number of tests = 7
Number of failed tests = 1
Number of skipped tests = 0
"""
XCTAssertEqual(expectedSummary, resultParser.summary)
XCTAssertEqual("---------------------\n", resultParser.divider)
XCTAssertTrue(resultParser.testDetails.starts(with: "Test Scheme Action"))

let lines = resultParser.coverageDetails.components(separatedBy: "\n")
XCTAssertEqual(2, lines.count)
XCTAssertEqual("Coverage report", lines.first)
XCTAssertTrue(lines.last?.starts(with: "Total coverage:") == true)
}

func testTextResultFormatterMethodsCoverageReportFormat() throws {
let xcresultFile = Bundle.module.url(forResource: "test", withExtension: "xcresult")!

guard let resultParser = XCResultFormatter(
with: xcresultFile,
formatter: TextResultFormatter(),
coverageTargets: [],
coverageReportFormat: .methods
) else {
XCTFail("Unable to create XCResultFormatter with \(xcresultFile)")
return
}
XCTAssertEqual("", resultParser.documentPrefix(title: "XCResults"))

let expectedSummary = """
Summary
Number of errors = 0
Number of warnings = 3
Number of analyzer warnings = 0
Number of tests = 7
Number of failed tests = 1
Number of skipped tests = 0
"""
XCTAssertEqual(expectedSummary, resultParser.summary)
XCTAssertEqual("---------------------\n", resultParser.divider)
XCTAssertTrue(resultParser.testDetails.starts(with: "Test Scheme Action"))

let lines = resultParser.coverageDetails.components(separatedBy: "\n")
XCTAssertEqual(473, lines.count)
XCTAssertEqual("Coverage report", lines.first)
XCTAssertTrue(lines[1].starts(with: "Total coverage:") == true)
XCTAssertTrue(lines[2].starts(with: "XcresultparserLib:") == true)
XCTAssertTrue(lines[3].contains("CLIResultFormatter.swift:") == true)
}

func testCLIResultFormatter() throws {
let xcresultFile = Bundle.module.url(forResource: "test", withExtension: "xcresult")!
Expand Down Expand Up @@ -258,6 +326,35 @@ final class XcresultparserTests: XCTestCase {
sut = OutputFormat(string: "xyz")
XCTAssertEqual(OutputFormat.cli, sut)
}

func testCoverageReportFormat() {
var sut = CoverageReportFormat(string: "methods")
XCTAssertEqual(CoverageReportFormat.methods, sut)

sut = CoverageReportFormat(string: "classes")
XCTAssertEqual(CoverageReportFormat.classes, sut)

sut = CoverageReportFormat(string: "targets")
XCTAssertEqual(CoverageReportFormat.targets, sut)

sut = CoverageReportFormat(string: "totals")
XCTAssertEqual(CoverageReportFormat.totals, sut)

sut = CoverageReportFormat(string: "not existing")
XCTAssertEqual(CoverageReportFormat.methods, sut)

sut = CoverageReportFormat(string: "")
XCTAssertEqual(CoverageReportFormat.methods, sut)

sut = CoverageReportFormat(string: "Classes")
XCTAssertEqual(CoverageReportFormat.classes, sut)

sut = CoverageReportFormat(string: "CLASSES")
XCTAssertEqual(CoverageReportFormat.classes, sut)

sut = CoverageReportFormat(string: "clASSeS")
XCTAssertEqual(CoverageReportFormat.classes, sut)
}

// MARK: helper functions

Expand Down

0 comments on commit 24285e7

Please sign in to comment.