forked from mattpolzin/swift-test-codecov
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add JSON option and rework runtime so that you always get the desired…
… output (table, minimum, json) regardless of success or failure
- Loading branch information
1 parent
d01fdc4
commit c0914f1
Showing
5 changed files
with
117 additions
and
39 deletions.
There are no files selected for viewing
Binary file modified
BIN
+16.4 KB
(150%)
...ftpm/xcode/package.xcworkspace/xcuserdata/matt.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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,53 @@ | ||
// | ||
// Aggregate.swift | ||
// | ||
// | ||
// Created by Mathew Polzin on 1/8/21. | ||
// | ||
|
||
import Foundation | ||
|
||
public func isDependencyPath(_ path: String) -> Bool { | ||
return path.contains(".build/") | ||
} | ||
|
||
public struct Aggregate: Encodable { | ||
/// The coverage data per-file. | ||
public let coveragePerFile: [String: CodeCov.File.Coverage] | ||
/// The total number of whatever aggregate property is chosen | ||
/// | ||
/// For example, the number of lines (in total, not with coverage). | ||
public let totalCount: Int | ||
/// Overall coverage -- a number between 0.0 and 1.0 | ||
public let overallCoverage: Double | ||
|
||
/// Overall coverage -- a number between 0.0 and 100.0 | ||
public var overallCoveragePercent: Double { | ||
overallCoverage * 100 | ||
} | ||
|
||
public var formattedOverallCoveragePercent: String { | ||
"\(String(format: "%.2f", overallCoveragePercent))%" | ||
} | ||
|
||
public init( | ||
coverage: CodeCov, | ||
property: CodeCov.AggregateProperty, | ||
includeDependencies: Bool | ||
) { | ||
coveragePerFile = coverage | ||
.fileCoverages(for: property) | ||
.filter { filename, _ in | ||
includeDependencies ? true : !isDependencyPath(filename) | ||
} | ||
|
||
let total = coveragePerFile.reduce(0) { tot, next in | ||
tot + next.value.count | ||
} | ||
totalCount = total | ||
|
||
overallCoverage = coveragePerFile.reduce(0.0) { avg, next in | ||
avg + Double(next.value.covered) / Double(total) | ||
} | ||
} | ||
} |
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