Skip to content

Commit

Permalink
Less fragile test
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-y committed Sep 4, 2024
1 parent 4bffc8d commit fac1431
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 37 deletions.
32 changes: 0 additions & 32 deletions src/__tests__/__snapshots__/compiler.test.ts.snap

This file was deleted.

9 changes: 5 additions & 4 deletions src/__tests__/compiler.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { e2eVoidText, gcVoidText, tcoText } from "./fixtures/e2e-file.js";
import { compile } from "../compiler.js";
import { describe, expect, test } from "vitest";
import { describe, expect, test, vi } from "vitest";
import assert from "node:assert";
import { getWasmFn, getWasmInstance } from "../lib/wasm.js";
import * as rCallUtil from "../assembler/return-call.js";

describe("E2E Compiler Pipeline", () => {
test("Compiler can compile and run a basic void program", async (t) => {
Expand Down Expand Up @@ -37,8 +38,8 @@ describe("E2E Compiler Pipeline", () => {
});

test("Compiler can do tco", async (t) => {
const mod = await compile(tcoText);
mod.optimize();
t.expect(mod.emitText()).toMatchSnapshot();
const spy = vi.spyOn(rCallUtil, "returnCall");
await compile(tcoText);
t.expect(spy).toHaveBeenCalledTimes(1);
});
});
3 changes: 2 additions & 1 deletion src/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { HeapTypeRef } from "./lib/binaryen-gc/types.js";
import { getExprType } from "./semantics/resolution/get-expr-type.js";
import { Match, MatchCase } from "./syntax-objects/match.js";
import { initExtensionHelpers } from "./assembler/extension-helpers.js";
import { returnCall } from "./assembler/return-call.js";

export const assemble = (ast: Expr) => {
const mod = new binaryen.Module();
Expand Down Expand Up @@ -182,7 +183,7 @@ const compileCall = (opts: CompileExprOpts<Call>): number => {
const returnType = mapBinaryenType(opts, expr.fn!.returnType!);

if (isReturnExpr && id === expr.parentFn?.id) {
return mod.return_call(id, args, returnType);
return returnCall(mod, id, args, returnType);
}

return mod.call(id, args, returnType);
Expand Down
11 changes: 11 additions & 0 deletions src/assembler/return-call.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import binaryen from "binaryen";
import { ExpressionRef, TypeRef } from "../lib/binaryen-gc/types.js";

export const returnCall = (
mod: binaryen.Module,
fnId: string,
args: ExpressionRef[],
returnType: TypeRef
) => {
return mod.return_call(fnId, args, returnType);
};

0 comments on commit fac1431

Please sign in to comment.