|
13 | 13 | import Build
|
14 | 14 | import Foundation
|
15 | 15 | import LLBuildManifest
|
16 |
| -@_spi(SwiftPMInternal) |
17 |
| -import SPMTestSupport |
18 | 16 | import TSCBasic
|
19 | 17 | import XCTest
|
| 18 | +@_spi(SwiftPMInternal) |
| 19 | +import SPMTestSupport |
| 20 | +import class Basics.ObservabilitySystem |
| 21 | +@_spi(DontAdoptOutsideOfSwiftPMExposedForBenchmarksAndTestsOnly) |
| 22 | +import func PackageGraph.loadModulesGraph |
| 23 | +import class PackageModel.Manifest |
| 24 | +import struct PackageModel.TargetDescription |
20 | 25 |
|
21 | 26 | class PrepareForIndexTests: XCTestCase {
|
22 | 27 | func testPrepare() throws {
|
@@ -82,4 +87,74 @@ class PrepareForIndexTests: XCTestCase {
|
82 | 87 | let name = lib.getLLBuildTargetName(buildParameters: plan.destinationBuildParameters)
|
83 | 88 | XCTAssertTrue(manifest.targets.keys.contains(name))
|
84 | 89 | }
|
| 90 | + |
| 91 | + // enable-testing requires the non-exportable-decls, make sure they aren't skipped. |
| 92 | + func testEnableTesting() throws { |
| 93 | + let fs = InMemoryFileSystem( |
| 94 | + emptyFiles: |
| 95 | + "/Pkg/Sources/lib/lib.swift", |
| 96 | + "/Pkg/Tests/test/TestCase.swift" |
| 97 | + ) |
| 98 | + |
| 99 | + let observability = ObservabilitySystem.makeForTesting() |
| 100 | + let scope = observability.topScope |
| 101 | + |
| 102 | + let graph = try loadModulesGraph( |
| 103 | + fileSystem: fs, |
| 104 | + manifests: [ |
| 105 | + Manifest.createRootManifest( |
| 106 | + displayName: "Pkg", |
| 107 | + path: "/Pkg", |
| 108 | + targets: [ |
| 109 | + TargetDescription(name: "lib", dependencies: []), |
| 110 | + TargetDescription(name: "test", dependencies: ["lib"], type: .test), |
| 111 | + ] |
| 112 | + ), |
| 113 | + ], |
| 114 | + observabilityScope: scope |
| 115 | + ) |
| 116 | + XCTAssertNoDiagnostics(observability.diagnostics) |
| 117 | + |
| 118 | + // Under debug, enable-testing is turned on by default. Make sure the flag is not added. |
| 119 | + let debugPlan = try BuildPlan( |
| 120 | + destinationBuildParameters: mockBuildParameters(destination: .target, config: .debug, prepareForIndexing: true), |
| 121 | + toolsBuildParameters: mockBuildParameters(destination: .host, prepareForIndexing: false), |
| 122 | + graph: graph, |
| 123 | + fileSystem: fs, |
| 124 | + observabilityScope: observability.topScope |
| 125 | + ) |
| 126 | + let debugBuilder = LLBuildManifestBuilder(debugPlan, fileSystem: fs, observabilityScope: scope) |
| 127 | + let debugManifest = try debugBuilder.generatePrepareManifest(at: "/manifest") |
| 128 | + |
| 129 | + XCTAssertNil(debugManifest.commands.values.first(where: { |
| 130 | + guard let swiftCommand = $0.tool as? SwiftCompilerTool, |
| 131 | + swiftCommand.outputs.contains(where: { $0.name.hasSuffix("/lib.swiftmodule")}) |
| 132 | + else { |
| 133 | + return false |
| 134 | + } |
| 135 | + return swiftCommand.otherArguments.contains("-experimental-skip-non-exportable-decls") |
| 136 | + && !swiftCommand.otherArguments.contains("-enable-testing") |
| 137 | + })) |
| 138 | + |
| 139 | + // Under release, enable-testing is turned off by default so we should see our flag |
| 140 | + let releasePlan = try BuildPlan( |
| 141 | + destinationBuildParameters: mockBuildParameters(destination: .target, config: .release, prepareForIndexing: true), |
| 142 | + toolsBuildParameters: mockBuildParameters(destination: .host, prepareForIndexing: false), |
| 143 | + graph: graph, |
| 144 | + fileSystem: fs, |
| 145 | + observabilityScope: observability.topScope |
| 146 | + ) |
| 147 | + let releaseBuilder = LLBuildManifestBuilder(releasePlan, fileSystem: fs, observabilityScope: scope) |
| 148 | + let releaseManifest = try releaseBuilder.generatePrepareManifest(at: "/manifest") |
| 149 | + |
| 150 | + XCTAssertEqual(releaseManifest.commands.values.filter({ |
| 151 | + guard let swiftCommand = $0.tool as? SwiftCompilerTool, |
| 152 | + swiftCommand.outputs.contains(where: { $0.name.hasSuffix("/lib.swiftmodule")}) |
| 153 | + else { |
| 154 | + return false |
| 155 | + } |
| 156 | + return swiftCommand.otherArguments.contains("-experimental-skip-non-exportable-decls") |
| 157 | + && !swiftCommand.otherArguments.contains("-enable-testing") |
| 158 | + }).count, 1) |
| 159 | + } |
85 | 160 | }
|
0 commit comments