Files
firebase-ios-sdk/Metrics/Sources/MetricsLib/CoverageReport.swift
T
Corrob aef87815bb Create a swift utility for uploading project health metrics from Travis (#2612)
* Create a swift utility for collecting code coverage and uploading to a database

* Update the readme

* Code clean up

* Fix line length

* Change to a still supported commandline kit

* Run swift formatter

* Add copyright

* Move example report under the Tests dir

* Add a TODO for Firestore, Functions, and InAppMessaging

* Change todo name to GitHub name

* Put line breaks in the example report
2019-03-26 10:18:45 -07:00

63 lines
1.7 KiB
Swift

/*
* Copyright 2019 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
/// Represents a code coverage report generated by XCov (maps to the JSON report one to one).
public struct CoverageReport: Decodable {
public var targets: [Target]
public var coverage: Double
public init(targets: [Target], coverage: Double) {
self.targets = targets
self.coverage = coverage
}
/// Creates a CoverageReport from a JSON file generated by XCov.
public static func load(path: String) throws -> CoverageReport {
let data = try Data(contentsOf: NSURL(fileURLWithPath: path) as URL)
let decoder = JSONDecoder()
return try decoder.decode(CoverageReport.self, from: data)
}
}
/// An XCov target.
public struct Target: Decodable {
public var name: String
public var files: [File]
public var coverage: Double
public init(name: String, coverage: Double) {
self.name = name
self.coverage = coverage
files = []
}
}
/// An XCov file.
public struct File: Decodable {
public var name: String
public var coverage: Double
public var type: String
public var functions: [Function]
}
/// An XCov function.
public struct Function: Decodable {
public var name: String
public var coverage: Double
}