From b8f8ea133204ef9bae1313ecc6ce13b3959e8865 Mon Sep 17 00:00:00 2001 From: sukanto01899 Date: Sat, 24 Jan 2026 10:59:07 +0600 Subject: [PATCH] Fix flow parser when no test functions exist --- src/parser/clarity-parser-flow-tests.ts | 3 +++ tests/clarity-parser-flow.test.ts | 13 +++++++++++++ tests/contracts/parser-tests/no-flow.clar | 4 ++++ 3 files changed, 20 insertions(+) create mode 100644 tests/contracts/parser-tests/no-flow.clar diff --git a/src/parser/clarity-parser-flow-tests.ts b/src/parser/clarity-parser-flow-tests.ts index 3ac09f3..520b7c5 100644 --- a/src/parser/clarity-parser-flow-tests.ts +++ b/src/parser/clarity-parser-flow-tests.ts @@ -81,6 +81,9 @@ export function extractTestAnnotationsAndCalls( lastFunctionName = functionName; } } + if (indexStart < 0) { + return [functionAnnotations, functionBodies]; + } const lastFunctionBody = contractSource.substring(indexStart + headerLength); contractCalls = extractContractCalls(lastFunctionBody, simnet); functionBodies[lastFunctionName] = contractCalls; diff --git a/tests/clarity-parser-flow.test.ts b/tests/clarity-parser-flow.test.ts index b920136..662dfa6 100644 --- a/tests/clarity-parser-flow.test.ts +++ b/tests/clarity-parser-flow.test.ts @@ -74,4 +74,17 @@ describe("verify clarity parser for flow tests", () => { }); expect(callInfos["test-bad-flow"].length).toEqual(1); }); + + it("should return empty results when no test functions exist", () => { + const [annotations, callInfos] = extractTestAnnotationsAndCalls( + fs.readFileSync( + path.join(__dirname, "./contracts/parser-tests/no-flow.clar"), + "utf8" + ), + simnet + ); + + expect(annotations).toEqual({}); + expect(callInfos).toEqual({}); + }); }); diff --git a/tests/contracts/parser-tests/no-flow.clar b/tests/contracts/parser-tests/no-flow.clar new file mode 100644 index 0000000..a9b2ab3 --- /dev/null +++ b/tests/contracts/parser-tests/no-flow.clar @@ -0,0 +1,4 @@ +;; A contract without any flow tests +(define-public (not-a-test) + (ok true) +)