@@ -12,6 +12,7 @@ import { coreCount, threadCount } from "../util/cpu.js";
12
12
import { diff } from "../util/text.js" ;
13
13
import { Rtrace } from "../lib/rtrace/index.js" ;
14
14
import asc from "../dist/asc.js" ;
15
+ import { exec } from "child_process" ;
15
16
16
17
const dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
17
18
const require = createRequire ( import . meta. url ) ;
@@ -143,7 +144,10 @@ async function runTest(basename) {
143
144
// Makes sure to reset the environment after
144
145
function prepareResult ( code , message = null ) {
145
146
if ( v8_no_flags ) v8 . setFlagsFromString ( v8_no_flags ) ;
146
- if ( ! args . createBinary ) fs . unlink ( path . join ( basedir , basename + ".debug.wasm" ) , err => { /* nop */ } ) ;
147
+ if ( ! args . createBinary ) {
148
+ fs . unlink ( path . join ( basedir , basename + ".debug.wasm" ) , err => { /* nop */ } ) ;
149
+ fs . unlink ( path . join ( basedir , basename + ".debug.wasm.map" ) , err => { /* nop */ } ) ;
150
+ }
147
151
return { code, message } ;
148
152
}
149
153
@@ -253,6 +257,40 @@ async function runTest(basename) {
253
257
}
254
258
compareFixture . end ( SUCCESS ) ;
255
259
}
260
+
261
+ // compare fixture source map
262
+ const sourcemapCompareFixture = section ( "compare fixture source map" ) ;
263
+ const debugWasmPath = path . join ( basedir , basename + ".debug.wasm" ) ;
264
+ const debugSourceMapPath = path . join ( basedir , basename + ".debug.wasm.map" ) ;
265
+ const sourceMapFixturePath = path . join ( basedir , basename + ".debug.sourcemap.wat" ) ;
266
+
267
+ if ( fs . existsSync ( debugSourceMapPath ) && fs . existsSync ( sourceMapFixturePath ) ) {
268
+ const sourceMapCmd = `node node_modules/.bin/wasm-opt ${ debugWasmPath } -ism ${ debugSourceMapPath } --print` ;
269
+ exec ( sourceMapCmd , ( err , stdout , stderr ) => {
270
+ const actual = stdout . toString ( ) . replace ( / \r \n / g, "\n" ) ;
271
+ if ( args . create ) {
272
+ fs . writeFileSync ( sourceMapFixturePath , actual , { encoding : "utf8" } ) ;
273
+ console . log ( " " + stdoutColors . yellow ( "Created fixture" ) ) ;
274
+ sourcemapCompareFixture . end ( SKIPPED ) ;
275
+ } else {
276
+ const expected = fs . readFileSync ( sourceMapFixturePath , { encoding : "utf8" } ) . replace ( / \r \n / g, "\n" ) ;
277
+ if ( args . noDiff ) {
278
+ if ( expected != actual ) {
279
+ compareFixture . end ( FAILURE ) ;
280
+ return prepareResult ( FAILURE , "fixture mismatch" ) ;
281
+ }
282
+ } else {
283
+ let diffs = diff ( basename + ".debug.sourcemap.wat" , expected , actual ) ;
284
+ if ( diffs !== null ) {
285
+ console . log ( diffs ) ;
286
+ compareFixture . end ( FAILURE ) ;
287
+ return prepareResult ( FAILURE , "fixture mismatch" ) ;
288
+ }
289
+ }
290
+ compareFixture . end ( SUCCESS ) ;
291
+ }
292
+ } ) ;
293
+ }
256
294
}
257
295
258
296
stdout . length = 0 ;
0 commit comments