#if canImport(UIKit)importCottonValuesimportImageIOimportSwiftUIimportUniformTypeIdentifiersimport XCTest@testable importCottonUI/// A capture utility, not a guard: with `FILM_FACES_OUT=<dir>` set (through/// xcodebuild, `TEST_RUNNER_FILM_FACES_OUT`) it draws the episode face on/// the numbers of the Codex round 2 design (series-1) — on its stock, a 360 x 450 card at scale 3 — into `<dir>`/// so they are laid beside the designs. Every title and name is invented./// With `FACES_ART` (passed as `TEST_RUNNER_FACES_ART`) each keeps its/// design's still, else none. Without the out variable it skips.@MainActorfinalclassFilmDesignShotsTests: XCTestCase {func testDrawTheFilmDesigns() throws {guardlet dir = ProcessInfo.processInfo.environment["FILM_FACES_OUT"], !dir.isEmpty else {throw XCTSkip("set FILM_FACES_OUT=<dir> to draw the film designs") }let out = URL(fileURLWithPath: dir, isDirectory: true)tryFileManager.default.createDirectory(at: out, withIntermediateDirectories: true)// No still: the episode draws its television, never a real actor's likeness.let episode = DeckCard(face: .episode, fields: ["title": .text("Cicadas"), "source": .text("Invented Precinct"), "subtitle": .text("S2 \u{00B7} E3"),"length": .text("48 min"), "place": .text("aired 2022"), "date": .text("Mon 12 Oct"), "count": .number(4), ]) shoot("series-1", episode, EpisodeFace(card: episode, still: picture(episode)), to: out) }/// The record's own picture, as the deck hands it to a face.privatefunc picture(_ card: DeckCard) -> PagePicture? { card.text("photo").map { PagePicture(key: $0, edge: DeckFaceKnobs.photoEdge) } }privatefunc shoot(_ name: String, _ card: DeckCard, _ face: someView, to out: URL) {let theme = Theme.paperlet renderer = ImageRenderer(content: face .environment(\.theme, theme) .environment(\.colorScheme, .light) .environment(\.facePictures, FacesArt.picture) .frame(width: 360, height: 450) .background(theme.colors.paper.color)) renderer.scale = 3guardlet image = renderer.cgImage,let dest = CGImageDestinationCreateWithURL(out.appendingPathComponent("\(name).png") as CFURL, UTType.png.identifier as CFString, 1, nil)else { return XCTFail("\(name) drew nothing") } CGImageDestinationAddImage(dest, image, nil) XCTAssertTrue(CGImageDestinationFinalize(dest), "\(name) was not written") }}#endif