Skip to content

`PackageGraph.computeTestTargetsForExecutableTargets() is incorrectly affected by plugin usage #5841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/PackageGraph/PackageGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ public struct PackageGraph {
// Create map of test target to set of its direct dependencies.
let testTargetDepMap: [ResolvedTarget: Set<ResolvedTarget>] = try {
let testTargetDeps = rootTargets.filter({ $0.type == .test }).map({
($0, Set($0.dependencies.compactMap({ $0.target })))
($0, Set($0.dependencies.compactMap{ $0.target }.filter{ $0.type != .plugin }))
})
return try Dictionary(throwingUniqueKeysWithValues: testTargetDeps)
}()

for target in rootTargets where target.type == .executable {
// Find all dependencies of this target within its package.
// Find all dependencies of this target within its package. Note that we do not traverse plugin usages.
let dependencies = try topologicalSort(target.dependencies, successors: {
$0.dependencies.compactMap { $0.target }.map { .target($0, conditions: []) }
$0.dependencies.compactMap{ $0.target }.filter{ $0.type != .plugin }.map{ .target($0, conditions: []) }
}).compactMap({ $0.target })

// Include the test targets whose dependencies intersect with the
Expand Down
36 changes: 36 additions & 0 deletions Tests/FunctionalTests/PluginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,42 @@ class PluginTests: XCTestCase {
}
}

func testPluginUsageDoesntAffectTestTargetMappings() throws {
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

try fixture(name: "Miscellaneous/Plugins/MySourceGenPlugin") { packageDir in
// Load a workspace from the package.
let observability = ObservabilitySystem.makeForTesting()
let workspace = try Workspace(
fileSystem: localFileSystem,
forRootPackage: packageDir,
customManifestLoader: ManifestLoader(toolchain: UserToolchain.default),
delegate: MockWorkspaceDelegate()
)

// Load the root manifest.
let rootInput = PackageGraphRootInput(packages: [packageDir], dependencies: [])
let rootManifests = try tsc_await {
workspace.loadRootManifests(
packages: rootInput.packages,
observabilityScope: observability.topScope,
completion: $0
)
}
XCTAssert(rootManifests.count == 1, "\(rootManifests)")

// Load the package graph.
let packageGraph = try workspace.loadPackageGraph(rootInput: rootInput, observabilityScope: observability.topScope)
XCTAssertNoDiagnostics(observability.diagnostics)

// Make sure that the use of plugins doesn't bleed into the use of plugins by tools.
let testTargetMappings = try packageGraph.computeTestTargetsForExecutableTargets()
for (target, testTargets) in testTargetMappings {
XCTAssertFalse(testTargets.contains{ $0.name == "MySourceGenPluginTests" }, "target: \(target), testTargets: \(testTargets)")
}
}
}

func testCommandPluginCancellation() throws {
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
Expand Down