fix(perf): reject invalid startup bench counts

This commit is contained in:
Vincent Koc
2026-05-28 03:48:51 +02:00
parent d2319d718c
commit d1577a2ff2
3 changed files with 40 additions and 25 deletions

View File

@@ -65,9 +65,29 @@ describe("bench-cli-startup", () => {
]);
});
it("does not accept zero measured runs", () => {
expect(testing.parsePositiveInt("0", 5)).toBe(5);
it("rejects invalid measured run counts", () => {
expect(() => testing.parsePositiveInt("0", 5, "--runs")).toThrow(
"--runs must be an integer >= 1",
);
expect(() => testing.parsePositiveInt("2abc", 5, "--runs")).toThrow(
"--runs must be an integer >= 1",
);
expect(() => testing.parsePositiveInt("1.5", 5, "--runs")).toThrow(
"--runs must be an integer >= 1",
);
expect(() => testing.parsePositiveInt("1e3", 5, "--runs")).toThrow(
"--runs must be an integer >= 1",
);
expect(() => testing.parsePositiveInt("0x10", 5, "--runs")).toThrow(
"--runs must be an integer >= 1",
);
expect(testing.parsePositiveInt("1", 5)).toBe(1);
expect(testing.parseNonNegativeInt("0", 1)).toBe(0);
expect(() => testing.parseNonNegativeInt("-1", 1, "--warmup")).toThrow(
"--warmup must be an integer >= 0",
);
expect(() => testing.parseNonNegativeInt("0b10", 1, "--warmup")).toThrow(
"--warmup must be an integer >= 0",
);
});
});