Skip to content

Commit

Permalink
Merge pull request #226 from mooori/yargs-setup
Browse files Browse the repository at this point in the history
feat(run-tests-zkasm.js): use yargs to build CLI
  • Loading branch information
mooori authored Feb 21, 2024
2 parents 8da9e89 + 50e08f9 commit 932468c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/zkasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "AGPL",
"dependencies": {
"@0xpolygonhermez/zkasmcom": "https://github.com/0xPolygonHermez/zkasmcom.git#v1.0.0",
"yargs": "^17.5.1"
"yargs": "^17.7.2"
},
"devDependencies": {
"@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#v2.0.0-fork.5",
Expand Down
31 changes: 26 additions & 5 deletions tests/zkasm/run-tests-zkasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,40 @@ function value_to_json(key, value) {
return value;
}

/**
* Run this script with `--help` to print docs.
*/
async function main() {
const argv = require("yargs/yargs")(process.argv.slice(2))
.command("$0 <path> [outfile]", "the default command runs zkASM tests", (yargs) => {
yargs.positional("path", {
describe: "The zkASM file to run or a directory to search for zkASM files.",
type: "string"
})
yargs.positional("outfile", {
describe: "If provided, results are written to this file. Otherwise they are printed to stdout.",
type: "string"
})
})
.parse();

// Run the default command.
runTestsCmd(argv.path, argv.outfile);
}

/**
* Executes zkASM stored in files. Expects the following positional command line arguments:
*
* @param {string} path - The file or a directory to search for zkASM files.
* @param {string} [outFile] - If provided, results are written to this file. Otherwise they are
* @param {string} [outfile] - If provided, results are written to this file. Otherwise they are
* printed to stdout.
*/
async function main() {
async function runTestsCmd(path, outfile) {
// Compile pil
const cmPols = await compilePil();

// Get all zkasm files
const files = await getTestFiles(process.argv[2]);
const files = await getTestFiles(path);

// Run all zkasm files
let testResults = [];
Expand All @@ -53,9 +74,9 @@ async function main() {
testResults.push(await runTest(file, cmPols));
}

if (process.argv[3]) {
if (outfile) {
const json = JSON.stringify(testResults, value_to_json);
fs.writeFileSync(process.argv[3], json);
fs.writeFileSync(outfile, json);
} else {
console.log(testResults);
}
Expand Down

0 comments on commit 932468c

Please sign in to comment.