Slice 2 (Phase 1a) of the M9 Monterey retarget. Converts all pure Core suites (argv builders, CGATS/CUPS/profcheck/gamut-mesh parsers, colour math, file/artefact helpers, classifiers) to XCTestCase, and adds the shared assertAsyncThrows helper for the async-throws sites that Slice 3 will convert. Deferred to Slice 3 (kept on Swift Testing in mixed files): ProcessManagerTests, ArgyllRunner*Tests, ProcessRunSupportTests, store/UI suites, and the runner suites embedded in TargenTests / PrinttargTests / ProcessManagerTests. Also qualifies six bare `throw .case` expressions in CGATSParser with CGATSParseError — they only compiled under typed throws, which Slice 1 demoted to untyped `throws`; without this the ICCeryCore target fails to build and no test gate can run. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
83 lines
3.3 KiB
Swift
83 lines
3.3 KiB
Swift
import XCTest
|
|
import Foundation
|
|
@testable import ICCeryCore
|
|
|
|
final class BinaryResolverTests: XCTestCase {
|
|
|
|
private func makeTree(_ body: (URL) throws -> Void) throws -> URL {
|
|
let root = FileManager.default.temporaryDirectory
|
|
.appendingPathComponent("iccery-resolver-\(UUID().uuidString)")
|
|
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
|
|
try body(root)
|
|
return root
|
|
}
|
|
|
|
private func touch(_ url: URL, executable: Bool = true) throws {
|
|
FileManager.default.createFile(atPath: url.path, contents: Data())
|
|
if executable {
|
|
try FileManager.default.setAttributes(
|
|
[.posixPermissions: 0o755], ofItemAtPath: url.path
|
|
)
|
|
}
|
|
}
|
|
|
|
func testOverrideDirWinsWhenFileExists() throws {
|
|
let override = try makeTree { root in
|
|
try touch(root.appendingPathComponent("targen"))
|
|
}
|
|
let bundled = try makeTree { _ in }
|
|
let r = BinaryResolver(bundledRoot: bundled, overrideDir: override)
|
|
XCTAssertEqual(r.resolve("targen"), override.appendingPathComponent("targen"))
|
|
}
|
|
|
|
func testOverrideFallsThroughWhenMissing() throws {
|
|
let override = try makeTree { _ in }
|
|
let bundled = try makeTree { root in
|
|
let dir = root.appendingPathComponent("macos-universal")
|
|
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
|
try touch(dir.appendingPathComponent("instlist"))
|
|
}
|
|
let r = BinaryResolver(bundledRoot: bundled, overrideDir: override)
|
|
XCTAssertTrue(r.resolve("targen").path.contains("macos-universal/targen"))
|
|
}
|
|
|
|
func testUniversalPreferredWhenMarkerPresent() throws {
|
|
let bundled = try makeTree { root in
|
|
for dir in ["macos-universal", "macos-x86_64"] {
|
|
let d = root.appendingPathComponent(dir)
|
|
try FileManager.default.createDirectory(at: d, withIntermediateDirectories: true)
|
|
try touch(d.appendingPathComponent("instlist"))
|
|
}
|
|
}
|
|
let r = BinaryResolver(bundledRoot: bundled)
|
|
XCTAssertEqual(r.platformDir(), "macos-universal")
|
|
}
|
|
|
|
func testFallsBackToArchDir() throws {
|
|
let bundled = try makeTree { root in
|
|
let d = root.appendingPathComponent("macos-x86_64")
|
|
try FileManager.default.createDirectory(at: d, withIntermediateDirectories: true)
|
|
try touch(d.appendingPathComponent("instlist"))
|
|
}
|
|
let r = BinaryResolver(
|
|
bundledRoot: bundled,
|
|
archDirs: ["macos-universal", "macos-x86_64"]
|
|
)
|
|
XCTAssertEqual(r.platformDir(), "macos-x86_64")
|
|
}
|
|
|
|
func testMissingEverythingReturnsConstructedPath() throws {
|
|
let bundled = try makeTree { _ in }
|
|
let r = BinaryResolver(bundledRoot: bundled)
|
|
// v1 semantic: path is returned; spawn surfaces the error.
|
|
XCTAssertTrue(r.resolve("targen").path.hasSuffix("macos-universal/targen"))
|
|
XCTAssertFalse(r.exists(r.resolve("targen")))
|
|
}
|
|
|
|
func testMockAndGamutPaths() throws {
|
|
let r = BinaryResolver(bundledRoot: URL(fileURLWithPath: "/x"))
|
|
XCTAssertEqual(r.mock("chartread").path, "/x/mocks/chartread.mock")
|
|
XCTAssertEqual(r.referenceGamut("sRGB.gam").path, "/x/reference_gamuts/sRGB.gam")
|
|
}
|
|
}
|