Skip to content

Commit 809c405

Browse files
committed
Fix: enhance cache cleanup test
1 parent ee48da5 commit 809c405

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Sources/SPMTestSupport/MockWorkspace.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public final class MockWorkspace {
136136
return self.sandbox.appending(components: ".build", "artifacts")
137137
}
138138

139+
public var workspaceLocation: Workspace.Location? {
140+
return self._workspace?.location
141+
}
142+
139143
public func pathToRoot(withName name: String) throws -> AbsolutePath {
140144
return try AbsolutePath(validating: name, relativeTo: self.rootsDir)
141145
}

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7416,6 +7416,7 @@ final class WorkspaceTests: XCTestCase {
74167416
let fs = InMemoryFileSystem()
74177417
let sandbox = AbsolutePath("/tmp/ws/")
74187418
try fs.createDirectory(sandbox, recursive: true)
7419+
let artifactUrl = "https://a.com/a.zip"
74197420

74207421
let httpClient = LegacyHTTPClient(handler: { request, _, completion in
74217422
do {
@@ -7446,7 +7447,7 @@ final class WorkspaceTests: XCTestCase {
74467447
MockTarget(
74477448
name: "A1",
74487449
type: .binary,
7449-
url: "https://a.com/a.zip",
7450+
url: artifactUrl,
74507451
checksum: "a1"
74517452
),
74527453
]
@@ -7471,7 +7472,17 @@ final class WorkspaceTests: XCTestCase {
74717472
// make sure artifact downloaded is deleted
74727473
XCTAssertTrue(fs.isDirectory(AbsolutePath("/tmp/ws/.build/artifacts/root")))
74737474
XCTAssertFalse(fs.exists(AbsolutePath("/tmp/ws/.build/artifacts/root/a.zip")))
7474-
XCTAssertFalse(fs.exists(AbsolutePath("/home/user/caches/org.swift.swiftpm/artifacts/https___a_com_a_zip")))
7475+
7476+
// make sure the cached artifact is also deleted
7477+
let artifactCacheKey = artifactUrl.spm_mangledToC99ExtendedIdentifier()
7478+
guard let cachePath = workspace.workspaceLocation?
7479+
.sharedBinaryArtifactsCacheDirectory?
7480+
.appending(artifactCacheKey) else {
7481+
XCTFail("Required workspace location wasn't found")
7482+
return
7483+
}
7484+
7485+
XCTAssertFalse(fs.exists(cachePath))
74757486
}
74767487

74777488
func testArtifactDownloaderOrArchiverError() throws {

0 commit comments

Comments
 (0)