Skip to content

Commit c837de6

Browse files
committed
Add tests for coverage subcommand
1 parent 72ecb06 commit c837de6

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

Tests/EndToEndTests/GenerateSubcommandTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import class Foundation.Bundle
21
import XCTest
32

43
final class GenerateSubcommandTests: XCTestCase {
54
func testCommonMark() throws {
65
let command = Bundle.productsDirectory.appendingPathComponent("swift-doc")
7-
let outputDirectory = try temporaryDirectory()
86

7+
let outputDirectory = try temporaryDirectory()
98
defer { try? FileManager.default.removeItem(at: outputDirectory) }
9+
1010
try Process.run(command: command,
1111
arguments: [
1212
"generate",

0 commit comments

Comments
 (0)