From fa9034e7cf8dec061137d913950b69fa19a2fc01 Mon Sep 17 00:00:00 2001 From: Stoeffel Date: Wed, 10 Jan 2024 10:36:45 +0100 Subject: [PATCH] Verify all elm files --- CHANGELOG.md | 6 + Readme.md | 16 ++ bin/cli-helpers.js | 31 ++-- bin/runner.js | 9 +- bin/templates/elm-verify-examples.json | 3 - example/tests/elm-verify-examples.json | 23 --- package-lock.json | 216 ++++++------------------- package.json | 1 + run-tests.sh | 4 +- src/VerifyExamples.elm | 5 +- 10 files changed, 106 insertions(+), 208 deletions(-) delete mode 100644 bin/templates/elm-verify-examples.json delete mode 100644 example/tests/elm-verify-examples.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 167f995..de32f6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## 6.0.0 +- Add option `all` to `elm-verify-examples.json` to verify all elm files. + + ```diff + + "tests": "all" + ``` + - Remove `root` from elm-verify-examples.json. In addition it will respect source-directories defined in elm.json [#109](https://github.com/stoeffel/elm-verify-examples/pull/109) To migrate, remove the "root" key in your config file and move it into `/tests`. diff --git a/Readme.md b/Readme.md index 9d99594..fe07270 100644 --- a/Readme.md +++ b/Readme.md @@ -28,6 +28,22 @@ $ touch tests/elm-verify-examples.json } ``` +Alternatively you can run elm-verify-examples on all elm files in your source directories: + +```json +{ + "tests": "all" +} +``` + +or + +```json +{ + "tests": ["all", "Some.md"] +} +``` + It's recommended to add `./tests/VerifyExamples` to your `.gitignore`. If you are building a _package_, you can pass the string `"exposed"` instead of an explicit list of modules, diff --git a/bin/cli-helpers.js b/bin/cli-helpers.js index ba0aff9..c453c42 100644 --- a/bin/cli-helpers.js +++ b/bin/cli-helpers.js @@ -1,5 +1,6 @@ var path = require("path"); var fsExtra = require("fs-extra"); +const { globSync } = require("glob"); function loadVerifyExamplesConfig(configPath) { /* load the doc test config if we can find it @@ -19,23 +20,16 @@ function loadVerifyExamplesConfig(configPath) { var elmJsonPath = findParentElmJson(path.dirname(configPath)); elmJson = require(elmJsonPath); } catch (e) { - console.log(`Copying initial elm-verify-examples.json to ${configPath}`); - fsExtra.copySync( - path.resolve(__dirname, "./templates/elm-verify-examples.json"), - configPath - ); - - verifyExamples = require(path.resolve( - __dirname, - "templates/elm-verify-examples.json" - )); + var elmJsonPath = findParentElmJson(path.dirname(configPath)); + elmJson = require(elmJsonPath); + verifyExamples = { tests: "all" }; } return resolveTests(configPath, Object.assign({}, verifyExamples, elmJson)); } function resolveTests(configPath, config) { - if (config.tests === "exposed") { + if (config.tests === "exposed" || config.tests.includes("exposed")) { if (config.type == "package") { config.tests = config["exposed-modules"].concat("./README.md"); } else { @@ -45,6 +39,17 @@ function resolveTests(configPath, config) { process.exit(1); } } + if (config.tests === "all" || config.tests.includes("all")) { + var allElmFiles = config["source-directories"] + .map((d) => + globSync("**/*.elm", { + cwd: path.join(path.dirname(configPath), "..", d), + }) + ) + .flat() + .map(elmPathToModuleName); + config.tests = allElmFiles.concat("./README.md"); + } return config; } @@ -59,6 +64,10 @@ function findParentElmJson(p) { } } +function elmPathToModuleName(pathName) { + return pathName.slice(0, -4).replace(/\//g, "."); +} + module.exports = { loadVerifyExamplesConfig: loadVerifyExamplesConfig, }; diff --git a/bin/runner.js b/bin/runner.js index 5e1b0ff..82bffb2 100644 --- a/bin/runner.js +++ b/bin/runner.js @@ -73,10 +73,17 @@ function generate(model, allTestsGenerated) { }); var writtenTests = 0; + var noExamples = 0; + app.ports.noExamples.subscribe(function () { + noExamples = noExamples + 1; + }); app.ports.writeFiles.subscribe(function (data) { serial(data, writeFile(model.testsDocPath), function () { writtenTests = writtenTests + 1; - if (writtenTests === model.tests.length && allTestsGenerated) { + if ( + writtenTests + noExamples === model.tests.length && + allTestsGenerated + ) { allTestsGenerated(warnings); } }); diff --git a/bin/templates/elm-verify-examples.json b/bin/templates/elm-verify-examples.json deleted file mode 100644 index 08b8a0e..0000000 --- a/bin/templates/elm-verify-examples.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "tests": [] -} diff --git a/example/tests/elm-verify-examples.json b/example/tests/elm-verify-examples.json deleted file mode 100644 index 0861269..0000000 --- a/example/tests/elm-verify-examples.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "tests": [ - "Mock", - "Mock.Foo.Bar.Moo", - "Robustness", - "Failing", - "Todo", - "FalseTodo", - "README.md", - "Other" - ], - "ignoreWarnings": { - "Mock.Foo.Bar.Moo": [ - { - "name": "dontCare", - "ignore": ["NoExampleForExposedDefinition"] - }, - { - "ignore": ["ExposingDotDot"] - } - ] - } -} diff --git a/package-lock.json b/package-lock.json index 7fde1da..dd6fe77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "chalk": "^4.1.2", "elm-test": "^0.19.1-revision7", "fs-extra": "^11.1.1", + "glob": "^10.3.10", "mkdirp": "^3.0.1", "rimraf": "^5.0.5", "yargs": "^17.7.2" @@ -440,21 +441,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/@tufjs/models/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/@types/http-cache-semantics": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.3.tgz", @@ -776,43 +762,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/cacache/node_modules/glob": { - "version": "10.3.10", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", - "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", - "dev": true, - "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^2.3.5", - "minimatch": "^9.0.1", - "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", - "path-scurry": "^1.10.1" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/cacache/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/cacache/node_modules/minipass": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", @@ -1211,6 +1160,35 @@ "node": ">=12.20.0" } }, + "node_modules/elm-test/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/elm-test/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -1457,18 +1435,21 @@ } }, "node_modules/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "version": "10.3.10", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", + "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" + "foreground-child": "^3.1.0", + "jackspeak": "^2.3.5", + "minimatch": "^9.0.1", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", + "path-scurry": "^1.10.1" + }, + "bin": { + "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=12" + "node": ">=16 || 14 >=14.17" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -1695,21 +1676,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/ignore-walk/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/import-lazy": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-4.0.0.tgz", @@ -2126,14 +2092,17 @@ } }, "node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", "dependencies": { "brace-expansion": "^2.0.1" }, "engines": { - "node": ">=10" + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/minimist": { @@ -2618,21 +2587,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/npm-check-updates/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/npm-check-updates/node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -3122,43 +3076,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/read-package-json/node_modules/glob": { - "version": "10.3.10", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", - "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", - "dev": true, - "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^2.3.5", - "minimatch": "^9.0.1", - "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", - "path-scurry": "^1.10.1" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/read-package-json/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", @@ -3294,41 +3211,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/rimraf/node_modules/glob": { - "version": "10.3.10", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", - "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", - "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^2.3.5", - "minimatch": "^9.0.1", - "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", - "path-scurry": "^1.10.1" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/rimraf/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", diff --git a/package.json b/package.json index bc6db86..5dd7e53 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "chalk": "^4.1.2", "elm-test": "^0.19.1-revision7", "fs-extra": "^11.1.1", + "glob": "^10.3.10", "mkdirp": "^3.0.1", "rimraf": "^5.0.5", "yargs": "^17.7.2" diff --git a/run-tests.sh b/run-tests.sh index 4a091ab..8c5ab5c 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -PASSED_COUNT=34 -FAILED_COUNT=3 +PASSED_COUNT=35 +FAILED_COUNT=5 TODO_COUNT=1 pushd example diff --git a/src/VerifyExamples.elm b/src/VerifyExamples.elm index 3044af4..f4446cb 100644 --- a/src/VerifyExamples.elm +++ b/src/VerifyExamples.elm @@ -89,7 +89,7 @@ generateTests : List Compiler.Result -> Cmd Msg generateTests tests = case tests of [] -> - Cmd.none + noExamples () _ -> tests @@ -137,6 +137,9 @@ port readFile : String -> Cmd msg port writeFiles : Value -> Cmd msg +port noExamples : () -> Cmd msg + + port generateModuleVerifyExamples : (Value -> msg) -> Sub msg