





















@@ -1,10 +1,19 @@
11import { describe, expect, it } from "vitest";
2+import type { InterpreterInlineEvalHit } from "./inline-eval.js";
23import {
34describeInterpreterInlineEval,
45detectInterpreterInlineEvalArgv,
56isInterpreterLikeAllowlistPattern,
67} from "./inline-eval.js";
789+function expectInlineEvalDescription(hit: InterpreterInlineEvalHit | null, expected: string) {
10+expect(hit).toEqual(expect.any(Object));
11+if (hit === null) {
12+throw new Error(`Expected inline eval hit for ${expected}`);
13+}
14+expect(describeInterpreterInlineEval(hit)).toBe(expected);
15+}
16+817describe("exec inline eval detection", () => {
918it.each([
1019{ argv: ["python3", "-c", "print('hi')"], expected: "python3 -c" },
@@ -15,8 +24,7 @@ describe("exec inline eval detection", () => {
1524{ argv: ["gawk", "-F", ",", "{print $1}", "data.csv"], expected: "gawk inline program" },
1625] as const)("detects interpreter eval flags for %j", ({ argv, expected }) => {
1726const hit = detectInterpreterInlineEvalArgv([...argv]);
18-expect(hit).not.toBeNull();
19-expect(describeInterpreterInlineEval(hit!)).toBe(expected);
27+expectInlineEvalDescription(hit, expected);
2028});
21292230it.each([
@@ -46,8 +54,7 @@ describe("exec inline eval detection", () => {
4654{ argv: ["sed", "-es/.*/id/e", "/dev/null"], expected: "sed -e" },
4755] as const)("detects command carriers for %j", ({ argv, expected }) => {
4856const hit = detectInterpreterInlineEvalArgv([...argv]);
49-expect(hit).not.toBeNull();
50-expect(describeInterpreterInlineEval(hit!)).toBe(expected);
57+expectInlineEvalDescription(hit, expected);
5158});
52595360it("ignores normal script execution", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。