Skip to content

Commit 176e123

Browse files
committed
Added Test
1 parent 6d83aef commit 176e123

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Sources/Swiftly/Install.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ struct Install: SwiftlyCommand {
325325
} else if ctx.format == .json {
326326
nil
327327
} else {
328-
ConsoleProgressReporter(stream: stdoutStream, header: "Downloading \(version)")
328+
ConsoleProgressReporter(stream: stderrStream, header: "Downloading \(version)")
329329
}
330330

331331
defer {

Tests/SwiftlyTests/InstallTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,38 @@ import Testing
389389
}
390390
}
391391
#endif
392+
393+
/// Tests that `install` command with JSON format outputs correctly structured JSON.
394+
@Test(.testHomeMockedToolchain()) func installJsonFormat() async throws {
395+
let output = try await SwiftlyTests.runWithMockedIO(
396+
Install.self, ["install", "5.7.0", "--post-install-file=\(fs.mktemp())", "--format", "json"], format: .json
397+
)
398+
399+
let installInfo = try JSONDecoder().decode(
400+
InstallInfo.self,
401+
from: output[0].data(using: .utf8)!
402+
)
403+
404+
#expect(installInfo.version.name == "5.7.0")
405+
#expect(installInfo.alreadyInstalled == false)
406+
}
407+
408+
/// Tests that `install` command with JSON format correctly indicates when toolchain is already installed.
409+
@Test(.testHomeMockedToolchain()) func installJsonFormatAlreadyInstalled() async throws {
410+
// First install the toolchain
411+
try await SwiftlyTests.runCommand(Install.self, ["install", "5.7.0", "--post-install-file=\(fs.mktemp())"])
412+
413+
// Then try to install it again with JSON format
414+
let output = try await SwiftlyTests.runWithMockedIO(
415+
Install.self, ["install", "5.7.0", "--post-install-file=\(fs.mktemp())", "--format", "json"], format: .json
416+
)
417+
418+
let installInfo = try JSONDecoder().decode(
419+
InstallInfo.self,
420+
from: output[0].data(using: .utf8)!
421+
)
422+
423+
#expect(installInfo.version.name == "5.7.0")
424+
#expect(installInfo.alreadyInstalled == true)
425+
}
392426
}

0 commit comments

Comments
 (0)