Skip to content

Commit 7488194

Browse files
committed
more tests
1 parent e237516 commit 7488194

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ private func createResolvedPackages(
270270
} else {
271271
return packageObservabilityScope.emit(error)
272272
}
273+
} else if resolvedPackage.package.manifest.canonicalPackageLocation == dependencyPackageRef.canonicalLocation &&
274+
resolvedPackage.package.manifest.packageLocation != dependencyPackageRef.locationString &&
275+
!resolvedPackage.allowedToOverride {
276+
packageObservabilityScope.emit(info: "dependency on '\(resolvedPackage.package.identity)' is represented by similar locations ('\(resolvedPackage.package.manifest.packageLocation)' and '\(dependencyPackageRef.locationString)') which are treated as the same canonical location '\(dependencyPackageRef.canonicalLocation)'.")
273277
}
274278

275279
// checks if two dependencies have the same explicit name which can cause target based dependency package lookup issue

Sources/PackageModel/PackageIdentity.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ struct PackageIdentityParser {
384384
/// ```
385385
/// file:///Users/mona/LinkedList → /Users/mona/LinkedList
386386
/// ```
387-
public struct CanonicalPackageLocation: Equatable {
387+
public struct CanonicalPackageLocation: Equatable, CustomStringConvertible {
388388
/// A textual representation of this instance.
389389
public let description: String
390390

Sources/SPMTestSupport/Observability.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,17 @@ public func testDiagnostics(
9090
line: UInt = #line,
9191
handler: (DiagnosticsTestResult) throws -> Void
9292
) {
93-
let diagnostics = problemsOnly ? diagnostics.filter({ $0.severity >= .warning }) : diagnostics
93+
testDiagnostics(diagnostics, minSeverity: problemsOnly ? .warning : .debug, file: file, line: line, handler: handler)
94+
}
95+
96+
public func testDiagnostics(
97+
_ diagnostics: [Basics.Diagnostic],
98+
minSeverity: Basics.Diagnostic.Severity,
99+
file: StaticString = #file,
100+
line: UInt = #line,
101+
handler: (DiagnosticsTestResult) throws -> Void
102+
) {
103+
let diagnostics = diagnostics.filter{ $0.severity >= minSeverity }
94104
let testResult = DiagnosticsTestResult(diagnostics)
95105

96106
do {

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8109,6 +8109,116 @@ final class WorkspaceTests: XCTestCase {
81098109
}
81108110
}
81118111

8112+
func testDuplicateTransitiveIdentityWithSimilarURLs() throws {
8113+
let sandbox = AbsolutePath("/tmp/ws/")
8114+
let fs = InMemoryFileSystem()
8115+
8116+
let workspace = try MockWorkspace(
8117+
sandbox: sandbox,
8118+
fileSystem: fs,
8119+
roots: [
8120+
MockPackage(
8121+
name: "Root",
8122+
targets: [
8123+
MockTarget(name: "RootTarget", dependencies: [
8124+
.product(name: "FooProduct", package: "foo"),
8125+
.product(name: "BarProduct", package: "bar"),
8126+
.product(name: "BazProduct", package: "baz")
8127+
]),
8128+
],
8129+
products: [],
8130+
dependencies: [
8131+
.sourceControl(url: "https://github.com/org/foo.git", requirement: .upToNextMajor(from: "1.0.0")),
8132+
.sourceControl(url: "https://github.com/org/bar.git", requirement: .upToNextMajor(from: "1.0.0")),
8133+
.sourceControl(url: "https://github.com/org/baz.git", requirement: .upToNextMajor(from: "1.0.0")),
8134+
],
8135+
toolsVersion: .v5_6
8136+
),
8137+
],
8138+
packages: [
8139+
MockPackage(
8140+
name: "FooPackage",
8141+
url: "https://github.com/org/foo.git",
8142+
targets: [
8143+
MockTarget(name: "FooTarget"),
8144+
],
8145+
products: [
8146+
MockProduct(name: "FooProduct", targets: ["FooTarget"]),
8147+
],
8148+
versions: ["1.0.0"]
8149+
),
8150+
MockPackage(
8151+
name: "BarPackage",
8152+
url: "https://github.com/org/bar.git",
8153+
targets: [
8154+
MockTarget(name: "BarTarget", dependencies: [
8155+
.product(name: "FooProduct", package: "Foo"),
8156+
.product(name: "BazProduct", package: "baz"),
8157+
]),
8158+
],
8159+
products: [
8160+
MockProduct(name: "BarProduct", targets: ["BarTarget"]),
8161+
],
8162+
dependencies: [
8163+
.sourceControl(url: "https://github.com/ORG/Foo.git", requirement: .upToNextMajor(from: "1.0.0")),
8164+
.sourceControl(url: "https://github.com/org/baz", requirement: .upToNextMajor(from: "1.0.0")),
8165+
],
8166+
versions: ["1.0.0"]
8167+
),
8168+
MockPackage(
8169+
name: "BazPackage",
8170+
url: "https://github.com/org/baz.git",
8171+
targets: [
8172+
MockTarget(name: "BazTarget"),
8173+
],
8174+
products: [
8175+
MockProduct(name: "BazProduct", targets: ["BazTarget"]),
8176+
],
8177+
versions: ["1.0.0"]
8178+
),
8179+
// URL with different casing
8180+
MockPackage(
8181+
name: "FooPackage",
8182+
url: "https://github.com/ORG/Foo.git",
8183+
targets: [
8184+
MockTarget(name: "FooTarget"),
8185+
],
8186+
products: [
8187+
MockProduct(name: "FooProduct", targets: ["FooTarget"]),
8188+
],
8189+
versions: ["1.0.0"]
8190+
),
8191+
// URL with no .git extension
8192+
MockPackage(
8193+
name: "BazPackage",
8194+
url: "https://github.com/org/baz",
8195+
targets: [
8196+
MockTarget(name: "BazTarget"),
8197+
],
8198+
products: [
8199+
MockProduct(name: "BazProduct", targets: ["BazTarget"]),
8200+
],
8201+
versions: ["1.0.0"]
8202+
),
8203+
]
8204+
)
8205+
8206+
// 9/2021 this is currently emitting a warning only to support backwards compatibility
8207+
// we will escalate this to an error in a few versions to tighten up the validation
8208+
try workspace.checkPackageGraph(roots: ["Root"]) { graph, diagnostics in
8209+
testDiagnostics(diagnostics, minSeverity: .info) { result in
8210+
result.checkUnordered(
8211+
diagnostic: "dependency on 'foo' is represented by similar locations ('https://github.com/org/foo.git' and 'https://github.com/ORG/Foo.git') which are treated as the same canonical location 'github.com/org/foo'.",
8212+
severity: .info
8213+
)
8214+
result.checkUnordered(
8215+
diagnostic: "dependency on 'baz' is represented by similar locations ('https://github.com/org/baz.git' and 'https://github.com/org/baz') which are treated as the same canonical location 'github.com/org/baz'.",
8216+
severity: .info
8217+
)
8218+
}
8219+
}
8220+
}
8221+
81128222
func testDuplicateNestedTransitiveIdentityWithNames() throws {
81138223
let sandbox = AbsolutePath("/tmp/ws/")
81148224
let fs = InMemoryFileSystem()

0 commit comments

Comments
 (0)