Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/62_snapshot_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
container: ["ubuntu:20.04", "ubuntu:22.04", "ubuntu:24.04", "redhat/ubi9", "debian:12"]
container: ["ubuntu:22.04", "ubuntu:24.04", "redhat/ubi9", "debian:12"]
container:
image: ${{ matrix.container }}
steps:
Expand All @@ -20,9 +20,9 @@ jobs:
- name: Prepare the action
run: ./scripts/prep-gh-action.sh --install-swiftly --swift-snapshot 6.2
- name: Build and Test
# UBI 9 and Ubuntu 20.04 - See https://github.com/swiftlang/swift/issues/80908
# UBI 9 - See https://github.com/swiftlang/swift/issues/80908
# UBI 9 - See https://github.com/swiftlang/swift/issues/80909
run: bash -c 'if [[ "${{ matrix.container }}" == "redhat/ubi9" ]]; then swiftly run +6.2-snapshot swift build --build-tests; elif [[ "${{ matrix.container }}" == "ubuntu:20.04" ]]; then swiftly run +6.2-snapshot swift build --build-tests; else swiftly run +6.2-snapshot swift test; fi'
run: bash -c 'if [[ "${{ matrix.container }}" == "redhat/ubi9" ]]; then swiftly run +6.2-snapshot swift build --build-tests; else swiftly run +6.2-snapshot swift test; fi'

tests-selfhosted-macos:
name: Test (Smoke Test - Nightly Swift Toolchain) / macOS Sequoia ARM64
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nightly_snapshot_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
container: ["ubuntu:20.04", "ubuntu:22.04", "ubuntu:24.04", "redhat/ubi9", "debian:12"]
container: ["ubuntu:22.04", "ubuntu:24.04", "redhat/ubi9", "debian:12"]
container:
image: ${{ matrix.container }}
steps:
Expand All @@ -20,9 +20,9 @@ jobs:
- name: Prepare the action
run: ./scripts/prep-gh-action.sh --install-swiftly --swift-snapshot main
- name: Build and Test
# UBI 9 and Ubuntu 20.04 - See https://github.com/swiftlang/swift/issues/80908
# UBI 9 - See https://github.com/swiftlang/swift/issues/80908
# UBI 9 - See https://github.com/swiftlang/swift/issues/80909
run: bash -c 'if [[ "${{ matrix.container }}" == "redhat/ubi9" ]]; then swiftly run +main-snapshot swift build --build-tests; elif [[ "${{ matrix.container }}" == "ubuntu:20.04" ]]; then swiftly run +main-snapshot swift build --build-tests; else swiftly run +main-snapshot swift test; fi'
run: bash -c 'if [[ "${{ matrix.container }}" == "redhat/ubi9" ]]; then swiftly run +main-snapshot swift build --build-tests; else swiftly run +main-snapshot swift test; fi'

tests-selfhosted-macos:
name: Test (Smoke Test - Nightly Swift Toolchain) / macOS Sequoia ARM64
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
container: ["ubuntu:20.04", "ubuntu:22.04", "ubuntu:24.04", "redhat/ubi9", "debian:12", "fedora:39"]
container: ["ubuntu:22.04", "ubuntu:24.04", "redhat/ubi9", "debian:12", "fedora:39"]
container:
image: ${{ matrix.container }}
steps:
Expand All @@ -48,9 +48,9 @@ jobs:
- name: Prepare the action
run: ./scripts/prep-gh-action.sh --install-swiftly
- name: Build and Test
# UBI 9 and Ubuntu 20.04 - See https://github.com/swiftlang/swift/issues/80908
# UBI 9 - See https://github.com/swiftlang/swift/issues/80908
# UBI 9 - See https://github.com/swiftlang/swift/issues/80909
run: bash -c 'if [[ "${{ matrix.container }}" == "redhat/ubi9" ]]; then swift build --build-tests; elif [[ "${{ matrix.container }}" == "ubuntu:20.04" ]]; then swift build --build-tests; else swift test; fi'
run: bash -c 'if [[ "${{ matrix.container }}" == "redhat/ubi9" ]]; then swift build --build-tests; else swift test; fi'

releasebuildcheck:
name: Release Build Check / Linux
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.0
6.2.0
2 changes: 1 addition & 1 deletion Sources/Swiftly/Uninstall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct Uninstall: SwiftlyCommand {
static let allSelector = "all"
}

private struct UninstallCancelledError: Error {}
package struct UninstallCancelledError: Error {}

