|
| 1 | +import XCTest |
| 2 | + |
| 3 | +final class CoverageSubcommandTests: XCTestCase { |
| 4 | + func testStandardOutput() throws { |
| 5 | + let command = Bundle.productsDirectory.appendingPathComponent("swift-doc") |
| 6 | + |
| 7 | + let outputDirectory = try temporaryDirectory() |
| 8 | + defer { try? FileManager.default.removeItem(at: outputDirectory) } |
| 9 | + |
| 10 | + try Process.run(command: command, |
| 11 | + arguments: [ |
| 12 | + "coverage", |
| 13 | + "Sources" |
| 14 | + ] |
| 15 | + ) { result in |
| 16 | + XCTAssertEqual(result.terminationStatus, EXIT_SUCCESS) |
| 17 | + XCTAssertEqual(result.output?.starts(with: "Total"), true) |
| 18 | + XCTAssertEqual(result.error, "") |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + func testFileOutput() throws { |
| 23 | + let command = Bundle.productsDirectory.appendingPathComponent("swift-doc") |
| 24 | + |
| 25 | + let outputDirectory = try temporaryDirectory() |
| 26 | + let outputFile = outputDirectory.appendingPathComponent("report.json") |
| 27 | + defer { try? FileManager.default.removeItem(at: outputDirectory) } |
| 28 | + |
| 29 | + try Process.run(command: command, |
| 30 | + arguments: [ |
| 31 | + "coverage", |
| 32 | + "--output", outputFile.path, |
| 33 | + "Sources" |
| 34 | + ] |
| 35 | + ) { result in |
| 36 | + XCTAssertEqual(result.terminationStatus, EXIT_SUCCESS) |
| 37 | + XCTAssertEqual(result.output, "") |
| 38 | + XCTAssertEqual(result.error, "") |
| 39 | + |
| 40 | + do { |
| 41 | + let data = try Data(contentsOf: outputFile) |
| 42 | + let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] |
| 43 | + XCTAssertEqual(json?["type"] as? String, "org.dcov.report.json.export") |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments