Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 7dcdd26

Browse files
author
Erik Hollensbe
committed
gc_test.go: not-passing-yet tests for IsDead and three new GC-related functions.
Signed-off-by: Erik Hollensbe <[email protected]>
1 parent a8ba509 commit 7dcdd26

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

gc_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package mruby
2+
3+
import "testing"
4+
5+
func TestEnableDisableGC(t *testing.T) {
6+
mrb := NewMrb()
7+
defer mrb.Close()
8+
9+
mrb.FullGC()
10+
mrb.DisableGC()
11+
12+
_, err := mrb.LoadString("b = []; a = []; a = []")
13+
if err != nil {
14+
t.Fatal(err)
15+
}
16+
17+
orig := mrb.LiveObjectCount()
18+
mrb.FullGC()
19+
20+
if orig != mrb.LiveObjectCount() {
21+
t.Fatalf("Object count was not what was expected after full GC: %d %d", orig, mrb.LiveObjectCount())
22+
}
23+
24+
mrb.EnableGC()
25+
mrb.FullGC()
26+
27+
if orig-2 != mrb.LiveObjectCount() {
28+
t.Fatalf("Object count was not what was expected after full GC: %d %d", orig-2, mrb.LiveObjectCount())
29+
}
30+
}
31+
32+
func TestIsDead(t *testing.T) {
33+
mrb := NewMrb()
34+
35+
val, err := mrb.LoadString("$a = []")
36+
if err != nil {
37+
t.Fatal(err)
38+
}
39+
40+
if val.IsDead() {
41+
t.Fatal("Value is already dead and should not be")
42+
}
43+
44+
mrb.Close()
45+
46+
if !val.IsDead() {
47+
t.Fatal("Value should be dead and is not")
48+
}
49+
}

0 commit comments

Comments
 (0)