Skip to content

Commit

Permalink
fix: add source map check for compiler test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Chen committed Apr 20, 2023
1 parent fd0e456 commit d1acdfa
Show file tree
Hide file tree
Showing 6 changed files with 9,045 additions and 1 deletion.
40 changes: 39 additions & 1 deletion tests/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { coreCount, threadCount } from "../util/cpu.js";
import { diff } from "../util/text.js";
import { Rtrace } from "../lib/rtrace/index.js";
import asc from "../dist/asc.js";
import {exec} from "child_process";

const dirname = path.dirname(fileURLToPath(import.meta.url));
const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -143,7 +144,10 @@ async function runTest(basename) {
// Makes sure to reset the environment after
function prepareResult(code, message = null) {
if (v8_no_flags) v8.setFlagsFromString(v8_no_flags);
if (!args.createBinary) fs.unlink(path.join(basedir, basename + ".debug.wasm"), err => { /* nop */ });
if (!args.createBinary) {
fs.unlink(path.join(basedir, basename + ".debug.wasm"), err => { /* nop */ });
fs.unlink(path.join(basedir, basename + ".debug.wasm.map"), err => { /* nop */ });
}
return { code, message };
}

Expand Down Expand Up @@ -253,6 +257,40 @@ async function runTest(basename) {
}
compareFixture.end(SUCCESS);
}

// compare fixture source map
const sourcemapCompareFixture = section("compare fixture source map");
const debugWasmPath = path.join(basedir, basename + ".debug.wasm");
const debugSourceMapPath = path.join(basedir, basename + ".debug.wasm.map");
const sourceMapFixturePath = path.join(basedir, basename + ".debug.sourcemap.wat");

if (fs.existsSync(debugSourceMapPath) && fs.existsSync(sourceMapFixturePath)) {
const sourceMapCmd = `node node_modules/.bin/wasm-opt ${debugWasmPath} -ism ${debugSourceMapPath} --print`;
exec(sourceMapCmd, (err, stdout, stderr) => {
const actual = stdout.toString().replace(/\r\n/g, "\n");
if (args.create) {
fs.writeFileSync(sourceMapFixturePath, actual, { encoding: "utf8" });
console.log(" " + stdoutColors.yellow("Created fixture"));
sourcemapCompareFixture.end(SKIPPED);
} else {
const expected = fs.readFileSync(sourceMapFixturePath, { encoding: "utf8" }).replace(/\r\n/g, "\n");
if (args.noDiff) {
if (expected != actual) {
compareFixture.end(FAILURE);
return prepareResult(FAILURE, "fixture mismatch");
}
} else {
let diffs = diff(basename + ".debug.sourcemap.wat", expected, actual);
if (diffs !== null) {
console.log(diffs);
compareFixture.end(FAILURE);
return prepareResult(FAILURE, "fixture mismatch");
}
}
compareFixture.end(SUCCESS);
}
});
}
}

stdout.length = 0;
Expand Down
Loading

0 comments on commit d1acdfa

Please sign in to comment.