@@ -1584,13 +1584,44 @@ class ConvertActionTests: XCTestCase {
1584
1584
}
1585
1585
}
1586
1586
1587
+ /// An empty implementation of `ConvertOutputConsumer` that purposefully does nothing except
1588
+ /// to pass the number of documentation coverage info structs received to the given handler
1589
+ struct TestDocumentationCoverageConsumer : ConvertOutputConsumer {
1590
+
1591
+ let coverageConsumeHandler : ( Int ) -> Void
1592
+
1593
+ init ( coverageConsumeHandler: @escaping ( Int ) -> Void ) {
1594
+ self . coverageConsumeHandler = coverageConsumeHandler
1595
+ }
1596
+
1597
+ func consume( renderNode: RenderNode ) throws { }
1598
+ func consume( problems: [ Problem ] ) throws { }
1599
+ func consume( assetsInBundle bundle: DocumentationBundle ) throws { }
1600
+ func consume( linkableElementSummaries: [ LinkDestinationSummary ] ) throws { }
1601
+ func consume( indexingRecords: [ IndexingRecord ] ) throws { }
1602
+ func consume( assets: [ RenderReferenceType : [ RenderReference ] ] ) throws { }
1603
+ func consume( benchmarks: Benchmark ) throws { }
1604
+
1605
+ // Call the handler with the number of coverage items consumed here
1606
+ func consume( documentationCoverageInfo: [ CoverageDataEntry ] ) throws {
1607
+ coverageConsumeHandler ( documentationCoverageInfo. count)
1608
+ }
1609
+ }
1610
+
1587
1611
func testMetadataIsOnlyWrittenToOutputFolderWhenDocumentationCoverage( ) throws {
1588
1612
1589
- // An empty documentation bundle
1613
+ // An empty documentation bundle, except for a single symbol graph file
1614
+ // containing 8 symbols.
1590
1615
let bundle = Folder ( name: " unit-test.docc " , content: [
1591
1616
InfoPlist ( displayName: " TestBundle " , identifier: " com.test.example " ) ,
1617
+ CopyOfFile ( original: symbolGraphFile, newName: " MyKit.symbols.json " ) ,
1592
1618
] )
1593
1619
1620
+ // Count the number of coverage info structs consumed by each test below,
1621
+ // using TestDocumentationCoverageConsumer and this handler.
1622
+ var coverageInfoCount = 0
1623
+ let coverageInfoHandler = { count in coverageInfoCount += count }
1624
+
1594
1625
// Check that they're nothing is written for `.noCoverage`
1595
1626
do {
1596
1627
let testDataProvider = try TestFileSystem ( folders: [ bundle, Folder . emptyHTMLTemplateDirectory] )
@@ -1612,6 +1643,10 @@ class ConvertActionTests: XCTestCase {
1612
1643
let result = try action. perform ( logHandle: . standardOutput)
1613
1644
1614
1645
XCTAssertFalse ( testDataProvider. fileExists ( atPath: result. outputs [ 0 ] . appendingPathComponent ( " documentation-coverage.json " ) . path) )
1646
+
1647
+ // Rerun the convert and test no coverage info structs were consumed
1648
+ let _ = try action. converter. convert ( outputConsumer: TestDocumentationCoverageConsumer ( coverageConsumeHandler: coverageInfoHandler) )
1649
+ XCTAssertEqual ( coverageInfoCount, 0 )
1615
1650
}
1616
1651
1617
1652
// Check that JSON is written for `.brief`
@@ -1635,6 +1670,11 @@ class ConvertActionTests: XCTestCase {
1635
1670
let result = try action. perform ( logHandle: . standardOutput)
1636
1671
1637
1672
XCTAssertTrue ( testDataProvider. fileExists ( atPath: result. outputs [ 0 ] . appendingPathComponent ( " documentation-coverage.json " ) . path) )
1673
+
1674
+ // Rerun the convert and test one coverage info structs was consumed for each symbol page (8)
1675
+ coverageInfoCount = 0
1676
+ let _ = try action. converter. convert ( outputConsumer: TestDocumentationCoverageConsumer ( coverageConsumeHandler: coverageInfoHandler) )
1677
+ XCTAssertEqual ( coverageInfoCount, 8 )
1638
1678
}
1639
1679
1640
1680
// Check that JSON is written for `.detailed`
@@ -1658,6 +1698,11 @@ class ConvertActionTests: XCTestCase {
1658
1698
let result = try action. perform ( logHandle: . standardOutput)
1659
1699
1660
1700
XCTAssertTrue ( testDataProvider. fileExists ( atPath: result. outputs [ 0 ] . appendingPathComponent ( " documentation-coverage.json " ) . path) )
1701
+
1702
+ // Rerun the convert and test one coverage info structs was consumed for each symbol page (8)
1703
+ coverageInfoCount = 0
1704
+ let _ = try action. converter. convert ( outputConsumer: TestDocumentationCoverageConsumer ( coverageConsumeHandler: coverageInfoHandler) )
1705
+ XCTAssertEqual ( coverageInfoCount, 8 )
1661
1706
}
1662
1707
}
1663
1708
0 commit comments