Skip to content

Commit 8473930

Browse files
committed
Fix a unit test that is writing to the checkout of SwiftPM itself.
This was never a good thing to do, but now that we have v2 of Package.resolved, it is an actively harmful thing to do if the IDE or toolchain being used to build SwiftPM and run the tests is older (e.g. using the 5.5 toolchain but working on main). There's not need at all to run this test against SwiftPM itself — a sample package created for the purpose in the usual temporary directory is all that's needed. rdar://83222890
1 parent 18902ff commit 8473930

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

Tests/WorkspaceTests/WorkspaceTests.swift

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3806,40 +3806,48 @@ final class WorkspaceTests: XCTestCase {
38063806

38073807
// This verifies that the simplest possible loading APIs are available for package clients.
38083808
func testSimpleAPI() throws {
3809-
// This checkout of the SwiftPM package.
3810-
let packagePath = AbsolutePath(#file).parentDirectory.parentDirectory.parentDirectory
3809+
try testWithTemporaryDirectory { path in
3810+
// Create a temporary package as a test case.
3811+
let packagePath = path.appending(component: "MyPkg")
3812+
let initPackage = try InitPackage(name: packagePath.basename, destinationPath: packagePath, packageType: .executable)
3813+
try initPackage.writePackageStructure()
3814+
3815+
// Load the workspace.
3816+
let observability = ObservabilitySystem.bootstrapForTesting()
3817+
let workspace = try Workspace(forRootPackage: packagePath, customToolchain: UserToolchain.default)
38113818

3812-
let observability = ObservabilitySystem.bootstrapForTesting()
3813-
let workspace = try Workspace(forRootPackage: packagePath, customToolchain: UserToolchain.default)
3814-
3815-
// From here the API should be simple and straightforward:
3816-
let manifest = try tsc_await {
3817-
workspace.loadRootManifest(
3818-
at: packagePath,
3819-
diagnostics: ObservabilitySystem.topScope.makeDiagnosticsEngine(),
3820-
completion: $0
3821-
)
3822-
}
3823-
XCTAssertFalse(observability.hasErrorDiagnostics)
3819+
// From here the API should be simple and straightforward:
3820+
let manifest = try tsc_await {
3821+
workspace.loadRootManifest(
3822+
at: packagePath,
3823+
diagnostics: ObservabilitySystem.topScope.makeDiagnosticsEngine(),
3824+
completion: $0
3825+
)
3826+
}
3827+
XCTAssertFalse(observability.hasWarningDiagnostics, observability.diagnostics.description)
3828+
XCTAssertFalse(observability.hasErrorDiagnostics, observability.diagnostics.description)
38243829

3825-
let package = try tsc_await {
3826-
workspace.loadRootPackage(
3827-
at: packagePath,
3828-
diagnostics: ObservabilitySystem.topScope.makeDiagnosticsEngine(),
3829-
completion: $0
3830-
)
3831-
}
3832-
XCTAssertFalse(observability.hasErrorDiagnostics)
3830+
let package = try tsc_await {
3831+
workspace.loadRootPackage(
3832+
at: packagePath,
3833+
diagnostics: ObservabilitySystem.topScope.makeDiagnosticsEngine(),
3834+
completion: $0
3835+
)
3836+
}
3837+
XCTAssertFalse(observability.hasWarningDiagnostics, observability.diagnostics.description)
3838+
XCTAssertFalse(observability.hasErrorDiagnostics, observability.diagnostics.description)
38333839

3834-
let graph = try workspace.loadPackageGraph(
3835-
rootPath: packagePath,
3836-
diagnostics: ObservabilitySystem.topScope.makeDiagnosticsEngine()
3837-
)
3838-
XCTAssertFalse(observability.hasErrorDiagnostics)
3840+
let graph = try workspace.loadPackageGraph(
3841+
rootPath: packagePath,
3842+
diagnostics: ObservabilitySystem.topScope.makeDiagnosticsEngine()
3843+
)
3844+
XCTAssertFalse(observability.hasWarningDiagnostics, observability.diagnostics.description)
3845+
XCTAssertFalse(observability.hasErrorDiagnostics, observability.diagnostics.description)
38393846

3840-
XCTAssertEqual(manifest.name, "SwiftPM")
3841-
XCTAssertEqual(package.manifestName, manifest.name)
3842-
XCTAssert(graph.reachableProducts.contains(where: { $0.name == "SwiftPM" }))
3847+
XCTAssertEqual(manifest.name, "MyPkg")
3848+
XCTAssertEqual(package.manifestName, manifest.name)
3849+
XCTAssert(graph.reachableProducts.contains(where: { $0.name == "MyPkg" }))
3850+
}
38433851
}
38443852

38453853
func testRevisionDepOnLocal() throws {

0 commit comments

Comments
 (0)