diff --git a/IntegrationTests/Package.swift b/IntegrationTests/Package.swift index 05b73b3..e72f1af 100644 --- a/IntegrationTests/Package.swift +++ b/IntegrationTests/Package.swift @@ -30,6 +30,7 @@ let package = Package( .copy("Fixtures/MixedTargets"), .copy("Fixtures/TargetWithDocCCatalog"), .copy("Fixtures/PackageWithSnippets"), + .copy("Fixtures/LibraryTargetWithExtensionSymbols"), ] ), ] diff --git a/IntegrationTests/Tests/Fixtures/LibraryTargetWithExtensionSymbols/Package.swift b/IntegrationTests/Tests/Fixtures/LibraryTargetWithExtensionSymbols/Package.swift new file mode 100644 index 0000000..a3efff1 --- /dev/null +++ b/IntegrationTests/Tests/Fixtures/LibraryTargetWithExtensionSymbols/Package.swift @@ -0,0 +1,30 @@ +// swift-tools-version: 5.6 +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for Swift project authors + +import Foundation +import PackageDescription + +let package = Package( + name: "LibraryTargetWithExtensionSymbols", + targets: [ + .target(name: "Library"), + ] +) + +// We only expect 'swift-docc-plugin' to be a sibling when this package +// is running as part of a test. +// +// This allows the package to compile outside of tests for easier +// test development. +if FileManager.default.fileExists(atPath: "../swift-docc-plugin") { + package.dependencies += [ + .package(path: "../swift-docc-plugin"), + ] +} diff --git a/IntegrationTests/Tests/Fixtures/LibraryTargetWithExtensionSymbols/Sources/Library/Library.swift b/IntegrationTests/Tests/Fixtures/LibraryTargetWithExtensionSymbols/Sources/Library/Library.swift new file mode 100644 index 0000000..e900fc8 --- /dev/null +++ b/IntegrationTests/Tests/Fixtures/LibraryTargetWithExtensionSymbols/Sources/Library/Library.swift @@ -0,0 +1,22 @@ +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for Swift project authors + +/// This is foo's documentation. +/// +/// Foo is a public struct and should be included in documentation. +public struct Foo { + public func foo() {} +} + +extension Array { + public var isArray: Bool { true } +} + +extension Int { + public var isArray: Bool { false } +} diff --git a/IntegrationTests/Tests/TargetWithSwiftExtensionsTests.swift b/IntegrationTests/Tests/TargetWithSwiftExtensionsTests.swift new file mode 100644 index 0000000..59e6f3b --- /dev/null +++ b/IntegrationTests/Tests/TargetWithSwiftExtensionsTests.swift @@ -0,0 +1,83 @@ +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2022 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for Swift project authors + +import Foundation +import XCTest + +final class TargetWithSwiftExtensionsTests: ConcurrencyRequiringTestCase { +#if swift(>=5.8) + let supportsIncludingSwiftExtendedTypes = true +#else + let supportsIncludingSwiftExtendedTypes = false +#endif + + override func setUpWithError() throws { + try XCTSkipUnless( + supportsIncludingSwiftExtendedTypes, + "The current toolchain does not support symbol graph generation for extended types." + ) + + try super.setUpWithError() + } + + func testGenerateDocumentationWithoutEnablementFlag() throws { + let result = try swiftPackage( + "generate-documentation", + workingDirectory: try setupTemporaryDirectoryForFixture(named: "LibraryTargetWithExtensionSymbols") + ) + + result.assertExitStatusEquals(0) + XCTAssertEqual(result.referencedDocCArchives.count, 1) + + let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first) + + let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL) + + XCTAssertEqual( + Set(dataDirectoryContents.map(\.lastTwoPathComponents)), + [ + "documentation/library.json", + + "library/foo.json", + "foo/foo().json", + ] + ) + } + + func testGenerateDocumentationWithEnablementFlag() throws { + let result = try swiftPackage( + "generate-documentation", + "--include-extended-types", + workingDirectory: try setupTemporaryDirectoryForFixture(named: "LibraryTargetWithExtensionSymbols") + ) + + result.assertExitStatusEquals(0) + XCTAssertEqual(result.referencedDocCArchives.count, 1) + + let doccArchiveURL = try XCTUnwrap(result.referencedDocCArchives.first) + + let dataDirectoryContents = try filesIn(.dataSubdirectory, of: doccArchiveURL) + + XCTAssertEqual( + Set(dataDirectoryContents.map(\.lastTwoPathComponents)), + [ + "documentation/library.json", + "library/swift.json", + + "swift/int.json", + "int/isarray.json", + + "swift/array.json", + "array/isarray.json", + + "library/foo.json", + "foo/foo().json", + ] + ) + } +}