Skip to content

Commit

Permalink
Give total number of tests in result as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Nov 22, 2024
1 parent d3e71df commit dbca0e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .ncurc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"dep": ["prod", "dev", "packageManager"]
"dep": ["prod", "dev", "packageManager"],
"reject": ["typescript"]
}
23 changes: 20 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let counter = 0;
* @typedef {object} TestCounts
* @prop {number} valid
* @prop {number} invalid
* @prop {number} total
* @prop {string} grammarPath
* @prop {string} modifiedPath
*/
Expand Down Expand Up @@ -61,6 +62,20 @@ let counter = 0;
* @typedef {import('peggy').Location} Location
*/

/**
* Add the formatted information to the given error.
*
* @param {unknown} e
* @param {string} source
* @param {string} text
*/
function format(e, source, text) {
const er = /** @type {import('peggy').parser.SyntaxError} */(e);
if (typeof er?.format === "function") {
er.message = er.format([{ source, text }]);
}
}

/**
* @template T
* @param {Parser} grammar
Expand Down Expand Up @@ -101,9 +116,8 @@ function checkParserStarts(grammar, starts, modified, counts) {
...options,
});
} catch (er) {
const e = /** @type {import('peggy').parser.SyntaxError} */ (er);
e.message = e.format([{ source, text: start.validInput }]);
throw e;
format(er, source, start.validInput);
throw er;
}
if (typeof expected === "string") {
equal(res, expected, `${source} (eq): "${start.validInput}"`);
Expand Down Expand Up @@ -175,6 +189,7 @@ function checkParserStarts(grammar, starts, modified, counts) {
}));
}
counts.valid++;
counts.total++;
}

if (typeof start.invalidInput === "string") {
Expand Down Expand Up @@ -221,6 +236,7 @@ function checkParserStarts(grammar, starts, modified, counts) {
equal(typeof fmt, "string");
}
counts.invalid++;
counts.total++;
}
}
}
Expand Down Expand Up @@ -270,6 +286,7 @@ export async function testPeggy(grammarUrl, starts, opts) {
const counts = {
valid: 0,
invalid: 0,
total: 0,
grammarPath,
modifiedPath,
};
Expand Down
5 changes: 5 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ test("test peggy coverage", async() => {
deepEqual(counts, {
valid: 11,
invalid: 9,
total: 20,
});
});

Expand All @@ -101,6 +102,7 @@ test("noGenerate", async() => {
deepEqual(counts, {
valid: 1,
invalid: 1,
total: 2,
});
});

Expand All @@ -118,6 +120,7 @@ test("noMap", async() => {
deepEqual(counts, {
valid: 2,
invalid: 2,
total: 4,
});
});

Expand All @@ -140,6 +143,7 @@ test("skip", async() => {
deepEqual(counts, {
valid: 2,
invalid: 0,
total: 2,
});
});

Expand All @@ -158,6 +162,7 @@ test("skip", async() => {
deepEqual(counts, {
valid: 2,
invalid: 0,
total: 2,
});
});

Expand Down

0 comments on commit dbca0e9

Please sign in to comment.