Skip to content

Commit 463ac41

Browse files
authored
Merge pull request #14 from hildjj/total
Give total number of tests in result as well.
2 parents d3e71df + dbca0e9 commit 463ac41

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

.ncurc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"dep": ["prod", "dev", "packageManager"]
2+
"dep": ["prod", "dev", "packageManager"],
3+
"reject": ["typescript"]
34
}

lib/index.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ let counter = 0;
1717
* @typedef {object} TestCounts
1818
* @prop {number} valid
1919
* @prop {number} invalid
20+
* @prop {number} total
2021
* @prop {string} grammarPath
2122
* @prop {string} modifiedPath
2223
*/
@@ -61,6 +62,20 @@ let counter = 0;
6162
* @typedef {import('peggy').Location} Location
6263
*/
6364

65+
/**
66+
* Add the formatted information to the given error.
67+
*
68+
* @param {unknown} e
69+
* @param {string} source
70+
* @param {string} text
71+
*/
72+
function format(e, source, text) {
73+
const er = /** @type {import('peggy').parser.SyntaxError} */(e);
74+
if (typeof er?.format === "function") {
75+
er.message = er.format([{ source, text }]);
76+
}
77+
}
78+
6479
/**
6580
* @template T
6681
* @param {Parser} grammar
@@ -101,9 +116,8 @@ function checkParserStarts(grammar, starts, modified, counts) {
101116
...options,
102117
});
103118
} catch (er) {
104-
const e = /** @type {import('peggy').parser.SyntaxError} */ (er);
105-
e.message = e.format([{ source, text: start.validInput }]);
106-
throw e;
119+
format(er, source, start.validInput);
120+
throw er;
107121
}
108122
if (typeof expected === "string") {
109123
equal(res, expected, `${source} (eq): "${start.validInput}"`);
@@ -175,6 +189,7 @@ function checkParserStarts(grammar, starts, modified, counts) {
175189
}));
176190
}
177191
counts.valid++;
192+
counts.total++;
178193
}
179194

180195
if (typeof start.invalidInput === "string") {
@@ -221,6 +236,7 @@ function checkParserStarts(grammar, starts, modified, counts) {
221236
equal(typeof fmt, "string");
222237
}
223238
counts.invalid++;
239+
counts.total++;
224240
}
225241
}
226242
}
@@ -270,6 +286,7 @@ export async function testPeggy(grammarUrl, starts, opts) {
270286
const counts = {
271287
valid: 0,
272288
invalid: 0,
289+
total: 0,
273290
grammarPath,
274291
modifiedPath,
275292
};

test/index.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ test("test peggy coverage", async() => {
8484
deepEqual(counts, {
8585
valid: 11,
8686
invalid: 9,
87+
total: 20,
8788
});
8889
});
8990

@@ -101,6 +102,7 @@ test("noGenerate", async() => {
101102
deepEqual(counts, {
102103
valid: 1,
103104
invalid: 1,
105+
total: 2,
104106
});
105107
});
106108

@@ -118,6 +120,7 @@ test("noMap", async() => {
118120
deepEqual(counts, {
119121
valid: 2,
120122
invalid: 2,
123+
total: 4,
121124
});
122125
});
123126

@@ -140,6 +143,7 @@ test("skip", async() => {
140143
deepEqual(counts, {
141144
valid: 2,
142145
invalid: 0,
146+
total: 2,
143147
});
144148
});
145149

@@ -158,6 +162,7 @@ test("skip", async() => {
158162
deepEqual(counts, {
159163
valid: 2,
160164
invalid: 0,
165+
total: 2,
161166
});
162167
});
163168

0 commit comments

Comments
 (0)