Skip to content

Commit b5e95b8

Browse files
committed
Fix up the tests and system toolchain list output
1 parent 627e158 commit b5e95b8

File tree

8 files changed

+40
-30
lines changed

8 files changed

+40
-30
lines changed

Sources/Swiftly/List.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ struct List: SwiftlyCommand {
6363
)
6464
}
6565

66-
#if os(macOS)
67-
installedToolchainInfos.append(
68-
InstallToolchainInfo(
69-
version: ToolchainVersion.xcode,
70-
inUse: inUse == ToolchainVersion.xcode,
71-
isDefault: config.inUse == ToolchainVersion.xcode
72-
)
73-
)
74-
#endif
75-
7666
try await ctx.output(InstalledToolchainsListInfo(toolchains: installedToolchainInfos, selector: selector))
7767
}
7868
}

Sources/Swiftly/OutputSchema.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ struct InstalledToolchainsListInfo: OutputData {
320320
"main development snapshot"
321321
case let .snapshot(.release(major, minor), nil):
322322
"\(major).\(minor) development snapshot"
323+
case .xcode:
324+
"xcode"
323325
default:
324326
"matching"
325327
}
@@ -340,6 +342,13 @@ struct InstalledToolchainsListInfo: OutputData {
340342
lines.append("Installed snapshot toolchains")
341343
lines.append("-----------------------------")
342344
lines.append(contentsOf: snapshotToolchains.map(\.description))
345+
346+
#if os(macOS)
347+
lines.append("")
348+
lines.append("Available system toolchains")
349+
lines.append("---------------------------")
350+
lines.append(ToolchainVersion.xcode.description)
351+
#endif
343352
}
344353

345354
return lines.joined(separator: "\n")

Tests/SwiftlyTests/InstallTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ import Testing
256256
}
257257

258258
/// Verify that the installed toolchain will be marked as in-use if the --use flag is specified.
259-
@Test(.testHomeMockedToolchain()) func installUseFlag() async throws {
259+
@Test(.mockedSwiftlyVersion(), .testHomeMockedToolchain()) func installUseFlag() async throws {
260260
try await SwiftlyTests.installMockedToolchain(toolchain: .oldStable)
261261
try await SwiftlyTests.runCommand(Use.self, ["use", ToolchainVersion.oldStable.name])
262262
try await SwiftlyTests.validateInUse(expected: .oldStable)

Tests/SwiftlyTests/ListTests.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ import Testing
5151
let parsedToolchains = lines.compactMap { outputLine in
5252
#if !os(macOS)
5353
Set<ToolchainVersion>.allToolchains().first {
54-
outputLine.contains(String(describing: $0))
54+
outputLine.hasPrefix(String(describing: $0))
5555
}
5656
#else
5757
(Set<ToolchainVersion>.allToolchains() + [.xcodeVersion]).first {
58-
outputLine.contains(String(describing: $0))
58+
outputLine.hasPrefix(String(describing: $0))
5959
}
6060
#endif
6161
}
6262

6363
// Ensure extra toolchains weren't accidentally included in the output.
64-
guard parsedToolchains.count == lines.filter({ $0.hasPrefix("Swift") || $0.contains("-snapshot") || $0.contains("xcode") }).count else {
64+
guard parsedToolchains.count == lines.filter({ $0.hasPrefix("Swift") || $0.contains("-snapshot") || $0.hasPrefix("xcode") }).count else {
6565
throw SwiftlyTestError(message: "unexpected listed toolchains in \(output)")
6666
}
6767

@@ -182,13 +182,18 @@ import Testing
182182
#expect(toolchains == systemToolchains)
183183

184184
toolchains = try await self.runList(selector: "5")
185-
#expect(toolchains == systemToolchains)
185+
#expect(toolchains == [])
186186

187187
toolchains = try await self.runList(selector: "main-snapshot")
188-
#expect(toolchains == systemToolchains)
188+
#expect(toolchains == [])
189189

190190
toolchains = try await self.runList(selector: "5.7-snapshot")
191+
#expect(toolchains == [])
192+
193+
#if os(macOS)
194+
toolchains = try await self.runList(selector: "xcode")
191195
#expect(toolchains == systemToolchains)
196+
#endif
192197
}
193198
}
194199

@@ -204,7 +209,13 @@ import Testing
204209
from: output[0].data(using: .utf8)!
205210
)
206211

207-
#expect(listInfo.toolchains.count == Set<ToolchainVersion>.allToolchains().count)
212+
#if !os(macOS)
213+
let systemToolchains: [ToolchainVersion] = []
214+
#else
215+
let systemToolchains: [ToolchainVersion] = [.xcodeVersion]
216+
#endif
217+
218+
#expect(listInfo.toolchains.count == Set<ToolchainVersion>.allToolchains().count + systemToolchains.count)
208219

