@jwilger/pi-development-system 0.10.4 → 0.10.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@ const KINDS: readonly Kind[] = [
|
|
|
26
26
|
inline: (line, after) =>
|
|
27
27
|
lastGroup(/reason\s*=\s*"([^"]*)"/, line) ??
|
|
28
28
|
lastGroup(/\)\]\s*\/\/\s*(.+)$/, after) ??
|
|
29
|
-
lastGroup(/\)\]\s*\/\*\s*(
|
|
29
|
+
lastGroup(/\)\]\s*\/\*\s*([^*]+?)\*\/\s*$/, after),
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
marker: "#![allow(",
|
package/src/core/test-runner.ts
CHANGED
|
@@ -59,7 +59,7 @@ export type ResultLike = {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
/** A pipe or sequence makes the shell report the last command's status, not the runner's. */
|
|
62
|
-
const MASKS_STATUS =
|
|
62
|
+
const MASKS_STATUS = /[|;\n]/;
|
|
63
63
|
const FAILURE_MARKERS =
|
|
64
64
|
/^(?:# |ℹ )fail [1-9]|test result: FAILED|\b[1-9]\d* (?:failed|failing)\b|^FAILED\b|^FAIL\b|\bnot ok\b/m;
|
|
65
65
|
|
|
@@ -13,7 +13,9 @@ export type RedFirstGuardDeps = { pi: ExtensionAPI; state: SessionState };
|
|
|
13
13
|
const GATE_ID = "tdd.red-first";
|
|
14
14
|
|
|
15
15
|
/** Test code written inside a source file (Rust `#[cfg(test)]`/`#[test]`): that edit is the RED step itself. */
|
|
16
|
-
const INLINE_TEST = /#\[(?:cfg\(test\)|test|
|
|
16
|
+
const INLINE_TEST = /#\[(?:cfg\(test\)|test|test_case|rstest|proptest|\w+::test)\b/g;
|
|
17
|
+
|
|
18
|
+
const INLINE_MODULE = /#\[cfg\(test\)\]\s*(?:#\[[^\]]*\]\s*)*mod\s+\w+\s*\{/;
|
|
17
19
|
|
|
18
20
|
const countInlineTests = (text: string): number => text.match(INLINE_TEST)?.length ?? 0;
|
|
19
21
|
|
|
@@ -25,14 +27,30 @@ const existing = (cwd: string, path: string): string => {
|
|
|
25
27
|
}
|
|
26
28
|
};
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
type EditInput =
|
|
31
|
+
| { content: string }
|
|
32
|
+
| { edits: ReadonlyArray<{ oldText: string; newText: string }> };
|
|
33
|
+
|
|
34
|
+
/** Is every edit inside the file's existing `#[cfg(test)]` module? Changing a test's expectation is RED itself. */
|
|
35
|
+
const insideTestModule = (edits: ReadonlyArray<{ oldText: string }>, file: string): boolean => {
|
|
36
|
+
// Only an inline module body counts: `mod tests;`, `#[cfg(test)] use ...` and fns are not test code.
|
|
37
|
+
const start = INLINE_MODULE.exec(file)?.index ?? -1;
|
|
38
|
+
return start >= 0 && edits.every((e) => e.oldText !== "" && file.indexOf(e.oldText) > start);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Does this edit write or change test code? A write counts markers beyond those on disk, an edit
|
|
43
|
+
* counts markers beyond those it replaces (an anchor line is not a new test), or must sit wholly
|
|
44
|
+
* inside the existing test module.
|
|
45
|
+
*/
|
|
46
|
+
const touchesInlineTest = (input: EditInput, before: () => string): boolean => {
|
|
47
|
+
if ("content" in input) return countInlineTests(input.content) > countInlineTests(before());
|
|
48
|
+
const added = input.edits.reduce(
|
|
49
|
+
(n, e) => n + Math.max(0, countInlineTests(e.newText) - countInlineTests(e.oldText)),
|
|
50
|
+
0,
|
|
51
|
+
);
|
|
52
|
+
return added > 0 || insideTestModule(input.edits, before());
|
|
53
|
+
};
|
|
36
54
|
|
|
37
55
|
/** Exemption classes a machine cannot see; the departure names which one applies (research 02). */
|
|
38
56
|
const JUDGED_EXEMPTIONS =
|
|
@@ -58,7 +76,7 @@ export function registerRedFirstGuard(deps: RedFirstGuardDeps): void {
|
|
|
58
76
|
if (lastTestRun !== undefined && lastTestRun.exitCode !== 0) return undefined;
|
|
59
77
|
const path = normalizeRepoPath(ctx.cwd, event.input.path, homedir());
|
|
60
78
|
if (classifyPath(path) !== "source") return undefined;
|
|
61
|
-
if (
|
|
79
|
+
if (touchesInlineTest(event.input, () => existing(ctx.cwd, path))) return undefined;
|
|
62
80
|
if (departure.hasOpen()) {
|
|
63
81
|
departure.consume();
|
|
64
82
|
return undefined;
|