Skip to content

Commit ac2c0f0

Browse files
committed
add integration test that uses extended types
1 parent 7d922f2 commit ac2c0f0

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

IntegrationTests/Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ let package = Package(
3030
.copy("Fixtures/MixedTargets"),
3131
.copy("Fixtures/TargetWithDocCCatalog"),
3232
.copy("Fixtures/PackageWithSnippets"),
33+
.copy("Fixtures/LibraryTargetWithExtensionSymbols"),
3334
]
3435
),
3536
]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// swift-tools-version: 5.6
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
10+
11+
import Foundation
12+
import PackageDescription
13+
14+
let package = Package(
15+
name: "LibraryTargetWithExtensionSymbols",
16+
targets: [
17+
.target(name: "Library"),
18+
]
19+
)
20+
21+
// We only expect 'swift-docc-plugin' to be a sibling when this package
22+
// is running as part of a test.
23+
//
24+
// This allows the package to compile outside of tests for easier
25+
// test development.
26+
if FileManager.default.fileExists(atPath: "../swift-docc-plugin") {
27+
package.dependencies += [
28+
.package(path: "../swift-docc-plugin"),
29+
]
30+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See https://swift.org/LICENSE.txt for license information
7+
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
/// This is foo's documentation.
10+
///
11+
/// Foo is a public struct and should be included in documentation.
12+
public struct Foo {
13+
public func foo() {}
14+
}
15+
16+
/// This is the documentation for ``Swift/Array``.
17+
///
18+
/// This is the extension to ``Array`` with the longest documentation
19+
/// comment, thus it is used for doucmenting the extended type in this
20+
/// target.
21+
extension Array {
22+
/// This is the documentation for the ``isArray`` property
23+
/// we added to ``Swift/Array``.
24+
///
25+
/// This is a public extension to an external type and should be included
26+
/// in the documentation.
27+
public var isArray: Bool { true }
28+
}
29+
30+
/// This is the documentation for ``Swift/Int``.
31+
///
32+
/// This is the extension to ``Int`` with the longest documentation
33+
/// comment, thus it is used for doucmenting the extended type in this
34+
/// target.
35+
extension Int {
36+
/// This is the documentation for the ``isArray`` property
37+
/// we added to ``Swift/Int``.
38+
///
39+
/// This is a public extension to an external type and should be included
40+
/// in the documentation.
41+
public var isArray: Bool { false }
42+
}
43+
44+
45+
/// This is the documentation for ``CustomFooConvertible``.
46+
///
47+
/// This is a public protocol and should be included in the documentation.
48+
public protocol CustomFooConvertible {
49+
/// This is the documentation for ``CustomFooConvertible/asFoo``.
50+
///
51+
/// This is a public protocol requirement and should be included in the documentation.
52+
var asFoo: Foo { get }
53+
}
54+
55+
/// This is not used as the documentation comment for ``Swift/Int``
56+
/// as it is shorter than the comment on the other extension to `Int`.
57+
extension Int: CustomFooConvertible {
58+
/// This is the documentation for ``Swift/Int/asFoo``.
59+
///
60+
/// This is a public protocol requirement implementation and should be included in the documentation.
61+
public var asFoo: Foo { Foo() }
62+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See https://swift.org/LICENSE.txt for license information
7+
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
import Foundation
10+
import XCTest
11+
12+
final class TargetWithSwiftExtensionsTests: ConcurrencyRequiringTestCase {
13+
#if swift(>=5.8)
14+
let supportsIncludingSwiftExtendedTypes = true
15+
#else
16+
let supportsIncludingSwiftExtendedTypes = false
17+
#endif
18+
19+
override func setUpWithError() throws {
20+
try XCTSkipUnless(
21+
supportsIncludingSwiftExtendedTypes,
22+
"The current toolchain does not support symbol graph generation for extended types."
23+
)
24+
25+
try super.setUpWithError()
26+
}
27+
28+
func testGenerateDocumentationWithoutEnablementFlag() throws {
29+
let result = try swiftPackage(
30+
"generate-documentation",
31+
workingDirectory: try setupTemporaryDirectoryForFixture(named: "LibraryTargetWithExtensionSymbols")
32+
)
33+
34+
result.assertExitStatusEquals(0)
35+
XCTAssertEqual(result.referencedDocCArchives.count, 1)
36+
37+
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
38+
39+
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
40+
41+
XCTAssertEqual(
42+
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
43+
[
44+
"documentation/library.json",
45+
46+
"library/foo.json",
47+
"foo/foo().json",
48+
49+
"library/customfooconvertible.json",
50+
"customfooconvertible/asfoo.json",
51+
]
52+
)
53+
}
54+
55+
func testGenerateDocumentationWithEnablementFlag() throws {
56+
let result = try swiftPackage(
57+
"generate-documentation",
58+
"--include-extended-types",
59+
workingDirectory: try setupTemporaryDirectoryForFixture(named: "LibraryTargetWithExtensionSymbols")
60+
)
61+
62+
result.assertExitStatusEquals(0)
63+
XCTAssertEqual(result.referencedDocCArchives.count, 1)
64+
65+
let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first)
66+
67+
let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL)
68+
69+
XCTAssertEqual(
70+
Set(dataDirectoryContents.map(\.lastTwoPathComponents)),
71+
[
72+
"documentation/library.json",
73+
"library/swift.json",
74+
75+
"swift/int.json",
76+
"int/isarray.json",
77+
"int/asfoo.json",
78+
"int/customfooconvertible-implementations.json",
79+
80+
"swift/array.json",
81+
"array/isarray.json",
82+
83+
"library/foo.json",
84+
"foo/foo().json",
85+
86+
"library/customfooconvertible.json",
87+
"customfooconvertible/asfoo.json",
88+
]
89+
)
90+
}
91+
}

0 commit comments

Comments
 (0)