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) +)