Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: add reason argument to assert import #5

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/basic/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare module "main" {

declare module "xtp:test" {
interface harness {
assert(name: PTR, value: I64);
assert(name: PTR, value: I64, reason: PTR);
call(func: PTR, input: PTR): PTR;
time(func: PTR, input: PTR): I64;
group(name: PTR);
Expand Down
Binary file modified examples/basic/test.wasm
Binary file not shown.
17 changes: 12 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,25 @@ export class Test {
return Test.call(funcName, input).readBuffer();
}

static assert(msg: string, value: boolean) {
static assert(name: string, value: boolean, reason: string) {
// @ts-ignore: Memory
const a = Memory.fromString(msg);
assert(a.offset, !!value);
const a = Memory.fromString(name);
// @ts-ignore: Memory
const b = Memory.fromString(reason);
assert(a.offset, !!value, b.offset);
a.free();
b.free();
}

static assertEqual(msg: string, x: unknown, y: unknown) {
Test.assert(msg, x === y);
const stack = new Error().stack;
stack.trim();
Test.assert(msg, x === y, `Expected ${x} === ${y}\n${stack}`);
}

static assertNotEqual(msg: string, x: unknown, y: unknown) {
Test.assert(msg, x !== y);
const stack = new Error().stack;
stack.trim();
Test.assert(msg, x !== y, `Expected ${x} !== ${y}\n${stack}`);
}
}
2 changes: 1 addition & 1 deletion test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare module "main" {

declare module "xtp:test" {
interface harness {
assert(name: PTR, value: I64);
assert(name: PTR, value: I64, reason: PTR);
call(func: PTR, input: PTR): PTR;
time(func: PTR, input: PTR): I64;
group(name: PTR);
Expand Down