From dc563de9378993f666f27bef715bc425a7711f45 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Fri, 10 Nov 2023 10:26:53 -0300 Subject: tests/assert-install.sh: Always to enforce correct installation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also in this change: - now we call ln(1) in the "install" target without using the -r "relative" flag, as it isn't POSIX; - add `+` as a prefix to the "assert-tests" command, so we tell sub-make calls to also run things in parallel. In this case, the "make DESTDIR=... install" calls; - use the implicit `index.js` entrypoint and do away completly with `package.json`; - change from `import` to `require` as Node.js ESM modules don't support `$NODE_PATH`[0]: "NODE_PATH is not part of resolving import specifiers. Please use symlinks if this behavior is desired." 🤦; The parallel sub-make behaviour isn't available in current specification of make (POSIX issue 7) but is included in the upcoming[1] version 8: > If a rule invokes a sub-make either via the MAKE macro or via a > command line that begins with '+', the sub-make is the same > implementation as the make that invoked the sub-make, and the −j > option is passed to the sub-make via the MAKEFLAGS environment > variable with the same maxjobs value and is not overridden by a > maxjobs value from another source (even if it has the same value), the > sub-make shall use the same token pool as its invoking make rather > than create a new token pool. [0]: https://nodejs.org/api/esm.html#no-node_path [1]: https://www.opengroup.org/austin/restricted/202x-d3/202x_d3.pdf --- src/api.js | 18 ++++++++++++++++-- src/cli.js | 2 +- src/utils.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 src/utils.js (limited to 'src') diff --git a/src/api.js b/src/api.js index 1ce7bcc..99ba01c 100644 --- a/src/api.js +++ b/src/api.js @@ -1,3 +1,17 @@ -export const main = async () => { - console.log({ argv: process.argv }); +const { eq } = require("./utils.js"); + +const main = async () => { + if (process.argv.length !== 2) { + console.log("papo 1970-01-01 0.1.0"); + return; + } + + console.log({ + argv: process.argv, + eq: eq({a: 1}, {a: 1}), + }); +}; + +module.exports = { + main, }; diff --git a/src/cli.js b/src/cli.js index aa602f7..2b486fe 100755 --- a/src/cli.js +++ b/src/cli.js @@ -1,4 +1,4 @@ #!/usr/bin/env node -import { main } from "papo"; +const { main } = require("papo"); (async () => await main())(); diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..1877a58 --- /dev/null +++ b/src/utils.js @@ -0,0 +1,43 @@ +const eq = (a, b) => { + if (a === b) { + return true; + } + + if (a === null || b === null) { + return false; + } + + if (typeof a != "object" || typeof b != "object") { + return false; + } + + if (Array.isArray(a) !== Array.isArray(b)) { + return false; + } + + if (Object.keys(a).length !== Object.keys(b).length) { + return false; + } + + for (const k in a) { + if (!b.hasOwnProperty(k)) { + return false; + } + if (!eq(a[k], b[k])) { + return false; + } + } + return true; +}; + +const keys = (ks, obj) => + ks.reduce( + (ret, k) => + obj.hasOwnProperty(k) ? {...ret, [k]: obj[k]} : ret, + {}, + ); + +module.exports = { + eq, + keys, +}; -- cgit v1.2.3