xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Tests / XToolTests / DarwinSDKTests.swift
DarwinSDKTests.swift55 lines · 2.2 KiBRaw
| 1 | import Foundation |
| 2 | import Testing |
| 3 | @testable import PackLib |
| 4 | |
| 5 | @Test func swiftPMDirectoryUsesXDGConfigHome() throws { |
| 6 | let directory = try DarwinSDK.swiftPMDirectory( |
| 7 | environment: ["XDG_CONFIG_HOME": "/xdg/config"], |
| 8 | homeDirectory: URL(fileURLWithPath: "/home/test") |
| 9 | ) |
| 10 | |
| 11 | #expect(directory.path == "/xdg/config/swiftpm") |
| 12 | } |
| 13 | |
| 14 | @Test func swiftPMDirectoryFallsBackToHomeDirectory() throws { |
| 15 | let directory = try DarwinSDK.swiftPMDirectory( |
| 16 | environment: [:], |
| 17 | homeDirectory: URL(fileURLWithPath: "/home/test") |
| 18 | ) |
| 19 | |
| 20 | #expect(directory.path == "/home/test/.swiftpm") |
| 21 | } |
| 22 | |
| 23 | @Test func swiftPMDirectoryRejectsRelativeXDGConfigHome() { |
| 24 | #expect(throws: StringError.self) { |
| 25 | try DarwinSDK.swiftPMDirectory( |
| 26 | environment: ["XDG_CONFIG_HOME": "relative/config"], |
| 27 | homeDirectory: URL(fileURLWithPath: "/home/test") |
| 28 | ) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | @Test func temporaryDarwinSDKBundleUsesSwiftSDKsDirectory() throws { |
| 33 | let configDirectory = FileManager.default.temporaryDirectory |
| 34 | .appendingPathComponent("DarwinSDKTests-\(UUID().uuidString)", isDirectory: true) |
| 35 | defer { try? FileManager.default.removeItem(at: configDirectory) } |
| 36 | |
| 37 | let environment = ["XDG_CONFIG_HOME": configDirectory.path] |
| 38 | let sdksDirectory = configDirectory.appending(path: "swiftpm/swift-sdks") |
| 39 | let temporaryURL = sdksDirectory.appendingPathComponent("darwin.artifactbundle.tmp", isDirectory: true) |
| 40 | let installedBundle = sdksDirectory.appending(path: "darwin.artifactbundle") |
| 41 | try FileManager.default.createDirectory(at: installedBundle, withIntermediateDirectories: true) |
| 42 | try FileManager.default.createDirectory(at: temporaryURL, withIntermediateDirectories: false) |
| 43 | |
| 44 | do { |
| 45 | let temporaryBundle = try DarwinSDK.prepareTemporaryBundle(environment: environment) |
| 46 | #expect(temporaryBundle.url == temporaryURL) |
| 47 | #expect(!FileManager.default.fileExists(atPath: temporaryURL.path)) |
| 48 | |
| 49 | try FileManager.default.createDirectory(at: temporaryBundle.url, withIntermediateDirectories: false) |
| 50 | #expect(DarwinSDK(bundle: temporaryBundle.url)?.version == "develop") |
| 51 | } |
| 52 | |
| 53 | #expect(!FileManager.default.fileExists(atPath: temporaryURL.path)) |
| 54 | #expect(FileManager.default.fileExists(atPath: installedBundle.path)) |
| 55 | } |