diff --git a/tests/$shared.ts b/tests/$shared.ts index ea8c9a5d..ae27545d 100644 --- a/tests/$shared.ts +++ b/tests/$shared.ts @@ -220,6 +220,35 @@ export const test = createTestFn(); //=== +// [`bmp`](https://deno.land/x/bmp@v0.0.7); install (for Deno-v1.11+/std@0.98.0)
`dxi --allow-read=. --allow-write=. --allow-run=git -qf https://deno.land/x/bmp@v0.0.7/cli.ts` + +export const haveBmpVersion = () => { + try { + // deno-lint-ignore no-deprecated-deno-api + const process = Deno.run({ + cmd: [...(isWinOS ? ['cmd', '/x/d/c'] : []), 'bmp', '--version'], + stdin: 'null', + stderr: 'null', + stdout: 'piped', + }); + return Promise + .all([process.status(), process.output()]) + .then(([status, out]) => { + // console.debug({ status: status, out: decode(out) }); + return (status.success + ? ((decode(out)?.match(/(?:^|@)(\d+(?:[.]\d+)+)/) || [])[1]) + : undefined); + }) + .finally(() => process.close()); + } catch (_) { + return Promise.resolve(undefined); + } +}; + +export const haveBmp = () => { + return haveBmpVersion().then((version) => version != null); +}; + // [`commitlint`](https://commitlint.js.org); install (for NodeJS v12+): `npm -g install @commitlint/cli@16 @commitlint/config-conventional@16` export const haveCommitLintVersion = () => { diff --git a/tests/00.project.style.test.ts b/tests/00.project.style.test.ts index fd054d11..a6834e0f 100644 --- a/tests/00.project.style.test.ts +++ b/tests/00.project.style.test.ts @@ -7,6 +7,7 @@ // import { $colors } from './$deps.ts'; import { $args, $path, assert, assertEquals, equal } from './$deps.ts'; import { + haveBmp, haveCommitLint, haveCSpell, haveCSpellVersion, @@ -137,6 +138,34 @@ const projectNonBinaryFiles = projectFiles.filter((file) => // console.warn({ projectFiles, projectDirs }); // console.warn({ projectPath, projectDirs }); +{ + // ToDO: [2023-10-10; rivy] deal with CWD != projectPath + const command = 'bmp'; + const haveCommand = await haveBmp(); + const exeArgs = ['--info']; + const exeCmd = [command, ...exeArgs].join(' '); + const cmd = [...(isWinOS ? ['cmd', '/x/d/c'] : []), exeCmd]; + const description = `style ~ \`${exeCmd}\``; + if (!haveCommand) { + test.skip(description + `...skipped (\`${command}\` not found)`); + } else { + test(description, async () => { + // deno-lint-ignore no-deprecated-deno-api + const p = Deno.run({ cmd, stdin: 'null', stdout: 'piped', stderr: 'piped' }); + const [status, out, err] = await Promise + .all([p.status(), p.output(), p.stderrOutput()]) + .finally(() => p.close()); + // console.debug({ status, stdout: decode(out), stderr: decode(err) }); + if (!status.success) { + console.warn(`\`${command}\` status`, status); + console.warn(decode(out).replace(/\r?\n$/ms, '')); + console.warn(decode(err).replace(/\r?\n$/ms, '')); + } + assert(status.success, `\`${command}\` check succeeds`); + }); + } +} + { // ToDO: [2023-10-03; rivy] add `--cwd ` to commitlint command (as needed, if CWD != projectPath) // ToDO: [2023-10-03; rivy] check for correct configuration; present and working config file (including plugins; may use `commitlint --config .commitlint.config.js --print-config`)