Skip to content

Commit f0851c7

Browse files
committed
Refactor tests to use NodeJS's built-in test runner
1 parent 461e5a8 commit f0851c7

File tree

10 files changed

+235
-375
lines changed

10 files changed

+235
-375
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2+
"type": "module",
23
"scripts": {
34
"build": "esbuild --bundle --sourcemap --outfile=gh-pages/index.js gh-pages/editor.js && esbuild --bundle --outfile=gh-pages/make_editor_out.js gh-pages/make_editor.js",
45
"dev": "esbuild --banner:js=\"\\\"use strict\\\";\" --bundle --sourcemap --servedir=gh-pages --outfile=gh-pages/index.js gh-pages/editor.js",
5-
"test": "node tests.js"
6+
"test": "node --test t/*.js"
67
},
78
"dependencies": {
89
"@codemirror/autocomplete": "",

t/basic.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
#!/usr/bin/env node
2-
"use strict";
3-
// Sample code testing
4-
5-
exports.run = async function()
6-
{
7-
const { AssemblyState } = await import("@defasm/core");
8-
let attState = new AssemblyState(), intelState = new AssemblyState();
1+
import { test } from "node:test";
2+
import assert from "node:assert";
3+
4+
import { AssemblyState } from "@defasm/core";
5+
6+
test("Sample code testing", () => {
7+
const attState = new AssemblyState(), intelState = new AssemblyState();
98
attState.compile(`\
109
.att_syntax
1110
SYS_WRITE = 1
@@ -138,11 +137,5 @@ exports.run = async function()
138137
mov edi, 0
139138
syscall`, { haltOnError: true });
140139

141-
if(!attState.head.dump().equals(intelState.head.dump()))
142-
throw `Discrepancy between AT&T and Intel output`;
143-
}
144-
145-
if(require.main === module)
146-
{
147-
exports.run().then(x => process.exit(0)).catch(x => { console.error(x); process.exit(1) });
148-
}
140+
assert(attState.head.dump().equals(intelState.head.dump()), "Discrepancy between AT&T and Intel output");
141+
});

t/exit.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
#!/usr/bin/env node
2-
"use strict";
3-
// Exit status propagation test
1+
import { test } from "node:test";
2+
import assert from "node:assert";
43

5-
exports.run = async function()
6-
{
7-
const { AssemblyState, Range } = await import("@defasm/core");
8-
const { createExecutable, debug } = await import("@defasm/cli");
9-
let outputFile = "/tmp/asm";
10-
let state = new AssemblyState();
4+
import { AssemblyState, Range } from "@defasm/core";
5+
import { createExecutable, debug } from "@defasm/cli";
6+
7+
test("Exit status propagation test", { skip: process.platform != 'linux' }, () => {
8+
const outputFile = "/tmp/asm";
9+
const state = new AssemblyState();
1110
state.compile(`\
1211
EXIT_STATUS = 0
1312
mov $60, %eax
@@ -17,15 +16,7 @@ syscall`);
1716
{
1817
state.compile(i.toString(), { range: new Range("EXIT_STATUS = ".length, j.toString().length) });
1918
createExecutable(outputFile, state);
20-
let status = debug(outputFile, [], state);
21-
if(status !== i)
22-
throw `Discrepancy between written exit status and output: ${status} != ${i}`;
19+
const status = debug(outputFile, [], state);
20+
assert.equal(status, i);
2321
}
24-
}
25-
26-
exports.linuxOnly = true;
27-
28-
if(require.main === module)
29-
{
30-
exports.run().then(x => process.exit(0)).catch(x => { console.error(x); process.exit(1) });
31-
}
22+
});

0 commit comments

Comments
 (0)