diff --git a/Tests/SwiftlyTests/SwiftlyTests.swift b/Tests/SwiftlyTests/SwiftlyTests.swift index db8fb4a5..59bedf9f 100644 --- a/Tests/SwiftlyTests/SwiftlyTests.swift +++ b/Tests/SwiftlyTests/SwiftlyTests.swift @@ -336,6 +336,7 @@ public enum SwiftlyTests { if cleanBinDir { try await fs.remove(atPath: Swiftly.currentPlatform.swiftlyBinDir(Self.ctx)) } + throw error } } } diff --git a/Tests/SwiftlyTests/UseTests.swift b/Tests/SwiftlyTests/UseTests.swift index 720ec2de..1e7fbbca 100644 --- a/Tests/SwiftlyTests/UseTests.swift +++ b/Tests/SwiftlyTests/UseTests.swift @@ -11,9 +11,17 @@ import Testing /// Execute a `use` command with the provided argument. Then validate that the configuration is updated properly and /// the in-use swift executable prints the the provided expectedVersion. func useAndValidate(argument: String, expectedVersion: ToolchainVersion) async throws { - try await SwiftlyTests.runCommand(Use.self, ["use", "-g", argument]) + do { + try await SwiftlyTests.runCommand(Use.self, ["use", "-g", argument]) + } catch { + // Swallow any errors. Some of these tests verify that switching to + // a non-existent toolchain does not change the version + // configuration. + // Swiftly should emit an error message, but we don't care. + } - #expect(try await Config.load().inUse == expectedVersion) + let useToolchain = try await Config.load().inUse + #expect(useToolchain == expectedVersion) } /// Tests that the `use` command can switch between installed stable release toolchains. @@ -201,15 +209,20 @@ import Testing /// Tests that the `use` command gracefully exits when executed before any toolchains have been installed. @Test(.mockedSwiftlyVersion(), .mockHomeToolchains(toolchains: [])) func useNoInstalledToolchains() async throws { - try await SwiftlyTests.runCommand(Use.self, ["use", "-g", "latest"]) + do { + try await SwiftlyTests.runCommand(Use.self, ["use", "-g", "latest"]) - var config = try await Config.load() - #expect(config.inUse == nil) + var config = try await Config.load() + #expect(config.inUse == nil) - try await SwiftlyTests.runCommand(Use.self, ["use", "-g", "5.6.0"]) + try await SwiftlyTests.runCommand(Use.self, ["use", "-g", "5.6.0"]) - config = try await Config.load() - #expect(config.inUse == nil) + config = try await Config.load() + #expect(config.inUse == nil) + } catch { + // Swallow errors. This test is verifying that we don't change the + // in-use toolchain if no toolchains are installed + } } /// Tests that the `use` command gracefully handles being executed with toolchain names that haven't been installed.