@@ -4,7 +4,7 @@ import Foundation
44import Testing
55
66@Suite struct PlatformTests {
7- func mockToolchainDownload( version: String ) async throws -> ( URL , ToolchainVersion ) {
7+ func mockToolchainDownload( version: String ) async throws -> ( URL , ToolchainVersion , URL ) {
88 let mockDownloader = MockToolchainDownloader ( executables: [ " swift " ] )
99 let version = try ! ToolchainVersion ( parsing: version)
1010 let ext = Swiftly . currentPlatform. toolchainFileExtension
@@ -14,28 +14,37 @@ import Testing
1414 let mockedToolchain = try mockDownloader. makeMockedToolchain ( toolchain: version, name: tmpDir. path)
1515 try mockedToolchain. write ( to: mockedToolchainFile)
1616
17- return ( mockedToolchainFile, version)
17+ return ( mockedToolchainFile, version, tmpDir )
1818 }
1919
2020 @Test ( . testHome( ) ) func install( ) async throws {
2121 // GIVEN: a toolchain has been downloaded
22- var ( mockedToolchainFile, version) = try await self . mockToolchainDownload ( version: " 5.7.1 " )
22+ var ( mockedToolchainFile, version, tmpDir) = try await self . mockToolchainDownload ( version: " 5.7.1 " )
23+ var cleanup = [ tmpDir]
24+ defer {
25+ for dir in cleanup {
26+ try ? FileManager . default. removeItem ( at: dir)
27+ }
28+ }
29+
2330 // WHEN: the platform installs the toolchain
2431 try Swiftly . currentPlatform. install ( SwiftlyTests . ctx, from: mockedToolchainFile, version: version, verbose: true )
2532 // THEN: the toolchain is extracted in the toolchains directory
2633 var toolchains = try FileManager . default. contentsOfDirectory ( at: Swiftly . currentPlatform. swiftlyToolchainsDir ( SwiftlyTests . ctx) , includingPropertiesForKeys: nil )
2734 #expect( 1 == toolchains. count)
2835
2936 // GIVEN: a second toolchain has been downloaded
30- ( mockedToolchainFile, version) = try await self . mockToolchainDownload ( version: " 5.8.0 " )
37+ ( mockedToolchainFile, version, tmpDir) = try await self . mockToolchainDownload ( version: " 5.8.0 " )
38+ cleanup += [ tmpDir]
3139 // WHEN: the platform installs the toolchain
3240 try Swiftly . currentPlatform. install ( SwiftlyTests . ctx, from: mockedToolchainFile, version: version, verbose: true )
3341 // THEN: the toolchain is added to the toolchains directory
3442 toolchains = try FileManager . default. contentsOfDirectory ( at: Swiftly . currentPlatform. swiftlyToolchainsDir ( SwiftlyTests . ctx) , includingPropertiesForKeys: nil )
3543 #expect( 2 == toolchains. count)
3644
3745 // GIVEN: an identical toolchain has been downloaded
38- ( mockedToolchainFile, version) = try await self . mockToolchainDownload ( version: " 5.8.0 " )
46+ ( mockedToolchainFile, version, tmpDir) = try await self . mockToolchainDownload ( version: " 5.8.0 " )
47+ cleanup += [ tmpDir]
3948 // WHEN: the platform installs the toolchain
4049 try Swiftly . currentPlatform. install ( SwiftlyTests . ctx, from: mockedToolchainFile, version: version, verbose: true )
4150 // THEN: the toolchains directory remains the same
@@ -45,9 +54,16 @@ import Testing
4554
4655 @Test ( . testHome( ) ) func uninstall( ) async throws {
4756 // GIVEN: toolchains have been downloaded, and installed
48- var ( mockedToolchainFile, version) = try await self . mockToolchainDownload ( version: " 5.8.0 " )
57+ var ( mockedToolchainFile, version, tmpDir) = try await self . mockToolchainDownload ( version: " 5.8.0 " )
58+ var cleanup = [ tmpDir]
59+ defer {
60+ for dir in cleanup {
61+ try ? FileManager . default. removeItem ( at: dir)
62+ }
63+ }
4964 try Swiftly . currentPlatform. install ( SwiftlyTests . ctx, from: mockedToolchainFile, version: version, verbose: true )
50- ( mockedToolchainFile, version) = try await self . mockToolchainDownload ( version: " 5.6.3 " )
65+ ( mockedToolchainFile, version, tmpDir) = try await self . mockToolchainDownload ( version: " 5.6.3 " )
66+ cleanup += [ tmpDir]
5167 try Swiftly . currentPlatform. install ( SwiftlyTests . ctx, from: mockedToolchainFile, version: version, verbose: true )
5268 // WHEN: one of the toolchains is uninstalled
5369 try Swiftly . currentPlatform. uninstall ( SwiftlyTests . ctx, version, verbose: true )
0 commit comments