@@ -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