From 2f2ab5149701243647a5f8d60dc9f771e45b2a5a Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 24 May 2022 23:40:16 -0500 Subject: add hacky frameworkless unit testing --- modules/test-assert.js | 21 +++++++++++++++++++++ test.js | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 modules/test-assert.js create mode 100644 test.js diff --git a/modules/test-assert.js b/modules/test-assert.js new file mode 100644 index 0000000..7be2989 --- /dev/null +++ b/modules/test-assert.js @@ -0,0 +1,21 @@ +import { strict as assert } from 'node:assert'; + +function test(description, func) +{ + process.stdout.write(description); + let error = null; + try { + func(); + } + catch(err) { + error = err; + } + + if (error) { + console.log(' - FAIL'); + console.log(error); + } + else console.log(' - OK'); +} + +export { test, assert }; diff --git a/test.js b/test.js new file mode 100644 index 0000000..b7c1e58 --- /dev/null +++ b/test.js @@ -0,0 +1,22 @@ +import fs from 'node:fs'; +import { execSync } from 'node:child_process'; + +function recursiveScanDir(path, f) +{ + let dirs = []; + for (let dirent of fs.readdirSync(path, { withFileTypes: true })) { + if (dirent.isDirectory()) dirs.push(`${path}/${dirent.name}`); + else f(`${path}/${dirent.name}`); + } + for (let dir of dirs) { + recursiveScanDir(dir, f); + } +} + +recursiveScanDir('./modules', fname => { + if (fname.endsWith('.test.js')) { + console.log(`======== ${fname} ========`); + execSync(`node ${fname}`, { stdio: 'inherit' }); + console.log(''); + } +}); -- cgit v1.2.1