diff options
author | Clyybber <darkmine956@gmail.com> | 2020-07-14 14:15:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-14 14:15:39 +0200 |
commit | 2b0e336c971401d06797240686722ce669d902b9 (patch) | |
tree | 51ce03a1310b5477a16a20f8234621ffa5d5d51f /tests/arc/tarcmisc.nim | |
parent | f999f916f31946be3cf8abc485fc07e0d89de9ae (diff) | |
download | Nim-2b0e336c971401d06797240686722ce669d902b9.tar.gz |
injectdestructors fixes and refactor (#14964)
* injectdestructors fixes and refactor * Tiny cleanup * Refactor and expand testcase * Closes #14902 by adding testcase * Better naming * Fix test failures * Misc cleanup * Add testcase for #14968 * Better approach; expand testcases * Optimizations and fixes * Add testcase * typo * Tiny cleanup
Diffstat (limited to 'tests/arc/tarcmisc.nim')
-rw-r--r-- | tests/arc/tarcmisc.nim | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim index b6d9d781d..2d7e6b455 100644 --- a/tests/arc/tarcmisc.nim +++ b/tests/arc/tarcmisc.nim @@ -3,6 +3,11 @@ discard """ 123xyzabc destroyed: false destroyed: false +destroyed2: false +destroyed2: false +destroying variable: 2 +destroying variable: 1 +whiley ends :( 1 (x: "0") (x: "1") @@ -17,7 +22,8 @@ destroyed: false (x: "10") 0 closed -destroying variable +destroying variable: 20 +destroying variable: 10 ''' cmd: "nim c --gc:arc $file" """ @@ -40,11 +46,12 @@ type Variable = ref object value: int proc `=destroy`(self: var typeof(Variable()[])) = - echo "destroying variable" + echo "destroying variable: ",self.value proc newVariable(value: int): Variable = result = Variable() result.value = value + #echo "creating variable: ",result.value proc test(count: int) = var v {.global.} = newVariable(10) @@ -57,6 +64,28 @@ proc test(count: int) = test(3) +proc test2(count: int) = + #block: #XXX: Fails with block currently + var v {.global.} = newVariable(20) + + var count = count - 1 + if count == 0: return + + test2(count) + echo "destroyed2: ", v.isNil + +test2(3) + +proc whiley = + var a = newVariable(1) + while true: + var b = newVariable(2) + if true: raise newException(CatchableError, "test") + +try: + whiley() +except CatchableError: + echo "whiley ends :(" #------------------------------------------------------------------------------ # issue #13810 @@ -209,3 +238,8 @@ proc setParent(self: SimpleLoopB, parent: SimpleLoopB) = var l = SimpleLoopB() l.setParent(l) + + +# bug #14968 +import times +let currentTime = now().utc |