diff --git a/testament/testament.nim b/testament/testament.nim index 2a3b4c05368..4a0a0e23890 100644 --- a/testament/testament.nim +++ b/testament/testament.nim @@ -1110,7 +1110,7 @@ func nativeTarget(): TTarget {.inline.} = func defaultTargets(category: Category): set[TTarget] = const standardTargets = {nativeTarget()} case category.string - of "lang", "lang_callable": + of "lang", "lang_callable", "exception": {targetC, targetJs, targetVM} of "arc", "avr", "destructor", "distros", "dll", "gc", "osproc", "parallel", "realtimeGC", "threads", "views", "valgrind": diff --git a/tests/exception/tassignment.nim b/tests/exception/tassignment.nim index d007a18f658..ef8877389aa 100644 --- a/tests/exception/tassignment.nim +++ b/tests/exception/tassignment.nim @@ -1,5 +1,4 @@ discard """ - targets: "c js vm" description: ''' Tests for assignments where an exception is raised during evaluation of the right-hand side diff --git a/tests/exception/tasync_stacktrace_gc.nim b/tests/exception/tasync_stacktrace_gc.nim index 77ad80f2d5f..05e929c1f06 100644 --- a/tests/exception/tasync_stacktrace_gc.nim +++ b/tests/exception/tasync_stacktrace_gc.nim @@ -1,5 +1,4 @@ discard """ - matrix: "--gc:arc" description: ''' . From https://github.com/nim-lang/Nim/issues/18620 Stacktrace when using async with arc/orc is different than @@ -9,6 +8,7 @@ discard """ the stacktrace with arc/orc gives little help in finding out where the problem is. ''' + knownIssue.js vm: "`getStackTraceEntries` is not yet supported" """ proc hello() = diff --git a/tests/exception/tcontinuexc.nim b/tests/exception/tcontinuexc.nim index b7560a605bc..18920e4ba84 100644 --- a/tests/exception/tcontinuexc.nim +++ b/tests/exception/tcontinuexc.nim @@ -1,5 +1,7 @@ discard """ - outputsub: "ECcaught" + outputsub: '''E +C +caught''' exitcode: "1" """ type @@ -17,8 +19,8 @@ try: try: genErrors("error!") except ESomething: - stdout.write("E") - stdout.write("C") + echo "E" + echo "C" raise newException(EsomeotherErr, "bla") finally: echo "caught" diff --git a/tests/exception/tdefer1.nim b/tests/exception/tdefer1.nim index 42a5679b795..1e722c25c9e 100644 --- a/tests/exception/tdefer1.nim +++ b/tests/exception/tdefer1.nim @@ -7,7 +7,7 @@ B A''' """ -# bug #1742 +# bug https://github.com/nim-lang/nim/issues/1742 import strutils let x = try: parseInt("133a") diff --git a/tests/exception/tdont_overwrite_typename.nim b/tests/exception/tdont_overwrite_typename.nim index 6d41689a6a7..0b67dc9e52d 100644 --- a/tests/exception/tdont_overwrite_typename.nim +++ b/tests/exception/tdont_overwrite_typename.nim @@ -1,10 +1,9 @@ discard """ - targets: "c" output: '''Check passed Check passed''' """ -# bug #5628 +# bug https://github.com/nim-lang/nim/issues/5628 proc checkException(ex: ref Exception) = doAssert(ex.name == cstring"ValueError") diff --git a/tests/exception/texcas.nim b/tests/exception/texcas.nim index 814809b6b0d..fdbbf678b9a 100644 --- a/tests/exception/texcas.nim +++ b/tests/exception/texcas.nim @@ -1,5 +1,4 @@ discard """ - targets: "c" output: ''' Hello Hello @@ -34,7 +33,7 @@ test[Exception]() test2() testTryAsExpr(5) -# see bug #7115 +# bug https://github.com/nim-lang/nim/issues/7115 doAssert(not compiles( try: echo 1 diff --git a/tests/exception/texception_inference.nim b/tests/exception/texception_inference.nim index c0cb212028f..2659df51a89 100644 --- a/tests/exception/texception_inference.nim +++ b/tests/exception/texception_inference.nim @@ -1,7 +1,6 @@ discard """ output: '''good''' - joinable: false - cmd: "nim c --gc:orc -d:release $file" + matrix: "-d:release" """ type diff --git a/tests/exception/texception_message_null_byte.nim b/tests/exception/texception_message_null_byte.nim index 72599038d67..6519b3f659c 100644 --- a/tests/exception/texception_message_null_byte.nim +++ b/tests/exception/texception_message_null_byte.nim @@ -5,46 +5,14 @@ description: ''' . Error output produced by raise newException is inconsistent with other IO such as echo or stdout.write. ''' -joinable: false +matrix: ";-d:debug;-d:danger" +outputsub: "` and works fine! [Exception]" +exitcode: 1 """ -# marked as not joinable because this test self-executes - +# `\0` not preserved on windows, so only the trailing part can be reliably +# tested for const msg = "This char is `" & '\0' & "` and works fine!" -when defined nim_t13115: - # bug #13115 - template fn = - raise newException(Exception, msg) - when defined nim_t13115_static: - static: fn() - fn() -else: - import std/[osproc,strformat,os,strutils] - proc main = - const nim = getCurrentCompilerExe() - const file = currentSourcePath - for b in "c js".split: - when defined(openbsd): - if b == "js": - # xxx bug: pending #13115 - # remove special case once nodejs updated >= 12.16.2 - # refs https://github.com/nim-lang/Nim/pull/16167#issuecomment-738270751 - continue - - # save CI time by avoiding mostly redundant combinations as far as this bug is concerned - var opts = case b - of "c": @["", "-d:nim_t13115_static", "-d:danger", "-d:debug"] - of "js": @["", "-d:nim_t13115_static"] - else: @[""] - - for opt in opts: - let cmd = fmt"{nim} r -b:{b} -d:nim_t13115 {opt} --hints:off {file}" - let (outp, exitCode) = execCmdEx(cmd) - when defined windows: - # `\0` not preserved on windows - doAssert "` and works fine!" in outp, cmd & "\n" & msg - else: - doAssert msg in outp, cmd & "\n" & msg - doAssert exitCode == 1 - main() \ No newline at end of file +# bug https://github.com/nim-lang/nim/issues/13115 +raise newException(Exception, msg) \ No newline at end of file diff --git a/tests/exception/texception_name.nim b/tests/exception/texception_name.nim index 59eab320147..052d055ff6b 100644 --- a/tests/exception/texception_name.nim +++ b/tests/exception/texception_name.nim @@ -1,6 +1,5 @@ discard """ description: "Tests to make sure that the Exception.name field is set" - targets: "c js" """ template test(desc, body) {.dirty.} = @@ -9,8 +8,6 @@ template test(desc, body) {.dirty.} = proc wrapper() = body - # TODO: once it's available in testament, use the VM target instead - static: wrapper() wrapper() @@ -46,10 +43,12 @@ test "Name is set on raise if it was unset": except IOError as e: doAssert e.name == "IOError" - -# fails for the VM. See ``texception_name_vm_issue.nim`` -block no_override_empty: +test "Don't override an explicitly empty name": try: raise (ref IOError)(name: "") # explicitly set name to an empty string except IOError as e: - doAssert e.name == "" \ No newline at end of file + when defined(vm): + # see ``texception_name_vm_issue.nim`` + doAssert e.name != "", "works now" + else: + doAssert e.name == "" \ No newline at end of file diff --git a/tests/exception/texception_name_vm_issue.nim b/tests/exception/texception_name_vm_issue.nim index 34d1031e307..0943e74615c 100644 --- a/tests/exception/texception_name_vm_issue.nim +++ b/tests/exception/texception_name_vm_issue.nim @@ -1,5 +1,5 @@ discard """ - action: compile + target: "vm" description: '''An empty exception name is overridden on raise when run in the VM''' knownIssue @@ -7,8 +7,7 @@ discard """ # The VM treats `cstring(nil)` and `cstring("")` as the same thing -static: - try: - raise (ref CatchableError)(name: "") - except CatchableError as e: - doAssert e.name == "" \ No newline at end of file +try: + raise (ref CatchableError)(name: "") +except CatchableError as e: + doAssert e.name == "" \ No newline at end of file diff --git a/tests/exception/texceptions.nim b/tests/exception/texceptions.nim index 33a9436d030..573dfccbe1e 100644 --- a/tests/exception/texceptions.nim +++ b/tests/exception/texceptions.nim @@ -1,5 +1,4 @@ discard """ - matrix: "--exceptions:goto" output: ''' BEFORE @@ -14,6 +13,9 @@ BEFORE EXCEPT: IOError: hi FINALLY ''' + knownIssue.vm: ''' + Exception/finally handling is largely disfunctional in the VM + ''' """ echo "" @@ -57,7 +59,8 @@ proc return_in_except = raise newException(IOError, "hi") except: - echo "EXCEPT: ", getCurrentException().name, ": ", getCurrentExceptionMsg() + let e = getCurrentException() + echo "EXCEPT: ", e.name, ": ", e.msg return finally: @@ -66,7 +69,7 @@ proc return_in_except = try: return_in_except() except: echo "RECOVER" -block: #10417 +block: # https://github.com/nim-lang/nim/issues/10417 proc moo() {.noreturn.} = discard let bar = @@ -84,10 +87,10 @@ block: try: raise newException(ValueError, "xx") except: - doAssert("xx" == getCurrentExceptionMsg()) + doAssert("xx" == getCurrentException().msg) raise newException(KeyError, "yy") except: - doAssert("yy" == getCurrentExceptionMsg()) + doAssert("yy" == getCurrentException().msg) result.add(1212) try: try: diff --git a/tests/exception/texceptions2.nim b/tests/exception/texceptions2.nim deleted file mode 100644 index 33a9436d030..00000000000 --- a/tests/exception/texceptions2.nim +++ /dev/null @@ -1,129 +0,0 @@ -discard """ - matrix: "--exceptions:goto" - output: ''' - -BEFORE -FINALLY - -BEFORE -EXCEPT -FINALLY -RECOVER - -BEFORE -EXCEPT: IOError: hi -FINALLY -''' -""" - -echo "" - -proc no_exception = - try: - echo "BEFORE" - - except: - echo "EXCEPT" - raise - - finally: - echo "FINALLY" - -try: no_exception() -except: echo "RECOVER" - -echo "" - -proc reraise_in_except = - try: - echo "BEFORE" - raise newException(IOError, "") - - except IOError: - echo "EXCEPT" - raise - - finally: - echo "FINALLY" - -try: reraise_in_except() -except: echo "RECOVER" - -echo "" - -proc return_in_except = - try: - echo "BEFORE" - raise newException(IOError, "hi") - - except: - echo "EXCEPT: ", getCurrentException().name, ": ", getCurrentExceptionMsg() - return - - finally: - echo "FINALLY" - -try: return_in_except() -except: echo "RECOVER" - -block: #10417 - proc moo() {.noreturn.} = discard - - let bar = - try: - 1 - except: - moo() - - doAssert(bar == 1) - -# Make sure the VM handles the exceptions correctly -block: - proc fun1(): seq[int] = - try: - try: - raise newException(ValueError, "xx") - except: - doAssert("xx" == getCurrentExceptionMsg()) - raise newException(KeyError, "yy") - except: - doAssert("yy" == getCurrentExceptionMsg()) - result.add(1212) - try: - try: - raise newException(AssertionDefect, "a") - finally: - result.add(42) - except AssertionDefect: - result.add(99) - finally: - result.add(10) - result.add(4) - result.add(0) - try: - result.add(1) - except KeyError: - result.add(-1) - except ValueError: - result.add(-1) - except IndexDefect: - result.add(2) - except: - result.add(3) - - try: - try: - result.add(1) - return - except: - result.add(-1) - finally: - result.add(2) - except KeyError: - doAssert(false) - finally: - result.add(3) - - let x1 = fun1() - const x2 = fun1() - doAssert(x1 == x2) diff --git a/tests/exception/texcpt1.nim b/tests/exception/texcpt1.nim index 835f3610afc..5f97649e51f 100644 --- a/tests/exception/texcpt1.nim +++ b/tests/exception/texcpt1.nim @@ -29,7 +29,7 @@ proc blah(): int = echo blah() -# Issue #7845, raise generic exception +# https://github.com/nim-lang/nim/issues/7845, raise generic exception var x: ref ESomethingGen[int] new(x) try: diff --git a/tests/exception/tfinally.nim b/tests/exception/tfinally.nim index c5b1dd84143..2bb68b6a532 100644 --- a/tests/exception/tfinally.nim +++ b/tests/exception/tfinally.nim @@ -13,6 +13,9 @@ finally1 except2 finally2 ''' + knownIssue.vm: ''' + Exception/finally handling is largely disfunctional in the VM + ''' """ # Test return in try statement: @@ -29,7 +32,7 @@ proc main: int = echo main() #OUT came here 3 -#bug 7204 +#bug https://github.com/nim-lang/nim/issues/7204 proc nested_finally = try: raise newException(KeyError, "msg1") @@ -38,7 +41,7 @@ proc nested_finally = try: raise newException(ValueError, "msg2") except: - echo getCurrentExceptionMsg() + echo getCurrentException().msg finally: echo "finally2" finally: @@ -47,7 +50,7 @@ proc nested_finally = nested_finally() echo "-----------" -#bug 7414 +#bug https://github.com/nim-lang/nim/issues/7414 try: try: raise newException(Exception, "Hello") diff --git a/tests/exception/tfinally2.nim b/tests/exception/tfinally2.nim index dae1a468a5a..dace6fb2f45 100644 --- a/tests/exception/tfinally2.nim +++ b/tests/exception/tfinally2.nim @@ -1,10 +1,13 @@ discard """ -output: ''' + output: ''' A B C D ''' + knownIssue.vm: ''' + Exception/finally handling is largely disfunctional in the VM + ''' """ # Test break in try statement: diff --git a/tests/exception/tfinally3.nim b/tests/exception/tfinally3.nim index 9053d397d33..00a80f9fad9 100644 --- a/tests/exception/tfinally3.nim +++ b/tests/exception/tfinally3.nim @@ -4,6 +4,9 @@ false Within finally->try ''' exitCode: 1 + knownIssue.vm: ''' + Exception/finally handling is largely disfunctional in the VM + ''' """ # Test break in try statement: @@ -17,11 +20,11 @@ proc main: bool = echo main() #OUT false -# bug #5871 +# bug https://github.com/nim-lang/nim/issues/5871 try: raise newException(Exception, "First") finally: try: raise newException(Exception, "Within finally->try") except: - echo getCurrentExceptionMsg() + echo getCurrentException().msg diff --git a/tests/exception/tnestedreturn.nim b/tests/exception/tnestedreturn.nim index 18e6f6f2112..0af5c141fda 100644 --- a/tests/exception/tnestedreturn.nim +++ b/tests/exception/tnestedreturn.nim @@ -1,5 +1,4 @@ discard """ - targets: "c" output: "A\nB\nC\n" """ diff --git a/tests/exception/tsetexceptions.nim b/tests/exception/tsetexceptions.nim index 8c501e3dc5c..9763b716781 100644 --- a/tests/exception/tsetexceptions.nim +++ b/tests/exception/tsetexceptions.nim @@ -1,6 +1,6 @@ discard """ - targets: "c js" joinable: false + knownIssue.vm: "`setCurrentException` is not supported" """ # refs https://github.com/nim-lang/Nim/pull/18247#issuecomment-860877161 diff --git a/tests/exception/tunhandled_in_non_main.nim b/tests/exception/tunhandled_in_non_main.nim index 35625715b5a..48f0e9df7d8 100644 --- a/tests/exception/tunhandled_in_non_main.nim +++ b/tests/exception/tunhandled_in_non_main.nim @@ -1,5 +1,4 @@ discard """ - targets: "c js vm" description: ''' An unhandled exception not raised inside the main module must also terminate the program diff --git a/tests/exception/tunhandledexc.nim b/tests/exception/tunhandledexc.nim index 6ca311d38fe..2d2bd646789 100644 --- a/tests/exception/tunhandledexc.nim +++ b/tests/exception/tunhandledexc.nim @@ -1,8 +1,10 @@ discard """ - cmd: "nim $target -d:release $options $file" - outputsub: '''tunhandledexc.nim(15) genErrors + matrix: "-d:release" + outputsub: '''tunhandledexc.nim(17) genErrors Error: unhandled exception: bla [ESomeOtherErr]''' exitcode: "1" + knownIssue.vm: "the stacktrace points to the wrong line" + knownIssue.js: "the output doesn't match the expectation" """ type ESomething = object of Exception diff --git a/tests/exception/twrongexc.nim b/tests/exception/twrongexc.nim index d229c57493f..ecd6160a683 100644 --- a/tests/exception/twrongexc.nim +++ b/tests/exception/twrongexc.nim @@ -1,6 +1,7 @@ discard """ outputsub: "Error: unhandled exception: [ValueError]" exitcode: "1" + knownIssue.js: "the 'uncaught exception' message doesn't match" """ try: raise newException(ValueError, "")