From 1afe662ccd02d686f46f596242055c3ea23e645f Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 29 Aug 2022 22:43:27 +0000 Subject: Add simple memory leak test --- pkg/lang/vm/vm_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'pkg') diff --git a/pkg/lang/vm/vm_test.go b/pkg/lang/vm/vm_test.go index 8c31d1f..ea4123f 100644 --- a/pkg/lang/vm/vm_test.go +++ b/pkg/lang/vm/vm_test.go @@ -525,6 +525,42 @@ func TestSetAtArray(t *testing.T) { test(t, src, "[2, 2]") } +func TestNoBasicLeak(t *testing.T) { + // NOTE: The loop count should be changed in accordance to the Mem memory limit. + src := ` + push_int 0 + + @check: + get_local 0 + push_int 10000 + lt + jf @end + + push_array + + get_local 1 + get_member "push" + push_int 123 + call 1 + drop 1 + + get_local 0 + push_int 1 + add + set_local 0 + + drop 1 + + jmp @check + + @end: + push_string "done" + halt + ` + + test(t, src, "\"done\"") +} + func test(t *testing.T, src string, expected string) { bc := compile(t, src) vm := vm.New(modules.NewUnknownModule(&bc), vm.NewEmptyOutput()) -- cgit 1.4.1