diff options
Diffstat (limited to 'tests')
41 files changed, 113 insertions, 161 deletions
diff --git a/tests/async/tasync_misc.nim b/tests/async/tasync_misc.nim index 695dcd98a..dbc2ea434 100644 --- a/tests/async/tasync_misc.nim +++ b/tests/async/tasync_misc.nim @@ -37,8 +37,7 @@ block: #8399 case line[0] of '+', '-': @[] of '$': (let x = await bar(); @[""]) - else: - nil + else: @[] doAssert(res == @[""]) diff --git a/tests/async/tasyncssl.nim b/tests/async/tasyncssl.nim index 3dc131036..0607cf3c6 100644 --- a/tests/async/tasyncssl.nim +++ b/tests/async/tasyncssl.nim @@ -15,11 +15,11 @@ when defined(ssl): var clientCount = 0 proc sendMessages(client: AsyncSocket) {.async.} = - for i in 0 .. <messagesToSend: + for i in 0 ..< messagesToSend: await send(client, "Message " & $i & "\c\L") proc launchSwarm(port: Port) {.async.} = - for i in 0 .. <swarmSize: + for i in 0 ..< swarmSize: var sock = newAsyncSocket() var clientContext = newContext(verifyMode = CVerifyNone) clientContext.wrapSocket(sock) diff --git a/tests/casestmt/tcasestm.nim b/tests/casestmt/tcasestm.nim index 4d32d023f..ff912ffab 100644 --- a/tests/casestmt/tcasestm.nim +++ b/tests/casestmt/tcasestm.nim @@ -41,16 +41,16 @@ let str2 = "NN" let a = case str1: of "Y": true of "N": false - else: + else: echo "no good" quit("quiting") -proc toBool(s: string): bool = +proc toBool(s: string): bool = case s: - of nil, "": raise newException(ValueError, "Invalid boolean") - elif s[0] == 'Y': true - elif s[0] == 'N': false - else: "error".quit(2) + of "": raise newException(ValueError, "Invalid boolean") + elif s[0] == 'Y': true + elif s[0] == 'N': false + else: "error".quit(2) let b = "NN".toBool() @@ -66,7 +66,7 @@ static: var bb: bool doassert(not compiles( bb = case str2: - of nil, "": raise newException(ValueError, "Invalid boolean") + of "": raise newException(ValueError, "Invalid boolean") elif str.startsWith("Y"): true elif str.startsWith("N"): false )) @@ -94,7 +94,7 @@ doassert(not compiles( bb = case str2: of "Y": raise newException(ValueError, "Invalid Y") - true + true else: raise newException(ValueError, "Invalid") )) @@ -103,6 +103,6 @@ doassert(not compiles( bb = case str2: of "Y": "invalid Y".quit(3) - true + true else: raise newException(ValueError, "Invalid") )) \ No newline at end of file diff --git a/tests/cpp/tasync_cpp.nim b/tests/cpp/tasync_cpp.nim index a5e3374b6..50bc1853c 100644 --- a/tests/cpp/tasync_cpp.nim +++ b/tests/cpp/tasync_cpp.nim @@ -1,6 +1,7 @@ discard """ targets: "cpp" output: "hello" + cmd: "nim cpp --nilseqs:on $file" """ # bug #3299 diff --git a/tests/distinct/tnil.nim b/tests/distinct/tnil.nim index 759a14657..16de38f60 100644 --- a/tests/distinct/tnil.nim +++ b/tests/distinct/tnil.nim @@ -9,7 +9,6 @@ discard """ type MyPointer = distinct pointer MyString = distinct string - MyStringNotNil = distinct (string not nil) MyInt = distinct int proc foo(a: MyPointer) = @@ -26,20 +25,6 @@ p = cast[MyPointer](nil) p = nil.MyPointer p = nil -var c: MyString -c = "Test".MyString -c = nil.MyString -c = nil - -p = nil -doAssert(compiles(c = p) == false) - -var n: MyStringNotNil = "Test".MyStringNotNil # Cannot prove warning ... -n = "Test".MyStringNotNil -doAssert(compiles(n = nil.MyStringNotNil) == false) -doAssert(compiles(n = nil.MyStringNotNil) == false) -doAssert(compiles(n = nil) == false) - var i: MyInt i = 1.MyInt doAssert(compiles(i = nil) == false) diff --git a/tests/exception/tdont_overwrite_typename.nim b/tests/exception/tdont_overwrite_typename.nim index 6e3ff816f..d6dca0990 100644 --- a/tests/exception/tdont_overwrite_typename.nim +++ b/tests/exception/tdont_overwrite_typename.nim @@ -7,10 +7,10 @@ Check passed''' # bug #5628 proc checkException(ex: ref Exception) = - doAssert(ex.name == "ValueError") + doAssert(ex.name == cstring"ValueError") doAssert(ex.msg == "SecondException") doAssert(ex.parent != nil) - doAssert(ex.parent.name == "KeyError") + doAssert(ex.parent.name == cstring"KeyError") doAssert(ex.parent.msg == "FirstException") echo "Check passed" diff --git a/tests/exprs/tstmtexprs.nim b/tests/exprs/tstmtexprs.nim index 61089b694..615c36024 100644 --- a/tests/exprs/tstmtexprs.nim +++ b/tests/exprs/tstmtexprs.nim @@ -87,7 +87,7 @@ proc parseResponse(): JsonNode = var excMsg = key & "(" if (var n=result["key2"]; n != nil): excMsg &= n.str - raise newException(SystemError, excMsg) + raise newException(CatchableError, excMsg) diff --git a/tests/generics/tgeneric3.nim b/tests/generics/tgeneric3.nim index d014eb998..6897d9de2 100644 --- a/tests/generics/tgeneric3.nim +++ b/tests/generics/tgeneric3.nim @@ -103,7 +103,7 @@ proc DeleteItem[T,D] (n: PNode[T,D], x: int): PNode[T,D] {.inline.} = else : result = n.left - n.slots = nil + n.slots = @[] n.left = nil proc internalDelete[T,D] (ANode: PNode[T,D], key: T, Avalue: var D): PNode[T,D] = @@ -200,7 +200,7 @@ proc traceTree[T,D](root: PNode[T,D]) = traceln(space) write stdout, "left: " doTrace(n.left, level+1) - for i, el in n.slots : + for i, el in n.slots: if el != nil and not isClean(el): traceln(space) traceX(i) diff --git a/tests/generics/tobjecttyperel.nim b/tests/generics/tobjecttyperel.nim index 8c8f90098..6c2184cc2 100644 --- a/tests/generics/tobjecttyperel.nim +++ b/tests/generics/tobjecttyperel.nim @@ -2,8 +2,8 @@ discard """ output: '''(peel: 0, color: 15) (color: 15) 17 -(width: 0.0, taste: nil, color: 13) -(width: 0.0, taste: nil, color: 15) +(width: 0.0, taste: "", color: 13) +(width: 0.0, taste: "", color: 15) cool''' """ @@ -11,16 +11,16 @@ cool''' type BaseFruit[T] = object of RootObj color: T - + MidLevel[T] = object of BaseFruit[T] - + Mango = object of MidLevel[int] peel: int - + Peach[X, T, Y] = object of T width: X taste: Y - + proc setColor[T](self: var BaseFruit[T]) = self.color = 15 diff --git a/tests/js/tclosures.nim b/tests/js/tclosures.nim index 67243c937..659c60092 100644 --- a/tests/js/tclosures.nim +++ b/tests/js/tclosures.nim @@ -48,4 +48,4 @@ for i in 1 .. 10: let results = runCallbacks() -doAssert(expected == results) +doAssert(expected == $results) diff --git a/tests/js/testobjs.nim b/tests/js/testobjs.nim index dd66825ec..78f0b4766 100644 --- a/tests/js/testobjs.nim +++ b/tests/js/testobjs.nim @@ -34,7 +34,7 @@ var recurse1 = Recurse[int](data: 1, next: recurse2) -doAssert test.name == "Jorden" +doAssert test.name == cstring"Jorden" doAssert knight.age == 19 doAssert knight.item.price == 50 doAssert recurse1.next.next.data == 3 diff --git a/tests/js/tjsffi.nim b/tests/js/tjsffi.nim index 325ab6366..156ca89e3 100644 --- a/tests/js/tjsffi.nim +++ b/tests/js/tjsffi.nim @@ -64,7 +64,7 @@ block: proc test(): bool = let obj = newJsObject() obj.`?!$` = proc(x, y, z: int, t: cstring): cstring = t & $(x + y + z) - obj.`?!$`(1, 2, 3, "Result is: ").to(cstring) == "Result is: 6" + obj.`?!$`(1, 2, 3, "Result is: ").to(cstring) == cstring"Result is: 6" echo test() # Test JsObject []() diff --git a/tests/macros/tforloop_macro1.nim b/tests/macros/tforloop_macro1.nim index a8f45c7ac..49918563d 100644 --- a/tests/macros/tforloop_macro1.nim +++ b/tests/macros/tforloop_macro1.nim @@ -12,7 +12,7 @@ discard """ """ import macros - +{.experimental: "forLoopMacros".} macro mymacro(): untyped = result = newLit([1, 2, 3]) diff --git a/tests/manyloc/argument_parser/argument_parser.nim b/tests/manyloc/argument_parser/argument_parser.nim index 1095a893e..985139f0a 100644 --- a/tests/manyloc/argument_parser/argument_parser.nim +++ b/tests/manyloc/argument_parser/argument_parser.nim @@ -74,14 +74,14 @@ type ## nothing prevents you from accessing directly the type of field you want ## if you expect only one kind. case kind*: Tparam_kind - of PK_EMPTY: nil + of PK_EMPTY: discard of PK_INT: int_val*: int of PK_BIGGEST_INT: big_int_val*: BiggestInt of PK_FLOAT: float_val*: float of PK_BIGGEST_FLOAT: big_float_val*: BiggestFloat of PK_STRING: str_val*: string of PK_BOOL: bool_val*: bool - of PK_HELP: nil + of PK_HELP: discard Tcommandline_results* = object of RootObj ## \ ## Contains the results of the parsing. @@ -319,7 +319,7 @@ proc echo_help*(expected: seq[Tparameter_specification] = @[], proc parse*(expected: seq[Tparameter_specification] = @[], - type_of_positional_parameters = PK_STRING, args: seq[TaintedString] = nil, + type_of_positional_parameters = PK_STRING, args: seq[TaintedString] = @[], bad_prefixes = @["-", "--"], end_of_options = "--", quit_on_failure = true): Tcommandline_results = ## Parses parameters and returns results. @@ -339,7 +339,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[], ## ## The args sequence should be the list of parameters passed to your program ## without the program binary (usually OSes provide the path to the binary as - ## the zeroth parameter). If args is nil, the list will be retrieved from the + ## the zeroth parameter). If args is empty, the list will be retrieved from the ## OS. ## ## If there is any kind of error and quit_on_failure is true, the quit proc @@ -358,7 +358,7 @@ proc parse*(expected: seq[Tparameter_specification] = @[], # Prepare the input parameter list, maybe get it from the OS if not available. var args = args - if args == nil: + if args.len == 0: let total_params = paramCount() #echo "Got no explicit args, retrieving from OS. Count: ", total_params newSeq(args, total_params) diff --git a/tests/manyloc/keineschweine/lib/sg_assets.nim b/tests/manyloc/keineschweine/lib/sg_assets.nim index 1e8a99c83..90f0a54e9 100644 --- a/tests/manyloc/keineschweine/lib/sg_assets.nim +++ b/tests/manyloc/keineschweine/lib/sg_assets.nim @@ -145,7 +145,7 @@ proc importHandling(data: JsonNode): THandlingRecord proc importBullet(data: JsonNode; errors: var seq[string]): PBulletRecord proc importSoul(data: JsonNode): TSoulRecord proc importExplosion(data: JsonNode; errors: var seq[string]): TExplosionRecord -proc importSound*(data: JsonNode; errors: var seq[string]; fieldName: string = nil): PSoundRecord +proc importSound*(data: JsonNode; errors: var seq[string]; fieldName: string = ""): PSoundRecord ## this is the only pipe between lobby and main.nim proc getActiveState*(): TGameState = @@ -514,7 +514,7 @@ proc importExplosion(data: JsonNode; errors: var seq[string]): TExplosionRecord let expl = data["explode"] result.anim = importAnim(expl, errors) result.sound = importSound(expl, errors, "sound") -proc importSound*(data: JsonNode; errors: var seq[string]; fieldName: string = nil): PSoundRecord = +proc importSound*(data: JsonNode; errors: var seq[string]; fieldName: string = ""): PSoundRecord = if data.kind == JObject: checkKey(data, fieldName) result = newSound(data[fieldName].str, errors) diff --git a/tests/manyloc/keineschweine/lib/sg_gui.nim b/tests/manyloc/keineschweine/lib/sg_gui.nim index 95cef1b24..074e0604c 100644 --- a/tests/manyloc/keineschweine/lib/sg_gui.nim +++ b/tests/manyloc/keineschweine/lib/sg_gui.nim @@ -92,8 +92,8 @@ proc newGuiContainer*(pos: TVector2f): PGuiContainer = result = newGuiContainer() result.setPosition pos proc free*(container: PGuiContainer) = - container.widgets = nil - container.buttons = nil + container.widgets = @[] + container.buttons = @[] proc add*(container: PGuiContainer; widget: PGuiObject) = container.widgets.add(widget) proc add*(container: PGuiContainer; button: PButton) = diff --git a/tests/notnil/tmust_compile.nim b/tests/notnil/tmust_compile.nim index a32c6c7ec..d09dda057 100644 --- a/tests/notnil/tmust_compile.nim +++ b/tests/notnil/tmust_compile.nim @@ -44,16 +44,16 @@ import json type foo = object - thing: string not nil + thing: ptr int not nil CTS = ref object subs_by_sid: Table[int, foo] proc parse(cts: CTS, jn: JsonNode) = - + var y = jn.getInt(4523) let ces = foo( - thing: jn.getStr("thing") + thing: addr y ) cts.subs_by_sid[0] = ces @@ -63,17 +63,3 @@ proc parse(cts: CTS, jn: JsonNode) = proc p(x: proc(){.closure.} not nil) = discard p(proc(){.closure.} = discard) - -# bug #3993 - -type - List[T] = seq[T] not nil - -proc `^^`[T](v: T, lst: List[T]): List[T] = - result = @[v] - result.add(lst) - -proc Nil[T](): List[T] = @[] - -when isMainModule: - let lst = 1 ^^ 2 ^^ Nil[int]() diff --git a/tests/notnil/tnotnil.nim b/tests/notnil/tnotnil.nim index e392b155c..aff3f8959 100644 --- a/tests/notnil/tnotnil.nim +++ b/tests/notnil/tnotnil.nim @@ -1,5 +1,5 @@ discard """ - line: 22 + line: 13 errormsg: "type mismatch" """ {.experimental: "notnil".} @@ -8,16 +8,6 @@ type TObj = object x: int - MyString = string not nil - -#var x: PObj = nil - -proc p(x: string not nil): int = - result = 45 - -proc q(x: MyString) = discard proc q2(x: string) = discard q2(nil) -q(nil) - diff --git a/tests/notnil/tnotnil1.nim b/tests/notnil/tnotnil1.nim index 7f9d02295..60666d64d 100644 --- a/tests/notnil/tnotnil1.nim +++ b/tests/notnil/tnotnil1.nim @@ -1,6 +1,6 @@ discard """ errormsg: "'y' is provably nil" - line:38 + line:25 """ import strutils @@ -10,19 +10,6 @@ type TObj = object x, y: int -type - superstring = string not nil - - -proc q(s: superstring) = - echo s - -proc p2() = - var a: string = "I am not nil" - q(a) # but this should and does not - -p2() - proc q(x: pointer not nil) = discard diff --git a/tests/notnil/tnotnil_in_objconstr.nim b/tests/notnil/tnotnil_in_objconstr.nim index d33709906..f0d5c1ae2 100644 --- a/tests/notnil/tnotnil_in_objconstr.nim +++ b/tests/notnil/tnotnil_in_objconstr.nim @@ -6,9 +6,9 @@ discard """ # bug #2355 type Foo = object - foo: string not nil - bar: string not nil - + foo: ref int + bar: ref int not nil +var x: ref int = new(int) # Create instance without initializaing the `bar` field -var f = Foo(foo: "foo") +var f = Foo(foo: x) echo f.bar.isNil # true diff --git a/tests/parallel/tptr_to_ref.nim b/tests/parallel/tptr_to_ref.nim index fee210dcd..ae02c16e5 100644 --- a/tests/parallel/tptr_to_ref.nim +++ b/tests/parallel/tptr_to_ref.nim @@ -11,7 +11,7 @@ type Killer* = object lock: Lock bailed {.guard: lock.}: bool - processes {.guard: lock.}: array[0..MAX_WORKERS-1, foreign ptr Process] + processes {.guard: lock.}: array[0..MAX_WORKERS-1, ptr Process] # Hold a lock for a statement. template hold(lock: Lock, body: untyped) = @@ -32,7 +32,7 @@ proc initKiller*(): Killer = var killer = initKiller() # remember that a process has been launched, killing it if we have bailed. -proc launched*(process: foreign ptr Process): int {.gcsafe.} = +proc launched*(process: ptr Process): int {.gcsafe.} = result = killer.processes.high + 1 killer.lock.hold: if killer.bailed: diff --git a/tests/parallel/twaitany.nim b/tests/parallel/twaitany.nim index 69136a3b6..fcabf691e 100644 --- a/tests/parallel/twaitany.nim +++ b/tests/parallel/twaitany.nim @@ -18,12 +18,12 @@ var results: seq[int] = @[] for i in 0 .. durations.high: tasks.add spawn timer(durations[i]) -var index = awaitAny(tasks) +var index = blockUntilAny(tasks) while index != -1: results.add ^cast[FlowVar[int]](tasks[index]) tasks.del(index) #echo repr results - index = awaitAny(tasks) + index = blockUntilAny(tasks) doAssert results.len == 5 doAssert 1000 in results diff --git a/tests/pragmas/custom_pragma.nim b/tests/pragmas/custom_pragma.nim index 9e8f51deb..d2fc969d0 100644 --- a/tests/pragmas/custom_pragma.nim +++ b/tests/pragmas/custom_pragma.nim @@ -2,4 +2,4 @@ template serializationKey*(s: string) {.pragma.} template defaultValue*(V: typed) {.pragma.} -template alternativeKey*(s: string = nil, V: typed) {.pragma.} \ No newline at end of file +template alternativeKey*(s: string = "", V: typed) {.pragma.} diff --git a/tests/stdlib/nre/captures.nim b/tests/stdlib/nre/captures.nim index 19c344a8d..31de71154 100644 --- a/tests/stdlib/nre/captures.nim +++ b/tests/stdlib/nre/captures.nim @@ -27,7 +27,7 @@ suite "captures": let ex2 = "foo".find(re("(?<foo>foo)(?<bar>bar)?")) check(ex2.captures["foo"] == "foo") - check(ex2.captures["bar"] == nil) + check(ex2.captures["bar"] == "") test "named capture bounds": let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?")) @@ -41,7 +41,7 @@ suite "captures": test "named capture table": let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?")) - check(ex1.captures.toTable == {"foo" : "foo", "bar" : nil}.toTable()) + check(ex1.captures.toTable == {"foo" : "foo", "bar" : ""}.toTable()) check(ex1.captureBounds.toTable == {"foo" : some(0..2), "bar" : none(Slice[int])}.toTable()) check(ex1.captures.toTable("") == {"foo" : "foo", "bar" : ""}.toTable()) @@ -50,7 +50,7 @@ suite "captures": test "capture sequence": let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?")) - check(ex1.captures.toSeq == @["foo", nil]) + check(ex1.captures.toSeq == @["foo", ""]) check(ex1.captureBounds.toSeq == @[some(0..2), none(Slice[int])]) check(ex1.captures.toSeq("") == @["foo", ""]) diff --git a/tests/stdlib/nre/replace.nim b/tests/stdlib/nre/replace.nim index 516fd4328..b762271a2 100644 --- a/tests/stdlib/nre/replace.nim +++ b/tests/stdlib/nre/replace.nim @@ -16,5 +16,5 @@ suite "replace": check("123".replace(re"(?<foo>\d)(\d)", "${foo}$#$#") == "1123") test "replacing missing captures should throw instead of segfaulting": - expect ValueError: discard "ab".replace(re"(a)|(b)", "$1$2") - expect ValueError: discard "b".replace(re"(a)?(b)", "$1$2") + discard "ab".replace(re"(a)|(b)", "$1$2") + discard "b".replace(re"(a)?(b)", "$1$2") diff --git a/tests/stdlib/tjsonmacro.nim b/tests/stdlib/tjsonmacro.nim index c0b4d5f78..bf0bb3ea7 100644 --- a/tests/stdlib/tjsonmacro.nim +++ b/tests/stdlib/tjsonmacro.nim @@ -40,7 +40,7 @@ when isMainModule: test: 18827361, test2: "hello world", test3: true, - testNil: nil + testNil: "nil" ) let node = %x @@ -53,7 +53,7 @@ when isMainModule: doAssert y.test == 18827361 doAssert y.test2 == "hello world" doAssert y.test3 - doAssert y.testNil.isNil + doAssert y.testNil == "nil" # Test for custom object variants (without an enum) and with an else branch. block: diff --git a/tests/stdlib/tnilecho.nim b/tests/stdlib/tnilecho.nim index 147b5e492..ec8d71dab 100644 --- a/tests/stdlib/tnilecho.nim +++ b/tests/stdlib/tnilecho.nim @@ -1,2 +1,6 @@ -var x = @["1", nil, "3"] -doAssert $x == "@[1, nil, 3]" +discard """ + output: "" +""" + +var x = @["1", "", "3"] +doAssert $x == """@["1", "", "3"]""" diff --git a/tests/system/tnilconcats.nim b/tests/system/tnilconcats.nim index ce059b7b0..5e4a1b317 100644 --- a/tests/system/tnilconcats.nim +++ b/tests/system/tnilconcats.nim @@ -1,5 +1,5 @@ discard """ - output: '''@[nil, nil, nil, nil, nil, nil, nil, "meh"]''' + output: '''@["", "", "", "", "", "", "", "meh"]''' exitcode: "0" """ diff --git a/tests/system/tostring.nim b/tests/system/tostring.nim index 9a6b83f95..99299f203 100644 --- a/tests/system/tostring.nim +++ b/tests/system/tostring.nim @@ -26,8 +26,8 @@ doAssert "nan" == $(0.0/0.0) var x: seq[string] doAssert "nil" == $(x) -var y: string = nil -doAssert nil == $(y) +var y: string +doAssert "" == $(y) type Foo = object @@ -54,7 +54,7 @@ doAssert $arr == "['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', ' doAssert $cstring(unsafeAddr arr) == "Hello World!" proc takes(c: cstring) = - doAssert c == "" + doAssert c == cstring"" proc testm() = var x: string @@ -90,12 +90,8 @@ proc stringCompare() = doAssert e == "" doAssert "" == e - doAssert nil == e - doAssert e == nil doAssert f == g doAssert "" == "" - doAssert "" == nil - doAssert nil == "" g.setLen(10) doAssert g == "\0\0\0\0\0\0\0\0\0\0" diff --git a/tests/template/mgensym_generic_cross_module.nim b/tests/template/mgensym_generic_cross_module.nim index 80b681db4..ea88f67e6 100644 --- a/tests/template/mgensym_generic_cross_module.nim +++ b/tests/template/mgensym_generic_cross_module.nim @@ -1,6 +1,6 @@ -template makeDomElement(x: untyped, name: string = nil) = - const tag {.gensym.} = if name == nil: astToStr(x) else: name +template makeDomElement(x: untyped, name: string = "") = + const tag {.gensym.} = if name.len == 0: astToStr(x) else: name proc x*(p: int|float) = echo tag, p diff --git a/tests/template/tdefault_nil.nim b/tests/template/tdefault_nil.nim index c5c372d9e..311a6c090 100644 --- a/tests/template/tdefault_nil.nim +++ b/tests/template/tdefault_nil.nim @@ -2,7 +2,7 @@ # bug #2629 import sequtils, os -template glob_rst(basedir: string = nil): untyped = +template glob_rst(basedir: string = ""): untyped = if baseDir.isNil: to_seq(walk_files("*.rst")) else: diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index fca6927d4..2c55bd0bd 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -260,6 +260,8 @@ proc jsTests(r: var TResults, cat: Category, options: string) = # ------------------------- nim in action ----------- proc testNimInAction(r: var TResults, cat: Category, options: string) = + let options = options & " --nilseqs:on" + template test(filename: untyped, action: untyped) = testSpec r, makeTest(filename, options, cat, action) @@ -488,7 +490,9 @@ proc processCategory(r: var TResults, cat: Category, options: string) = of "js": # only run the JS tests on Windows or Linux because Travis is bad # and other OSes like Haiku might lack nodejs: - when defined(linux) or defined(windows): + if not defined(linux) and isTravis: + discard + else: jsTests(r, cat, options) of "dll": dllTests(r, cat, options) diff --git a/tests/testament/specs.nim b/tests/testament/specs.nim index ac79e3942..fbe930a4f 100644 --- a/tests/testament/specs.nim +++ b/tests/testament/specs.nim @@ -12,8 +12,8 @@ import parseutils, strutils, os, osproc, streams, parsecfg var compilerPrefix* = "compiler" / "nim " -let isTravis = existsEnv("TRAVIS") -let isAppVeyor = existsEnv("APPVEYOR") +let isTravis* = existsEnv("TRAVIS") +let isAppVeyor* = existsEnv("APPVEYOR") proc cmdTemplate*(): string = compilerPrefix & "$target --lib:lib --hints:on -d:testing $options $file" diff --git a/tests/threads/tactors.nim b/tests/threads/tactors.nim index 45a03ebb7..ea052b9bd 100644 --- a/tests/threads/tactors.nim +++ b/tests/threads/tactors.nim @@ -5,9 +5,9 @@ discard """ import actors var - pool: TActorPool[int, void] + pool: ActorPool[int, void] createActorPool(pool) -for i in 0 .. < 300: +for i in 0 ..< 300: pool.spawn(i, proc (x: int) {.thread.} = echo x) pool.join() diff --git a/tests/tuples/tuple_with_nil.nim b/tests/tuples/tuple_with_nil.nim index ec48337bd..e09c53407 100644 --- a/tests/tuples/tuple_with_nil.nim +++ b/tests/tuples/tuple_with_nil.nim @@ -73,7 +73,7 @@ type const DefaultPrec = 6 ## Default precision for floating point numbers. - DefaultFmt: Format = (ftDefault, -1, -1, nil, faDefault, fsMinus, false, false, false, nil) + DefaultFmt: Format = (ftDefault, -1, -1, "", faDefault, fsMinus, false, false, false, "") ## Default format corresponding to the empty format string, i.e. ## `x.format("") == x.format(DefaultFmt)`. round_nums = [0.5, 0.05, 0.005, 0.0005, 0.00005, 0.000005, 0.0000005, 0.00000005] @@ -124,7 +124,7 @@ proc parse(fmt: string): Format {.nosideeffect.} = if fmt.rawmatch(p, 0, caps) < 0: raise newException(FormatError, "Invalid format string") - result.fill = fmt.get(caps, 0, nil) + result.fill = fmt.get(caps, 0, "") case fmt.get(caps, 1, 0.char) of '<': result.align = faLeft @@ -144,7 +144,7 @@ proc parse(fmt: string): Format {.nosideeffect.} = result.width = fmt.get(caps, 4, -1) if caps.has(4) and fmt[caps.bounds(4).first] == '0': - if result.fill != nil: + if result.fill != "": raise newException(FormatError, "Leading 0 in with not allowed with explicit fill character") if result.align != faDefault: raise newException(FormatError, "Leading 0 in with not allowed with explicit alignment") @@ -171,7 +171,7 @@ proc parse(fmt: string): Format {.nosideeffect.} = of '%': result.typ = ftPercent else: result.typ = ftDefault - result.arysep = fmt.get(caps, 8, nil, 1) + result.arysep = fmt.get(caps, 8, "", 1) proc getalign(fmt: Format; defalign: FmtAlign; slen: int) : tuple[left, right:int] {.nosideeffect.} = ## Returns the number of left and right padding characters for a @@ -218,7 +218,7 @@ proc writefill(o: var Writer; fmt: Format; n: int; signum: int = 0) = elif fmt.sign == fsPlus: write(o, '+') elif fmt.sign == fsSpace: write(o, ' ') - if fmt.fill == nil: + if fmt.fill.len == 0: for i in 1..n: write(o, ' ') else: for i in 1..n: @@ -626,19 +626,19 @@ proc splitfmt(s: string): seq[Part] {.compiletime, nosideeffect.} = else: lvl.dec let clpos = pos - var fmtpart = Part(kind: pkFmt, arg: -1, fmt: s.substr(oppos+1, clpos-1), field: nil, index: int.high, nested: nested) + var fmtpart = Part(kind: pkFmt, arg: -1, fmt: s.substr(oppos+1, clpos-1), field: "", index: int.high, nested: nested) if fmtpart.fmt.len > 0: var m: array[0..3, string] if not fmtpart.fmt.match(subpeg, m): error("invalid format string") - if m[1] != nil and m[1].len > 0: + if m[1].len > 0: fmtpart.field = m[1].substr(1) - if m[2] != nil and m[2].len > 0: + if m[2].len > 0: discard parseInt(m[2].substr(1, m[2].len-2), fmtpart.index) if m[0].len > 0: discard parseInt(m[0], fmtpart.arg) - if m[3] == nil or m[3].len == 0: + if m[3].len == 0: fmtpart.fmt = "" elif m[3][0] == ':': fmtpart.fmt = m[3].substr(1) @@ -650,7 +650,7 @@ proc splitfmt(s: string): seq[Part] {.compiletime, nosideeffect.} = proc literal(s: string): NimNode {.compiletime, nosideeffect.} = ## Return the nim literal of string `s`. This handles the case if ## `s` is nil. - result = if s == nil: newNilLit() else: newLit(s) + result = newLit(s) proc literal(b: bool): NimNode {.compiletime, nosideeffect.} = ## Return the nim literal of boolean `b`. This is either `true` @@ -713,7 +713,7 @@ proc generatefmt(fmtstr: string; args[arg].cnt = args[arg].cnt + 1 arg.inc # possible field access - if part.field != nil and part.field.len > 0: + if part.field.len > 0: argexpr = newDotExpr(argexpr, part.field.ident) # possible array access if part.index < int.high: @@ -724,7 +724,7 @@ proc generatefmt(fmtstr: string; # nested format string. Compute the format string by # concatenating the parts of the substring. for e in generatefmt(part.fmt, args, arg): - var newexpr = if part.fmt == nil: e.val else: newCall(bindsym"format", e.val, e.fmt) + var newexpr = if part.fmt.len == 0: e.val else: newCall(bindsym"format", e.val, e.fmt) if fmtexpr != nil and fmtexpr.kind != nnkNilLit: fmtexpr = infix(fmtexpr, "&", newexpr) else: diff --git a/tests/tuples/tuple_with_seq.nim b/tests/tuples/tuple_with_seq.nim index 39edb500f..00b07dd2c 100644 --- a/tests/tuples/tuple_with_seq.nim +++ b/tests/tuples/tuple_with_seq.nim @@ -3,8 +3,8 @@ discard """ @[1, 2, 3]''' """ -template foo(s: string = nil) = - if isNil(s): +template foo(s: string = "") = + if s.len == 0: echo "it's nil" else: echo s diff --git a/tests/types/temptyseqs.nim b/tests/types/temptyseqs.nim index 834f63729..28c3b87b8 100644 --- a/tests/types/temptyseqs.nim +++ b/tests/types/temptyseqs.nim @@ -22,7 +22,7 @@ when true: import os type - In_out = tuple[src, dest, options: string] + In_out = tuple[src, dest: string, options: ref int] let nil_var: In_out = ("hey"/"there", "something", nil) diff --git a/tests/vm/meta.nim b/tests/vm/meta.nim index 2aa01b5b3..32a441f27 100644 --- a/tests/vm/meta.nim +++ b/tests/vm/meta.nim @@ -39,7 +39,7 @@ proc newIdent*(node: NimNode): Ident = raise newException(ValueError, msg) proc render*(i: Ident): NimNode {.compileTime.} = - if i.name == nil: + if i.name == "": return newNimNode(nnkEmpty) if i.exported: @@ -67,7 +67,7 @@ proc newBracket*(node: NimNode): Bracket = raise newException(ValueError, msg) # Field procs -proc newField*(identifier: Ident, type_name: string, default: string = nil): Field = +proc newField*(identifier: Ident, type_name: string, default: string = ""): Field = result.identifier = identifier result.type_name = type_name result.default = default @@ -84,7 +84,7 @@ proc newField*(node: NimNode): Field = of nnkIdent: result.default = $(node[2]) else: - result.default = nil + result.default = "" else: let msg = "newField cannot initialize from node kind: " & $(node.kind) raise newException(ValueError, msg) @@ -102,7 +102,7 @@ proc newFieldSeq*(node: NimNode): FieldSeq = of nnkIdent: default = $(default_node) else: - default = nil + default = "" for i in 0..node.len - 3: let name = newIdent(node[i]) result.add(newField(name, type_name, default)) @@ -115,8 +115,8 @@ proc newFieldSeq*(node: NimNode): FieldSeq = proc render*(f: Field): NimNode {.compileTime.} = let identifier = f.identifier.render() - let type_name = if f.type_name != nil: ident(f.type_name) else: newEmptyNode() - let default = if f.default != nil: ident(f.default) else: newEmptyNode() + let type_name = if f.type_name != "": ident(f.type_name) else: newEmptyNode() + let default = if f.default != "": ident(f.default) else: newEmptyNode() newIdentDefs(identifier, type_name, default) proc render*(fs: FieldSeq): NimNode {.compileTime.} = @@ -127,7 +127,7 @@ proc render*(fs: FieldSeq): NimNode {.compileTime.} = # TypeDef procs proc newTypeDef*(identifier: Ident, is_ref = false, object_type = "object", - base_type: string = nil): TypeDef {.compileTime.} = + base_type: string = ""): TypeDef {.compileTime.} = result.identifier = identifier result.fields = @[] result.is_ref = is_ref @@ -165,7 +165,7 @@ proc render*(typedef: TypeDef): NimNode {.compileTime.} = result.add(newEmptyNode()) let object_node = newNimNode(nnkObjectTy) object_node.add(newEmptyNode()) - if typedef.base_type == nil: + if typedef.base_type == "": object_node.add(newEmptyNode()) else: var base_type = newNimNode(nnkOfInherit) @@ -195,8 +195,8 @@ proc render*(typeseq: TypeDefSeq): NimNode {.compileTime.} = for typedef in typeseq: result.add(typedef.render()) -proc newProc*(identifier: Ident, params: FieldSeq = nil, - returns: Ident, generics: FieldSeq = nil): Proc = +proc newProc*(identifier: Ident, params: FieldSeq = @[], + returns: Ident, generics: FieldSeq = @[]): Proc = result.identifier = identifier result.params = params result.returns = returns @@ -209,7 +209,7 @@ proc newProc*(node: NimNode): Proc = case node[2].kind: of nnkGenericParams: result.generics = newFieldSeq(node[2]) - else: result.generics = nil + else: result.generics = @[] let formal_params = node[3] case formal_params[0].kind: of nnkIdent: diff --git a/tests/vm/tcomponent.nim b/tests/vm/tcomponent.nim index e7962e7ab..b509bc5d7 100644 --- a/tests/vm/tcomponent.nim +++ b/tests/vm/tcomponent.nim @@ -11,7 +11,7 @@ FOO: blah''' import macros, sequtils, tables import strutils -import future, meta +import sugar, meta type Component = object diff --git a/tests/vm/tseq_badinit.nim b/tests/vm/tseq_badinit.nim index 15889d60e..5fa223c85 100644 --- a/tests/vm/tseq_badinit.nim +++ b/tests/vm/tseq_badinit.nim @@ -22,14 +22,14 @@ template test(typename, default: untyped) = result = newSeq[typename]() result.add(default) result.setLen(3) - for i in 0 .. <2: + for i in 0 ..< 2: result[i] = default const constval = `abc typename`() doAssert(constval == `abc typename`()) proc `arr typename`(): array[4, typename] = - for i in 0 .. <2: + for i in 0 ..< 2: result[i] = default const constarr = `arr typename`() doAssert(constarr == `arr typename`()) diff --git a/tests/vm/tstringnil.nim b/tests/vm/tstringnil.nim index 39e4040dc..df408910e 100644 --- a/tests/vm/tstringnil.nim +++ b/tests/vm/tstringnil.nim @@ -20,16 +20,16 @@ proc buildSuiteContents(suiteName, suiteDesc, suiteBloc: NimNode): tuple[tests: var testObj = SuiteTest() if suiteName.kind == nnkNilLit: - testObj.suiteName = nil + testObj.suiteName = "" else: testObj.suiteName = $suiteName if suiteDesc.kind == nnkNilLit: - testObj.suiteDesc = nil + testObj.suiteDesc = "" else: testObj.suiteDesc = suiteDesc.strVal testObj.testName = $child[1] # should not ever be nil if child[2].kind == nnkNilLit: - testObj.testDesc = nil + testObj.testDesc = "" else: testObj.testDesc = child[2].strVal testObj.testBlock = child[1] @@ -46,5 +46,5 @@ macro suite(suiteName, suiteDesc, suiteBloc: untyped): typed = # Test above suite basics, "Description of such": - test(t5, nil): + test(t5, ""): assert false |