diff --git a/Tests/TortoiseUITests/TortoiseSpriteTests.swift b/Tests/TortoiseUITests/TortoiseSpriteTests.swift index 55511ec..7dfb4d9 100644 --- a/Tests/TortoiseUITests/TortoiseSpriteTests.swift +++ b/Tests/TortoiseUITests/TortoiseSpriteTests.swift @@ -1,4 +1,5 @@ import CoreGraphics +import Foundation import SwiftUI import Testing import TortoiseCore @@ -66,25 +67,51 @@ extension CGSize { @Suite("Tortoise sprite canvas snapshots") @MainActor struct TortoiseSpriteCanvasTests { - /// An asymmetric, up-pointing sprite built in code (no test resource): - /// a red top half over a blue bottom half, so a golden image shows both - /// that the artwork is drawn and which way it is rotated. - private static func spriteImage(width: Double, height: Double) -> Image? { - let content = VStack(spacing: 0) { - Rectangle().fill(Color.red) - Rectangle().fill(Color.blue) + /// An asymmetric, up-pointing sprite: a red top half over a blue bottom + /// half, so a golden image shows both that the artwork is drawn and + /// which way it is rotated. + /// + /// The pixels are written out explicitly in sRGB rather than rendered + /// from a SwiftUI view. `ImageRenderer` was used at first and made the + /// goldens machine-dependent: `Color.red` / `Color.blue` are semantic + /// colors whose components depend on the display gamut and appearance, + /// and `ImageRenderer.nsImage` hands back a bitmap tagged with the + /// host's display profile — so the goldens recorded on a P3 Mac failed + /// on CI with a pure color shift (perceptual precision 0.956). + private static func spriteImage(pixelWidth: Int, pixelHeight: Int) -> Image? { + let bytesPerPixel = 4 + var pixels = [UInt8](repeating: 0, count: pixelWidth * pixelHeight * bytesPerPixel) + for y in 0..