From a6896054e73f7db1d82eba03a379efb74db14d40 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 4 Dec 2026 15:35:05 +0800 Subject: [PATCH] test(targets): share single-architecture fixtures (#16642) --- .../binary/TargetFormatVocabularies.test.ts | 66 +++++++------------ 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/src/application/binary/TargetFormatVocabularies.test.ts b/src/application/binary/TargetFormatVocabularies.test.ts index c21dd21490f..37e74ef2a53 100644 --- a/src/application/binary/TargetFormatVocabularies.test.ts +++ b/src/application/binary/TargetFormatVocabularies.test.ts @@ -34,14 +34,26 @@ const identity = { path: "/fixture/target", sha256: "a".repeat(64) } as const; const archive = { ...identity, kind: "archive" } as const; const artifact = { ...identity, kind: "artifact" } as const; -const TARGETS: TargetFixtures = { - "mach-o": { +const singleArchitectureTarget = < + Format extends TargetFormat, + Architecture extends Extract< + BinaryTarget, + { kind: "executable" } + >["architecture"], +>( + format: Format, + architecture: Architecture, +) => + ({ ...identity, kind: "executable", - format: "mach-o", - architecture: "arm64", - availableArchitectures: ["arm64"], - }, + format, + architecture, + availableArchitectures: [architecture], + }) as const; + +const TARGETS: TargetFixtures = { + "mach-o": singleArchitectureTarget("mach-o", "arm64"), "mach-o-universal": { ...identity, kind: "executable", @@ -50,51 +62,21 @@ const TARGETS: TargetFixtures = { availableArchitectures: ["x86_64", "arm64"], universalSlice: { offset: 0x4000, size: 0x4000 }, }, - elf: { - ...identity, - kind: "executable", - format: "elf", - architecture: "x86_64", - availableArchitectures: ["x86_64"], - }, + elf: singleArchitectureTarget("elf", "x86_64"), pe: { - ...identity, - kind: "executable", - format: "pe", - architecture: "x86_64", - availableArchitectures: ["x86_64"], + ...singleArchitectureTarget("pe", "x86_64"), executableRole: "application", managed: false, }, - "dos-mz": { - ...identity, - kind: "executable", - format: "dos-mz", - architecture: "x86", - availableArchitectures: ["x86"], - }, - "dos-com": { - ...identity, - kind: "executable", - format: "dos-com", - architecture: "x86", - availableArchitectures: ["x86"], - }, + "dos-mz": singleArchitectureTarget("dos-mz", "x86"), + "dos-com": singleArchitectureTarget("dos-com", "x86"), // A raw-only family: detected formats must not admit it. "raw-binary": { - ...identity, - kind: "executable", - format: "raw-binary", - architecture: "m68k", - availableArchitectures: ["m68k"], + ...singleArchitectureTarget("raw-binary", "m68k"), rawLoad: rawLoadAtEntry("0x1000"), }, "gamecube-dol": { - ...identity, - kind: "executable", - format: "gamecube-dol", - architecture: "powerpc", - availableArchitectures: ["powerpc"], + ...singleArchitectureTarget("gamecube-dol", "powerpc"), byteOrder: "big", bits: 32, entryPoint: "0x80003100",