Skip to content
Open
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
26 changes: 26 additions & 0 deletions Fixtures/TestTargetDependOnTestTarget/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// swift-tools-version: 6.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "TestTargetDependOnTestTarget",
targets: [
.testTarget(
name: "leafTestTarget",
),
.testTarget(
name: "myTestTarget",
dependencies: [
"leafTestTarget",
],
),
.testTarget(
name: "myOtherTestTarget",
dependencies: [
"leafTestTarget",
"myTestTarget",
],
),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Testing

@Suite
struct LeafTestTargetTests {
@Test("LeafTestTarget tests")
func example() {
#expect(42 == 17 + 25)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Testing

@Suite
struct MyOTherTestTargetTests {
@Test("MyOTherTestTarget tests")
func example() {
#expect(42 == 17 + 25)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Testing

@Suite
struct MyTestTargetTests {
@Test("MyTestTarget tests")
func example() {
#expect(42 == 17 + 25)
}
}
10 changes: 10 additions & 0 deletions Sources/SwiftBuildSupport/PIFBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public final class PIFBuilder {
throw PIFGenerationError.printedPIFManifestGraphviz
}

if self.observabilityScope.errorsReported {
throw PIFGenerationError.errorDiagnosticsReported
}

return PIFGenerationResult(pif: pifString, accompanyingMetadata: modulesAndProducts)
}

Expand Down Expand Up @@ -814,6 +818,9 @@ public enum PIFGenerationError: Error {

/// Early build termination when using `--print-pif-manifest-graph`.
case printedPIFManifestGraphviz

/// One or more error diagnostics were reported during PIF generation.
case errorDiagnosticsReported
}

extension PIFGenerationError: CustomStringConvertible {
Expand All @@ -832,6 +839,9 @@ extension PIFGenerationError: CustomStringConvertible {

case .printedPIFManifestGraphviz:
"Printed PIF manifest as graphviz"

case .errorDiagnosticsReported:
"Errors reported during PIF building"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@ extension PackagePIFProjectBuilder {
}

case .library, .systemModule, .test:
if moduleDependency.type == .test && product.type == .test {
log(
.error,
"Test target '\(product.name)' cannot depend on another test target '\(moduleDependency.name)'",
)
}
let shouldLinkProduct = moduleDependency.type != .systemModule
let dependencyGUID = moduleDependency.pifTargetGUID
self.project[keyPath: mainModuleTargetKeyPath].common.addDependency(
Expand Down
17 changes: 17 additions & 0 deletions Tests/SwiftBuildSupportTests/PIFBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,23 @@ struct PIFBuilderTests {
}
}

@Test
func errorEmittedWhenTestTargetDependsOnAnotherTestTarget() async throws {
try await withGeneratedPIF(fromFixture: "TestTargetDependOnTestTarget") { pif, observabilitySystem in
let expectedErrors: Set = [
"PIF: Test target 'myOtherTestTarget' cannot depend on another test target 'leafTestTarget'",
"PIF: Test target 'myTestTarget' cannot depend on another test target 'leafTestTarget'",
"PIF: Test target 'myOtherTestTarget' cannot depend on another test target 'myTestTarget'",
]
let actualDiags = observabilitySystem.diagnostics.filter { $0.severity == .error }
let diagMsgs = Set(actualDiags.map { $0.message })

#expect(actualDiags.count == expectedErrors.count)
#expect(actualDiags.count == diagMsgs.count)
#expect(diagMsgs == expectedErrors)
}
}

@Test func mixedSourceTarget() async throws {
let fs = InMemoryFileSystem(
emptyFiles:
Expand Down
Loading