@jwilger/pi-development-system 0.10.2 → 0.10.4
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 +1 -1
- package/src/core/test-paths.ts +2 -0
- package/src/core/test-runner.ts +12 -5
package/package.json
CHANGED
package/src/core/test-paths.ts
CHANGED
|
@@ -14,6 +14,8 @@ const PATTERNS: readonly RegExp[] = [
|
|
|
14
14
|
/_test\.(go|rb|py|exs?|rs)$/,
|
|
15
15
|
/(^|\/)test_[^/]+\.py$/,
|
|
16
16
|
/_spec\.rb$/,
|
|
17
|
+
/(^|\/)tests?\.rs$/,
|
|
18
|
+
/_tests\.rs$/,
|
|
17
19
|
];
|
|
18
20
|
|
|
19
21
|
/** Glob match without building a RegExp: `**` spans directories, `*` stays within a segment. */
|
package/src/core/test-runner.ts
CHANGED
|
@@ -27,6 +27,8 @@ function isRunner(words: readonly string[]): boolean {
|
|
|
27
27
|
if (head === undefined) return false;
|
|
28
28
|
const args = rest.filter((w) => !w.startsWith("+"));
|
|
29
29
|
const first = args[0];
|
|
30
|
+
// Compile-only and listing runs prove nothing about RED/GREEN, so they must not overwrite a real result.
|
|
31
|
+
if (rest.some((w) => /^--(?:no-run|list|help)$/.test(w) || w === "-h")) return false;
|
|
30
32
|
if (head === "cargo") return first === "test" || first === "nextest";
|
|
31
33
|
if (head === "go" || head === "deno") return first === "test";
|
|
32
34
|
if (head === "node") return rest.includes("--test");
|
|
@@ -59,22 +61,27 @@ export type ResultLike = {
|
|
|
59
61
|
/** A pipe or sequence makes the shell report the last command's status, not the runner's. */
|
|
60
62
|
const MASKS_STATUS = /\||;/;
|
|
61
63
|
const FAILURE_MARKERS =
|
|
62
|
-
|
|
64
|
+
/^(?:# |ℹ )fail [1-9]|test result: FAILED|\b[1-9]\d* (?:failed|failing)\b|^FAILED\b|^FAIL\b|\bnot ok\b/m;
|
|
63
65
|
|
|
64
66
|
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
65
67
|
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
66
68
|
|
|
67
69
|
/** Exit code of a bash tool result: structured `exit_code`, else pi's status line, else error/not. */
|
|
68
70
|
export function exitCodeOf(result: ResultLike): number {
|
|
71
|
+
const reported = reportedExit(result);
|
|
72
|
+
if (reported !== 0) return reported;
|
|
73
|
+
// `npm test | tail` exits 0 whatever the tests did, even in the structured status; trust the output.
|
|
74
|
+
const masked = result.command !== undefined && MASKS_STATUS.test(result.command);
|
|
75
|
+
return masked && FAILURE_MARKERS.test(result.text) ? 1 : 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function reportedExit(result: ResultLike): number {
|
|
69
79
|
if (isRecord(result.structured) && typeof result.structured.exit_code === "number") {
|
|
70
80
|
return result.structured.exit_code;
|
|
71
81
|
}
|
|
72
82
|
const line = /Command exited with code (\d+)\s*$/.exec(result.text);
|
|
73
83
|
if (line?.[1] !== undefined) return Number(line[1]);
|
|
74
|
-
|
|
75
|
-
// `npm test | tail` exits 0 whatever the tests did; trust the output over the masked status.
|
|
76
|
-
const masked = result.command !== undefined && MASKS_STATUS.test(result.command);
|
|
77
|
-
return masked && FAILURE_MARKERS.test(result.text) ? 1 : 0;
|
|
84
|
+
return result.isError ? 1 : 0;
|
|
78
85
|
}
|
|
79
86
|
|
|
80
87
|
/** The last few non-empty output lines, redacted and bounded: what the runner said at the end. */
|