@@ -2,6 +2,7 @@ import { globSync, readFileSync, writeFileSync } from "node:fs";
22import * as path from "node:path" ;
33import { dirname , resolve } from "node:path" ;
44import { fileURLToPath } from "node:url" ;
5+ import { expect } from "vitest" ;
56
67const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
78const RELATIVE_FLOAT_TOLERANCE = 0.0001 / 100 ;
@@ -44,29 +45,57 @@ export function writeActualOutput(
4445 return actualFile ;
4546}
4647
48+ export type TestCase = { name : string ; content : object ; fileName : string } ;
49+
4750export function getTestCases ( skipList : string [ ] ) : {
48- active : { name : string ; content : object ; fileName : string } [ ] ;
49- skipped : string [ ] ;
51+ active : TestCase [ ] ;
52+ skipped : TestCase [ ] ;
5053} {
5154 const syntheticDir = resolve ( __dirname , ".." ) ;
5255 const mltFiles = globSync ( `**/*.mlt` , {
5356 cwd : syntheticDir ,
5457 } ) . map ( ( mltFile : string ) => path . join ( syntheticDir , mltFile ) ) ;
5558
56- const active : { name : string ; content : object ; fileName : string } [ ] = [ ] ;
57- const skipped : string [ ] = [ ] ;
59+ const active : TestCase [ ] = [ ] ;
60+ const skipped : TestCase [ ] = [ ] ;
61+ const matched = new Set < string > ( ) ;
5862
5963 for ( const mltFile of mltFiles ) {
6064 const testName = path . relative ( syntheticDir , mltFile ) . replace ( / \. m l t $ / , "" ) ;
65+ const jsonFile = mltFile . replace ( / \. m l t $ / , ".json" ) ;
66+ const expected = JSON . parse ( readFileSync ( jsonFile , "utf-8" ) ) ;
67+ const testCase = { name : testName , fileName : mltFile , content : expected } ;
6168 if ( skipList . includes ( testName ) ) {
62- skipped . push ( testName ) ;
69+ matched . add ( testName ) ;
70+ skipped . push ( testCase ) ;
6371 } else {
64- const jsonFile = mltFile . replace ( / \. m l t $ / , ".json" ) ;
65- const expectedRaw = readFileSync ( jsonFile , "utf-8" ) ;
66- const expected = JSON . parse ( expectedRaw ) ;
67- active . push ( { name : testName , fileName : mltFile , content : expected } ) ;
72+ active . push ( testCase ) ;
6873 }
6974 }
7075
76+ const unmatched = skipList . filter ( ( name ) => ! matched . has ( name ) ) ;
77+ if ( unmatched . length > 0 ) {
78+ throw new Error (
79+ `Exclusion list references unknown synthetic test(s): ${ unmatched . join ( ", " ) } . ` +
80+ `Use the full path-style name, e.g. "0x01/poly_fpf".` ,
81+ ) ;
82+ }
83+
7184 return { active, skipped } ;
7285}
86+
87+ export async function expectUnsupported (
88+ decode : ( ) => Promise < unknown > ,
89+ content : object ,
90+ ) : Promise < void > {
91+ let actual : unknown ;
92+ try {
93+ actual = await decode ( ) ;
94+ } catch {
95+ return ;
96+ }
97+ expect (
98+ actual ,
99+ "decoded and matched the expected output — remove it from the exclusion list" ,
100+ ) . not . toEqual ( content ) ;
101+ }
0 commit comments