209220
for toolchain in listInfo.toolchains {
210221
#expect(toolchain.version.name.isEmpty == false)

Tests/SwiftlyTests/PlatformTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ import Testing
8888
}
8989

9090
#if os(macOS)
91-
@Test(.testHome()) func findXcodeToolchainLocation() async throws {
91+
@Test(.mockedSwiftlyVersion(), .testHome()) func findXcodeToolchainLocation() async throws {
9292
// GIVEN: the xcode toolchain
9393
// AND there is xcode installed
9494
guard let xcodeLocation = try? await Swiftly.currentPlatform.runProgramOutput("xcode-select", "-p"), xcodeLocation != "" else {

Tests/SwiftlyTests/SwiftlyTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ actor InputProviderFail: InputProvider {
6161
}
6262

6363
struct HTTPRequestExecutorFail: HTTPRequestExecutor {
64-
func getCurrentSwiftlyRelease() async throws -> SwiftlyWebsiteAPI.Components.Schemas.SwiftlyRelease { fatalError(unmockedMsg + "3") }
65-
func getReleaseToolchains() async throws -> [Components.Schemas.Release] { fatalError(unmockedMsg + "4") }
66-
func getSnapshotToolchains(branch _: SwiftlyWebsiteAPI.Components.Schemas.SourceBranch, platform _: SwiftlyWebsiteAPI.Components.Schemas.PlatformIdentifier) async throws -> SwiftlyWebsiteAPI.Components.Schemas.DevToolchains { fatalError(unmockedMsg + "5") }
67-
func getGpgKeys() async throws -> OpenAPIRuntime.HTTPBody { fatalError(unmockedMsg + "6") }
68-
func getSwiftlyRelease(url _: URL) async throws -> OpenAPIRuntime.HTTPBody { fatalError(unmockedMsg + "7") }
69-
func getSwiftlyReleaseSignature(url _: URL) async throws -> OpenAPIRuntime.HTTPBody { fatalError(unmockedMsg + "8") }
70-
func getSwiftToolchainFile(_: ToolchainFile) async throws -> OpenAPIRuntime.HTTPBody { fatalError(unmockedMsg + "9") }
64+
func getCurrentSwiftlyRelease() async throws -> SwiftlyWebsiteAPI.Components.Schemas.SwiftlyRelease { fatalError(unmockedMsg) }
65+
func getReleaseToolchains() async throws -> [Components.Schemas.Release] { fatalError(unmockedMsg) }
66+
func getSnapshotToolchains(branch _: SwiftlyWebsiteAPI.Components.Schemas.SourceBranch, platform _: SwiftlyWebsiteAPI.Components.Schemas.PlatformIdentifier) async throws -> SwiftlyWebsiteAPI.Components.Schemas.DevToolchains { fatalError(unmockedMsg) }
67+
func getGpgKeys() async throws -> OpenAPIRuntime.HTTPBody { fatalError(unmockedMsg) }
68+
func getSwiftlyRelease(url _: URL) async throws -> OpenAPIRuntime.HTTPBody { fatalError(unmockedMsg) }
69+
func getSwiftlyReleaseSignature(url _: URL) async throws -> OpenAPIRuntime.HTTPBody { fatalError(unmockedMsg) }
70+
func getSwiftToolchainFile(_: ToolchainFile) async throws -> OpenAPIRuntime.HTTPBody { fatalError(unmockedMsg) }
7171
func getSwiftToolchainFileSignature(_: ToolchainFile) async throws
72-
-> OpenAPIRuntime.HTTPBody { fatalError(unmockedMsg + "10") }
72+
-> OpenAPIRuntime.HTTPBody { fatalError(unmockedMsg) }
7373
}
7474

7575
// Convenience extensions to common Swiftly and SwiftlyCore types to set the correct context

Tests/SwiftlyTests/UninstallTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ import Testing
281281
)
282282
}
283283

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

Tests/SwiftlyTests/UseTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ import Testing
193193

194194
#if os(macOS)
195195
/// Tests that the xcode toolchain can be used on macOS
196-
/*@Test(.mockHomeToolchains()) func useXcode() async throws {
197-
try await self.useAndValidate(argument: ToolchainVersion.xcodeVersion.name, expectedVersion: .xcode)
198-
}*/
196+
@Test(.mockedSwiftlyVersion(), .mockHomeToolchains()) func useXcode() async throws {
197+
try await self.useAndValidate(argument: ToolchainVersion.xcodeVersion.name, expectedVersion: .xcode)
198+
}
199199
#endif
200200

201201
/// Tests that the `use` command gracefully exits when executed before any toolchains have been installed.

0 commit comments

Comments
 (0)