Skip to content
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

feat(run-tests-zkasm.js): use yargs to build CLI #226

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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