Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_net/lens/js/test/harness.mjs

1.0 KiB, 1 run

created by r1870400018:65620, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1// A bare check counter for the lens tests: no dependency, one line per check, a non-zero exit
2// on any failure. The same shape as Daimond's `debugshare.test.mjs`, so a reader moving between
3// the two sees one dialect.
4let passes = 0, failures = 0;
5
6export function check(name, cond, detail) {
7 if (cond) { passes += 1; console.log(' ok ' + name); }
8 else { failures += 1; console.log(' FAIL ' + name + (detail ? ' -- ' + detail : '')); }
9}
10
11export function section(title) { console.log(title); }
12
13export function counts() { return { passes, failures }; }
14
15export function finish(label) {
16 console.log('\n' + label + ': ' + passes + ' ok, ' + failures + ' failed');
17 process.exit(failures ? 1 : 0);
18}
19
20// Runs one block of checks. A throw inside it is a failed check, not the end of the run, so a
21// stub or a half-built core reports how much of the suite it breaks rather than the first fault.
22export async function part(fn) {
23 try { await fn(); }
24 catch (e) { failures += 1; console.log(' FAIL block threw: ' + (e && e.message)); }
25}