-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update tooling and and add nix #107
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: cachix/install-nix-action@v22 | ||
with: | ||
github_access_token: ${{ secrets.GITHUB_TOKEN }} | ||
- run: nix develop --command make test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
npm-install: | ||
npm install | ||
|
||
build: npm-install | ||
elm make src/VerifyExamples.elm --output bin/elm.js --optimize | ||
|
||
verify-own-docs: build | ||
./bin/cli.js | ||
|
||
test: verify-own-docs | ||
./run-tests.sh | ||
run-examples: build | ||
cd example && ../bin/cli.js | ||
|
||
watch: | ||
watchexec \ | ||
--clear \ | ||
--restart \ | ||
--watch src \ | ||
--watch bin \ | ||
--watch example/src \ | ||
--watch elm.json \ | ||
"make test" | ||
|
||
|
||
release-major: test | ||
npx xyz --repo git@github.com:stoeffel/elm-verify-examples.git --increment major | ||
|
||
release-minor: test | ||
npx xyz --repo git@github.com:stoeffel/elm-verify-examples.git --increment minor | ||
|
||
release-patch: test | ||
npx xyz --repo git@github.com:stoeffel/elm-verify-examples.git --increment patch |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,15 +25,16 @@ var argv = require("yargs") | |||||
"elm-test-args", | ||||||
'Pass arguments to elm-test. f.e. `--elm-test-args="--report=junit"`' | ||||||
) | ||||||
.coerce("elm-test-args", function(arg) { | ||||||
.coerce("elm-test-args", function (arg) { | ||||||
if (typeof arg === "string") return arg.split(" "); | ||||||
return []; | ||||||
}) | ||||||
.default("elm-test-args", []).argv; | ||||||
|
||||||
var model = runner.init(argv); | ||||||
|
||||||
runner.run(model, function(warnings) { | ||||||
runner.run(model, function (warnings) { | ||||||
console.log("warnings", warnings); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
AFAIK it goes to stderr in node, which is probably more desirable. |
||||||
warnings.map(runner.warnModule(model)); | ||||||
if (model["run-tests"]) { | ||||||
var status = runner.runElmTest(model); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
// imports | ||
var path = require("path"); | ||
var mkdirp = require("mkdirp"); | ||
var { mkdirp } = require("mkdirp"); | ||
var fs = require("fs"); | ||
var Elm = require("./elm.js"); | ||
var helpers = require("./cli-helpers.js"); | ||
var rimraf = require("rimraf"); | ||
var { rimrafSync } = require("rimraf"); | ||
var childProcess = require("child_process"); | ||
var chalk = require("chalk"); | ||
|
||
// loaders are called by init | ||
var init = function(args) { | ||
var init = function (args) { | ||
var configJson = "elm-verify-examples.json"; | ||
var configPath = path.join(process.cwd(), args.output, configJson); | ||
var verifyExamplesConfig = helpers.loadVerifyExamplesConfig(configPath); | ||
verifyExamplesConfig.testsPath = path.join(process.cwd(), args.output); | ||
var config = forFiles(verifyExamplesConfig, args._); | ||
|
||
return Object.assign(args, config, { | ||
testsDocPath: path.join(args.output, "VerifyExamples") | ||
testsDocPath: path.join(args.output, "VerifyExamples"), | ||
}); | ||
}; | ||
|
||
|
@@ -36,17 +36,17 @@ function generate(model, allTestsGenerated) { | |
} | ||
|
||
var app = Elm.Elm.VerifyExamples.init({ flags: model }); | ||
app.ports.reportError.subscribe(function(err) { | ||
app.ports.reportError.subscribe(function (err) { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
|
||
app.ports.readFile.subscribe(function(inputName) { | ||
app.ports.readFile.subscribe(function (inputName) { | ||
if (path.extname(inputName) === ".md") { | ||
readSource(inputName, function(fileText) { | ||
readSource(inputName, function (fileText) { | ||
app.ports.generateMarkdownVerifyExamples.send({ | ||
fileName: cleanMarkdownPath(inputName), | ||
fileText: fileText | ||
fileText: fileText, | ||
}); | ||
}); | ||
} else { | ||
|
@@ -56,25 +56,25 @@ function generate(model, allTestsGenerated) { | |
elmModuleToPath(inputName) | ||
); | ||
|
||
readSource(pathToModule, function(fileText) { | ||
readSource(pathToModule, function (fileText) { | ||
app.ports.generateModuleVerifyExamples.send({ | ||
moduleName: inputName, | ||
fileText: fileText, | ||
ignoredWarnings: ignoredWarnings(model.ignoreWarnings, inputName) | ||
ignoredWarnings: ignoredWarnings(model.ignoreWarnings, inputName), | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
var warnings = []; | ||
app.ports.warn.subscribe(function(args) { | ||
app.ports.warn.subscribe(function (args) { | ||
if (args.warnings.length === 0) return; | ||
warnings.push(args); | ||
}); | ||
|
||
var writtenTests = 0; | ||
app.ports.writeFiles.subscribe(function(data) { | ||
serial(data, writeFile(model.testsDocPath), function() { | ||
app.ports.writeFiles.subscribe(function (data) { | ||
serial(data, writeFile(model.testsDocPath), function () { | ||
writtenTests = writtenTests + 1; | ||
if (writtenTests === model.tests.length && allTestsGenerated) { | ||
allTestsGenerated(warnings); | ||
|
@@ -106,16 +106,16 @@ function runElmTest(model) { | |
model.elmTestArgs.unshift(model.testsDocPath); | ||
return childProcess.spawnSync(elmTest, model.elmTestArgs, { | ||
cwd: process.cwd(), | ||
stdio: "inherit" | ||
stdio: "inherit", | ||
}).status; | ||
} | ||
|
||
function cleanup(model) { | ||
rimraf.sync(model.testsDocPath); | ||
rimrafSync(model.testsDocPath); | ||
} | ||
|
||
function warnModule(model) { | ||
return function(warnings) { | ||
return function (warnings) { | ||
if (!model.warn || warnings.warnings.length === 0) return; | ||
warn(chalk.underline("Warnings in module " + warnings.moduleName)); | ||
warn("\n"); | ||
|
@@ -126,7 +126,7 @@ function warnModule(model) { | |
|
||
function warnSummary(model, warnings) { | ||
if (!model.warn) return; | ||
var count = warnings.reduce(function(acc, warning) { | ||
var count = warnings.reduce(function (acc, warning) { | ||
return warning.warnings.length + acc; | ||
}, 0); | ||
if (count > 0) { | ||
|
@@ -151,7 +151,7 @@ function forFiles(model, files) { | |
} | ||
|
||
model.tests = files | ||
.filter(function(v) { | ||
.filter(function (v) { | ||
return v.endsWith(".elm"); | ||
}) | ||
.map(elmPathToModule(model.root, model.testsPath)); | ||
|
@@ -160,8 +160,8 @@ function forFiles(model, files) { | |
} | ||
|
||
function serial(xs, f, done) { | ||
var run = function(x, rest) { | ||
f(x, function() { | ||
var run = function (x, rest) { | ||
f(x, function () { | ||
if (rest.length > 0) { | ||
run(rest[0], rest.slice(1)); | ||
} else { | ||
|
@@ -173,7 +173,7 @@ function serial(xs, f, done) { | |
} | ||
|
||
function writeFile(testsDocPath) { | ||
return function(data, done) { | ||
return function (data, done) { | ||
var test = data.content; | ||
var parts = data.moduleName.split("."); | ||
var modulePath = []; | ||
|
@@ -188,32 +188,35 @@ function writeFile(testsDocPath) { | |
|
||
var testsDocModulePath = path.join(testsDocPath, modulePath.join("/")); | ||
|
||
mkdirp(testsDocModulePath, function(err) { | ||
if (err) { | ||
mkdirp(testsDocModulePath) | ||
.then(function () { | ||
fs.writeFile( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be easier to eventually rewrite this in async/await style, but that's perhaps for another PR... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes! |
||
path.join(testsDocModulePath, moduleName + ".elm"), | ||
test, | ||
"utf8", | ||
function (err) { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
return; | ||
} | ||
|
||
done(); | ||
} | ||
); | ||
}) | ||
.catch((err) => { | ||
console.log( | ||
chalk.red("Error creating directory: " + testsDocModulePath) | ||
); | ||
console.error(err); | ||
process.exit(1); | ||
return; | ||
} | ||
fs.writeFile( | ||
path.join(testsDocModulePath, moduleName + ".elm"), | ||
test, | ||
"utf8", | ||
function(err) { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
return; | ||
} | ||
|
||
done(); | ||
} | ||
); | ||
}); | ||
}); | ||
}; | ||
} | ||
|
||
function elmPathToModule(root, testsPath) { | ||
return function(pathName) { | ||
return function (pathName) { | ||
var relativePath = path.relative( | ||
path.resolve(path.join(testsPath, root)), | ||
pathName | ||
|
@@ -230,7 +233,7 @@ function elmModuleToPath(moduleName) { | |
} | ||
|
||
function readSource(filePath, onSuccess) { | ||
fs.readFile(filePath, "utf8", function(err, fileText) { | ||
fs.readFile(filePath, "utf8", function (err, fileText) { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
|
@@ -254,5 +257,5 @@ module.exports = { | |
cleanup: cleanup, | ||
warnModule: warnModule, | ||
warnSummary: warnSummary, | ||
runElmTest: runElmTest | ||
runElmTest: runElmTest, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking it's a good idea to declare these as
.PHONY
in a makefile, you can skip errors when a file calledtest
is accidentally created your tests won't run.