summary refs log tree commit diff stats
path: root/tests/destructor
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2019-05-13 08:28:33 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-05-13 08:28:33 +0200
commit0c869eaa475caab9558aaf5b39b8e3519388f811 (patch)
tree6a1ee425e34f811c6e82cd6e48145465dad3a7d5 /tests/destructor
parenta3e27ffa2c721b2ef3b0481d7db5c45039072050 (diff)
downloadNim-0c869eaa475caab9558aaf5b39b8e3519388f811.tar.gz
Fix destructor injections for global variables (#11230)
* attach global destructors at end of mainModule
* Add testcase
* Minor cleanup
* Inject topLevelVar temporaries' destructors early
* Fix megatest
Diffstat (limited to 'tests/destructor')
-rw-r--r--tests/destructor/objFile.nim8
-rw-r--r--tests/destructor/texplicit_move.nim1
-rw-r--r--tests/destructor/tglobaldestructor.nim9
-rw-r--r--tests/destructor/topt.nim1
4 files changed, 19 insertions, 0 deletions
diff --git a/tests/destructor/objFile.nim b/tests/destructor/objFile.nim
new file mode 100644
index 000000000..436c090d1
--- /dev/null
+++ b/tests/destructor/objFile.nim
@@ -0,0 +1,8 @@
+type Obj* = object
+  v*: int
+
+proc `=destroy`(this: var Obj) =
+  echo "igotdestroyed"
+  this.v = -1
+
+var test* = Obj(v: 42)
diff --git a/tests/destructor/texplicit_move.nim b/tests/destructor/texplicit_move.nim
index 230f0b133..93795af42 100644
--- a/tests/destructor/texplicit_move.nim
+++ b/tests/destructor/texplicit_move.nim
@@ -6,6 +6,7 @@ discard """
 10
 destroyed!
 '''
+joinable: false
 """
 
 type
diff --git a/tests/destructor/tglobaldestructor.nim b/tests/destructor/tglobaldestructor.nim
new file mode 100644
index 000000000..403f670a0
--- /dev/null
+++ b/tests/destructor/tglobaldestructor.nim
@@ -0,0 +1,9 @@
+discard """
+  cmd: '''nim c --newruntime $file'''
+  output: '''(v: 42)
+igotdestroyed'''
+"""
+
+import objFile
+
+echo test
diff --git a/tests/destructor/topt.nim b/tests/destructor/topt.nim
index 829500f8a..3851a4283 100644
--- a/tests/destructor/topt.nim
+++ b/tests/destructor/topt.nim
@@ -3,6 +3,7 @@ discard """
   output: '''5
 vseq destroy
 '''
+joinable: false
 """
 type
   opt*[T] = object