private struct ToolchainSelectionResult {
let validToolchains: Set<ToolchainVersion>
Expand Down
12 changes: 10 additions & 2 deletions Tests/SwiftlyTests/SwiftlyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,11 @@ public enum SwiftlyTests {
try await cmd.run(Self.ctx)
}

public struct NoError: Error {}

/// Run this command, using the provided input as the stdin (in lines). Returns an array of captured
/// output lines.
static func runWithMockedIO<T: SwiftlyCommand>(_ commandType: T.Type, _ arguments: [String], quiet: Bool = false, input: [String]? = nil, format: SwiftlyCore.OutputFormat = .text) async throws -> [String] {
static func runWithMockedIO<T: SwiftlyCommand, E: Error>(_ commandType: T.Type, _ arguments: [String], quiet: Bool = false, input: [String]? = nil, format: SwiftlyCore.OutputFormat = .text, throws expectedError: E.Type = NoError.self) async throws -> [String] {
let handler = TestOutputHandler(quiet: quiet)
let provider: (any InputProvider)? = if let input {
TestInputProvider(lines: input)
Expand All @@ -263,7 +265,13 @@ public enum SwiftlyTests {
)
}

try await cmd.run(ctx)
if expectedError != NoError.self {
try await #expect(throws: expectedError) {
try await cmd.run(ctx)
}
} else {
try await cmd.run(ctx)
}

return await handler.lines
}
Expand Down
33 changes: 23 additions & 10 deletions Tests/SwiftlyTests/UninstallTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import Testing

/// Tests that `swiftly uninstall` successfully handles being invoked when no toolchains have been installed yet.
@Test(.mockHomeToolchains(Self.homeName, toolchains: []), .mockedSwiftlyVersion()) func uninstallNoInstalledToolchains() async throws {
_ = try await SwiftlyTests.runWithMockedIO(Uninstall.self, ["uninstall", "1.2.3"], input: ["y"])
try await #require(throws: Uninstall.UninstallCancelledError.self) {
_ = try await SwiftlyTests.runWithMockedIO(Uninstall.self, ["uninstall", "1.2.3"], input: ["y"])
}

try await SwiftlyTests.validateInstalledToolchains(
[],
Expand All @@ -33,7 +35,9 @@ import Testing
}

// Ensure that uninstalling when no toolchains are installed is handled gracefully.
try await SwiftlyTests.runCommand(Uninstall.self, ["uninstall", "latest"])
try await #require(throws: Uninstall.UninstallCancelledError.self) {
try await SwiftlyTests.runCommand(Uninstall.self, ["uninstall", "latest"])
}
}
}

Expand All @@ -51,7 +55,9 @@ import Testing
)
}

_ = try await SwiftlyTests.runWithMockedIO(Uninstall.self, ["uninstall", "1.2.3"], input: ["y"])
try await #require(throws: Uninstall.UninstallCancelledError.self) {
_ = try await SwiftlyTests.runWithMockedIO(Uninstall.self, ["uninstall", "1.2.3"], input: ["y"])
}

try await SwiftlyTests.validateInstalledToolchains(
installed,
Expand All @@ -73,7 +79,9 @@ import Testing
)
}

_ = try await SwiftlyTests.runWithMockedIO(Uninstall.self, ["uninstall", "main-snapshot-2022-01-01"], input: ["y"])
try await #require(throws: Uninstall.UninstallCancelledError.self) {
_ = try await SwiftlyTests.runWithMockedIO(Uninstall.self, ["uninstall", "main-snapshot-2022-01-01"], input: ["y"])
}

try await SwiftlyTests.validateInstalledToolchains(
installed,
Expand Down Expand Up @@ -239,7 +247,9 @@ import Testing
/// Tests that aborting an uninstall works correctly.
@Test(.mockedSwiftlyVersion(), .mockHomeToolchains(Self.homeName, toolchains: .allToolchains(), inUse: .oldStable)) func uninstallAbort() async throws {
let preConfig = try await Config.load()
_ = try await SwiftlyTests.runWithMockedIO(Uninstall.self, ["uninstall", ToolchainVersion.oldStable.name], input: ["n"])
try await #require(throws: Uninstall.UninstallCancelledError.self) {
_ = try await SwiftlyTests.runWithMockedIO(Uninstall.self, ["uninstall", ToolchainVersion.oldStable.name], input: ["n"])
}
try await SwiftlyTests.validateInstalledToolchains(
.allToolchains(),
description: "abort uninstall"
Expand Down Expand Up @@ -282,8 +292,8 @@ import Testing
}

@Test(.mockedSwiftlyVersion(), .mockHomeToolchains(Self.homeName, toolchains: [])) func uninstallXcode() async throws {
let output = try await SwiftlyTests.runWithMockedIO(Uninstall.self, ["uninstall", "-y", ToolchainVersion.xcodeVersion.name])
#expect(!output.filter { $0.contains("No toolchains can be uninstalled that match \"xcode\"") }.isEmpty)
let output = try await SwiftlyTests.runWithMockedIO(Uninstall.self, ["uninstall", "-y", ToolchainVersion.xcodeVersion.name], throws: Uninstall.UninstallCancelledError.self)
#expect(!output.filter { $0.contains("No toolchains can be uninstalled that match \"xcode\"") || $0.contains("No toolchains match these selectors: xcode") }.isEmpty)
}

// MARK: - Multiple Selector Tests
Expand Down Expand Up @@ -379,7 +389,8 @@ import Testing
let output = try await SwiftlyTests.runWithMockedIO(
Uninstall.self,
["uninstall", ToolchainVersion.oldStable.name, "invalid-selector"],
input: ["n"] // Abort at error prompt
input: ["n"], // Abort at error prompt
throws: Uninstall.UninstallCancelledError.self
)

// Should show error and abort
Expand All @@ -398,7 +409,8 @@ import Testing
func uninstallNoMatchSelectors() async throws {
let output = try await SwiftlyTests.runWithMockedIO(
Uninstall.self,
["uninstall", "main-snapshot", "5.99.0"] // Neither installed
["uninstall", "main-snapshot", "5.99.0"], // Neither installed
throws: Uninstall.UninstallCancelledError.self
)

#expect(output.contains { $0.contains("No toolchains match these selectors: main-snapshot, 5.99.0") })
Expand All @@ -416,7 +428,8 @@ import Testing
func uninstallAllInvalidSelectors() async throws {
let output = try await SwiftlyTests.runWithMockedIO(
Uninstall.self,
["uninstall", "invalid-1", "invalid-2"]
["uninstall", "invalid-1", "invalid-2"],
throws: Uninstall.UninstallCancelledError.self
)

#expect(output.contains { $0.contains("Invalid toolchain selectors: invalid-1, invalid-2") })
Expand Down