fix(plan): below 1.9 a test file after a note, and, plus or + is read
Operator decisions 28 (13.10) and 31 (14.10); review finding bd2520b0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b70f242e53
commit
8e6229b01d
2 changed files with 122 additions and 6 deletions
|
|
@ -637,6 +637,11 @@ const DOC_RE = /\.(md|markdown|mdx|txt|rst|adoc)$/i;
|
|||
const DATA_RE = /\.(ya?ml|json|toml|xml|csv)$/i;
|
||||
const UNDER_TESTS_RE = /(^|\/)(tests?|__tests__)\//;
|
||||
|
||||
/** A path that is clearly a test: a test by its path, and under tests/ or neither a document nor a data file. */
|
||||
function clearlyTest(p) {
|
||||
return isTestPath(p) && (UNDER_TESTS_RE.test(p) || !(DOC_RE.test(p) || DATA_RE.test(p)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether every file in a step's `Files:` is a test: the step's own `Test
|
||||
* first:` file, or a path that is clearly a test (lib/util/test-path.mjs). Such
|
||||
|
|
@ -662,6 +667,52 @@ const TEST_FIRST_FILE_LINE = /\bFile:\**[ \t]*(?=`)/gi;
|
|||
// From plan_version 1.9: a line that opens with `File:` (after an optional
|
||||
// list marker of the set LIST_ITEM accepts, and `**`), backticked or not.
|
||||
const TEST_FIRST_FILE_LINE_19 = /^\s*(?:(?:[-*+]|\d+[.)])\s+)?(?:\*\*)?File:(?:\*\*)?/i;
|
||||
// Below plan_version 1.9: one glue token at the start of the rest of a `File:`
|
||||
// run (operator decisions 28, 13.10, and 31, 14.10): whitespace or a comma
|
||||
// (group 1); a note in brackets holding no bracket, backtick or newline,
|
||||
// optionally in one `*` or `_` (`(new)`, `*(new)*`, `(existing, the parser)`);
|
||||
// the whole word `and` or `plus`, any case (`android` is no glue); or `+`.
|
||||
const OLDER_GLUE = /^(?:(\s+|,)|[*_]?\([^()`\n]*\)[*_]?|(?:and|plus)(?!\w)|\+)/i;
|
||||
|
||||
/**
|
||||
* The files of one below-1.9 `File:` run, read from just after the marker:
|
||||
* the leading backticked span, then each span after one or more glue tokens
|
||||
* (OLDER_GLUE). While every glue token so far was whitespace or a comma, a
|
||||
* span with the shape of a path is kept and any other span is skipped
|
||||
* (operator decision 20). Once a glue token was a note or a word, a span is
|
||||
* kept only when it has the shape of a path and is clearly a test, and the
|
||||
* first span that is not ends the run (operator decisions 28 and 31). Any text
|
||||
* that is neither a span nor glue ends the run.
|
||||
* @param {string} text - the line after one `File:` marker
|
||||
* @returns {string[]} the kept spans, trimmed, not normalised
|
||||
*/
|
||||
function olderFileRun(text) {
|
||||
const out = [];
|
||||
let rest = String(text ?? '');
|
||||
let loose = false;
|
||||
let m = LEADING_SPAN.exec(rest);
|
||||
while (m) {
|
||||
const s = m[1].trim();
|
||||
if (!loose) {
|
||||
if (tickedPath(s) || BUILD_FILE.test(s)) out.push(s);
|
||||
} else if (tickedPath(s) && clearlyTest(norm(s))) {
|
||||
out.push(s);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
rest = rest.slice(m[0].length);
|
||||
let glued = false;
|
||||
let g = OLDER_GLUE.exec(rest);
|
||||
while (g) {
|
||||
glued = true;
|
||||
if (g[1] === undefined) loose = true;
|
||||
rest = rest.slice(g[0].length);
|
||||
g = OLDER_GLUE.exec(rest);
|
||||
}
|
||||
m = glued ? LEADING_SPAN.exec(rest) : null;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* plan_version 1.9: the rest of each `Test first:` `File:` line (after `File:`
|
||||
|
|
@ -704,13 +755,18 @@ export function testFirstFileEntries(fields) {
|
|||
* Below plan_version 1.9 (or without a version) a line counts as that line
|
||||
* exactly when TEST_FIRST_FILE_LINE matches it. Each `File:` marker on the
|
||||
* line opens a run: the backticked spans that stand right after it, separated
|
||||
* only by commas or whitespace (leadingSpans), and every span in that run with
|
||||
* only by commas or whitespace (olderFileRun), and every span in that run with
|
||||
* the shape of a path is a test file (a call `parse()`, an option, a URL is
|
||||
* skipped and the run goes on). A path in the description after the run is no
|
||||
* test file (operator decision 20, 12.10; review `6c31212c`: "covers `parse()`
|
||||
* in `src/parser.mjs`" made the source a test and the step tests-only). The
|
||||
* markers are matched globally because 6.3.1 read the first span after each
|
||||
* `File:`, so a line with two markers keeps at least 6.3.1's files.
|
||||
* `File:`, so a line with two markers keeps at least 6.3.1's files. Below 1.9
|
||||
* the run also goes on past a note in brackets (`(new)`, `*(new)*`,
|
||||
* `(existing ...)`) and the words `and`, `plus` and `+`, to a further path
|
||||
* only when it is clearly a test, and a source path there ends it
|
||||
* (olderFileRun; operator decisions 28 and 31, 13.10 and 14.10; review
|
||||
* `bd2520b0`; review `6c31212c` for the guard).
|
||||
*
|
||||
* From 1.9 a line counts when it opens with `File:` (testFirstFileEntries),
|
||||
* backticked or not, after an optional list marker (`1.` and `1)` included);
|
||||
|
|
@ -739,8 +795,7 @@ export function testFirstFiles(fields, version) {
|
|||
}
|
||||
for (const line of String(fields.get('Test first').text ?? '').split('\n')) {
|
||||
for (const at of line.matchAll(TEST_FIRST_FILE_LINE)) {
|
||||
for (const s of leadingSpans(line.slice(at.index + at[0].length))) {
|
||||
if (!(tickedPath(s) || BUILD_FILE.test(s))) continue;
|
||||
for (const s of olderFileRun(line.slice(at.index + at[0].length))) {
|
||||
const p = norm(s);
|
||||
if (!out.includes(p)) out.push(p);
|
||||
}
|
||||
|
|
@ -756,8 +811,7 @@ export function testFirstFiles(fields, version) {
|
|||
*/
|
||||
function stepTestFile(f, version) {
|
||||
const testFirst = testFirstFiles(f, version);
|
||||
return (p) => testFirst.includes(p) ||
|
||||
(isTestPath(p) && (UNDER_TESTS_RE.test(p) || !(DOC_RE.test(p) || DATA_RE.test(p))));
|
||||
return (p) => testFirst.includes(p) || clearlyTest(p);
|
||||
}
|
||||
|
||||
/** `stepTestsOnly` for a caller that already holds the step's parsed fields. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue