summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-03-24 13:05:19 +0100
committerAraq <rumpf_a@web.de>2013-03-24 13:05:19 +0100
commitba80bd807ca0f8562974aa4deae2b956cf6bf6d2 (patch)
treebaaef873a2b47ea67715a14a518f07297bece06b /tests
parentdcb0f243de104635ab4b5d3824cb665635c34f1e (diff)
downloadNim-ba80bd807ca0f8562974aa4deae2b956cf6bf6d2.tar.gz
fixes #376
Diffstat (limited to 'tests')
-rw-r--r--tests/gc/closureleak.nim33
-rw-r--r--tests/js/test2.nim23
-rw-r--r--tests/specials.nim1
3 files changed, 57 insertions, 0 deletions
diff --git a/tests/gc/closureleak.nim b/tests/gc/closureleak.nim
new file mode 100644
index 000000000..c3eeac07b
--- /dev/null
+++ b/tests/gc/closureleak.nim
@@ -0,0 +1,33 @@
+discard """
+  outputsub: "true"
+"""
+
+from strutils import join
+
+type
+  TFoo * = object
+    id: int
+    func: proc(){.closure.}
+var foo_counter = 0
+var alive_foos = newseq[int](0)
+
+proc free*(some: ref TFoo) =
+  #echo "Tfoo #", some.id, " freed"
+  alive_foos.del alive_foos.find(some.id)
+proc newFoo*(): ref TFoo =
+  new result, free
+  
+  result.id = foo_counter
+  alive_foos.add result.id
+  inc foo_counter
+
+for i in 0 .. <10:
+ discard newFoo()
+
+for i in 0 .. <10:
+  let f = newFoo()
+  f.func = proc = 
+    echo f.id
+
+gc_fullcollect()
+echo alive_foos.len <= 2
diff --git a/tests/js/test2.nim b/tests/js/test2.nim
new file mode 100644
index 000000000..1342ed15d
--- /dev/null
+++ b/tests/js/test2.nim
@@ -0,0 +1,23 @@
+discard """
+  cmd: "nimrod js --hints:on -r $# $#"
+  output: '''foo
+js 3.14'''
+"""
+
+# This file tests the JavaScript generator
+
+#  #335 
+proc foo() =
+  var bar = "foo"
+  proc baz() =
+    echo bar
+  baz()
+foo()
+  
+# #376
+when not defined(JS):
+  proc foo(val: float): string = "no js " & $val
+else:
+  proc foo(val: float): string = "js " & $val
+
+echo foo(3.14)
diff --git a/tests/specials.nim b/tests/specials.nim
index 173ebd2f8..30bb6f423 100644
--- a/tests/specials.nim
+++ b/tests/specials.nim
@@ -131,6 +131,7 @@ proc runGcTests(r: var TResults, options: string) =
   test "gcleak3"
   test "weakrefs"
   test "cycleleak"
+  test "closureleak"
 
 # ------------------------- threading tests -----------------------------------