дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
Zig test blocks had run markers but their runs never reached the test runner: no parser read the runners' output. A parser now reads zig test's per-test progress lines, error-return traces and summary, and zig build test's failure blocks and --summary all counts (added to those runs). Results are rooted at the module stem so gutter icons turn green/red per test; Rerun Failed and Run Selected build --test-filter configs for standalone zig test runs. test names are unescaped in run targets so the marker label, --test-filter and the runner's names agree. Co-authored-by: akbar1214 <[email protected]>
87 рядки
4.3 KiB
TypeScript
87 рядки
4.3 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { TestResults } from "./results";
|
|
import { clearTestStates, onTestStatesChanged, recordTestStates, testState } from "./states";
|
|
|
|
function run(events: Parameters<TestResults["apply"]>[0]) {
|
|
const r = new TestResults();
|
|
r.apply(events);
|
|
r.finish(0);
|
|
recordTestStates(r);
|
|
}
|
|
|
|
describe("test states for the run gutter", () => {
|
|
afterEach(() => clearTestStates());
|
|
|
|
it("matches Rust tests by module path under any crate suite", () => {
|
|
run([
|
|
{ type: "result", path: ["src/lib.rs", "tests", "adds"], status: "passed" },
|
|
{ type: "result", path: ["src/lib.rs", "tests", "subs"], status: "failed" },
|
|
]);
|
|
expect(testState({ path: ["tests", "adds"] })).toBe("passed");
|
|
expect(testState({ path: ["tests", "subs"] })).toBe("failed");
|
|
// The suite (`mod tests`) failed because one of its tests did.
|
|
expect(testState({ path: ["tests"] })).toBe("failed");
|
|
expect(testState({ path: ["tests", "other"] })).toBeNull();
|
|
});
|
|
|
|
it("matches JVM results named by qualified class and `method()`", () => {
|
|
run([
|
|
{ type: "result", path: ["com.acme.OrderTest", "lists()"], status: "passed" },
|
|
{ type: "result", path: ["com.acme.OrderTest", "creates()"], status: "failed" },
|
|
]);
|
|
expect(testState({ path: ["OrderTest", "lists"] })).toBe("passed");
|
|
expect(testState({ path: ["OrderTest", "creates"] })).toBe("failed");
|
|
expect(testState({ path: ["OrderTest"] })).toBe("failed");
|
|
});
|
|
|
|
it("checks the file for results rooted at it, and any parameter failing fails the test", () => {
|
|
run([
|
|
{ type: "result", path: ["tests/test_math.py", "test_add[1]"], status: "passed" },
|
|
{ type: "result", path: ["tests/test_math.py", "test_add[2]"], status: "failed" },
|
|
{ type: "result", path: ["src/math.test.ts", "math", "adds"], status: "passed" },
|
|
]);
|
|
expect(testState({ path: ["test_add"], file: "/work/app/tests/test_math.py" })).toBe("failed");
|
|
expect(testState({ path: ["test_add"], file: "/work/app/other/test_math2.py" })).toBeNull();
|
|
expect(testState({ path: ["math", "adds"], file: "/work/app/src/math.test.ts" })).toBe("passed");
|
|
});
|
|
|
|
it("matches unittest results rooted at the dotted module of the file", () => {
|
|
run([
|
|
{ type: "result", path: ["polls.tests", "QuestionTests", "test_recent"], status: "failed" },
|
|
{ type: "result", path: ["polls.tests.test_views", "ViewTests", "test_ok"], status: "passed" },
|
|
{ type: "result", path: ["città.tests", "QTests", "test_a"], status: "passed" },
|
|
]);
|
|
expect(testState({ path: ["QuestionTests", "test_recent"], file: "/work/app/polls/tests.py" })).toBe("failed");
|
|
expect(testState({ path: ["QuestionTests"], file: "/work/app/polls/tests/__init__.py" })).toBe("failed");
|
|
expect(testState({ path: ["QuestionTests", "test_recent"], file: "/work/app/blog/tests.py" })).toBeNull();
|
|
expect(testState({ path: ["ViewTests", "test_ok"], file: "/work/app/polls/tests/test_views.py" })).toBe("passed");
|
|
expect(testState({ path: ["QTests", "test_a"], file: "/work/app/città/tests.py" })).toBe("passed");
|
|
});
|
|
|
|
it("matches Zig results rooted at the module stem of the file", () => {
|
|
run([
|
|
{ type: "result", path: ["tally", "adds"], status: "passed" },
|
|
{ type: "result", path: ["tally", "subs"], status: "failed" },
|
|
{ type: "result", path: ["other", "adds"], status: "failed" },
|
|
]);
|
|
expect(testState({ path: ["adds"], file: "src/tally.zig" })).toBe("passed");
|
|
expect(testState({ path: ["subs"], file: "/work/app/src/tally.zig" })).toBe("failed");
|
|
// Same-named tests of another module don't bleed over.
|
|
expect(testState({ path: ["adds"], file: "src/other.zig" })).toBe("failed");
|
|
expect(testState({ path: ["adds"], file: "src/tally/main.zig" })).toBeNull();
|
|
});
|
|
|
|
it("newer runs win and listeners hear about changes", () => {
|
|
const listener = vi.fn();
|
|
const off = onTestStatesChanged(listener);
|
|
run([{ type: "result", path: ["pkg", "TestA"], status: "failed" }]);
|
|
run([{ type: "result", path: ["pkg", "TestA"], status: "passed" }]);
|
|
expect(testState({ path: ["TestA"] })).toBe("passed");
|
|
expect(listener).toHaveBeenCalledTimes(2);
|
|
// Unchanged results don't redraw the gutters.
|
|
run([{ type: "result", path: ["pkg", "TestA"], status: "passed" }]);
|
|
expect(listener).toHaveBeenCalledTimes(2);
|
|
off();
|
|
});
|
|
});
|