CoverageReport.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. /// Represents a code coverage report generated by XCov (maps to the JSON report one to one).
  18. public struct CoverageReport: Decodable {
  19. public var targets: [Target]
  20. public var coverage: Double
  21. public init(targets: [Target], coverage: Double) {
  22. self.targets = targets
  23. self.coverage = coverage
  24. }
  25. /// Creates a CoverageReport from a JSON file generated by XCov.
  26. public static func load(path: String) throws -> CoverageReport {
  27. let data = try Data(contentsOf: NSURL(fileURLWithPath: path) as URL)
  28. let decoder = JSONDecoder()
  29. return try decoder.decode(CoverageReport.self, from: data)
  30. }
  31. }
  32. /// An XCov target.
  33. public struct Target: Decodable {
  34. public var name: String
  35. public var files: [File]
  36. public var coverage: Double
  37. public init(name: String, coverage: Double) {
  38. self.name = name
  39. self.coverage = coverage
  40. files = []
  41. }
  42. }
  43. /// An XCov file.
  44. public struct File: Decodable {
  45. public var name: String
  46. public var coverage: Double
  47. public var type: String
  48. public var functions: [Function]
  49. }
  50. /// An XCov function.
  51. public struct Function: Decodable {
  52. public var name: String
  53. public var coverage: Double
  54. }