diff options
Diffstat (limited to 'tests')
46 files changed, 582 insertions, 67 deletions
diff --git a/tests/async/tasyncawait.nim b/tests/async/tasyncawait.nim index e5895abe1..443f769cd 100644 --- a/tests/async/tasyncawait.nim +++ b/tests/async/tasyncawait.nim @@ -2,7 +2,7 @@ discard """ file: "tasyncawait.nim" output: "5000" """ -import asyncdispatch, rawsockets, net, strutils, os +import asyncdispatch, nativesockets, net, strutils, os var msgCount = 0 @@ -18,7 +18,7 @@ proc sendMessages(client: TAsyncFD) {.async.} = proc launchSwarm(port: TPort) {.async.} = for i in 0 .. <swarmSize: - var sock = newAsyncRawSocket() + var sock = newAsyncNativeSocket() await connect(sock, "localhost", port) await sendMessages(sock) @@ -38,7 +38,7 @@ proc readMessages(client: TAsyncFD) {.async.} = doAssert false proc createServer(port: TPort) {.async.} = - var server = newAsyncRawSocket() + var server = newAsyncNativeSocket() block: var name: Sockaddr_in when defined(windows): diff --git a/tests/async/tasyncconnect.nim b/tests/async/tasyncconnect.nim index b27a810b8..3dac379b2 100644 --- a/tests/async/tasyncconnect.nim +++ b/tests/async/tasyncconnect.nim @@ -19,7 +19,7 @@ when defined(windows) or defined(nimdoc): quit("Error: unhandled exception: Connection refused") else: proc testAsyncConnect() {.async.} = - var s = newAsyncRawSocket() + var s = newAsyncNativeSocket() await s.connect(testHost, testPort) diff --git a/tests/async/tasynceverror.nim b/tests/async/tasynceverror.nim index 2f570344f..22b4fe9a7 100644 --- a/tests/async/tasynceverror.nim +++ b/tests/async/tasynceverror.nim @@ -7,7 +7,7 @@ discard """ import asyncdispatch, asyncnet, - rawsockets, + nativesockets, os @@ -21,7 +21,7 @@ when defined(windows) or defined(nimdoc): quit("Error: unhandled exception: Connection reset by peer") else: proc createListenSocket(host: string, port: Port): TAsyncFD = - result = newAsyncRawSocket() + result = newAsyncNativeSocket() SocketHandle(result).setSockOptInt(SOL_SOCKET, SO_REUSEADDR, 1) diff --git a/tests/ccgbugs/twrong_discriminant_check.nim b/tests/ccgbugs/twrong_discriminant_check.nim new file mode 100644 index 000000000..a802f45ef --- /dev/null +++ b/tests/ccgbugs/twrong_discriminant_check.nim @@ -0,0 +1,30 @@ +discard """ + output: "(kind: None)" +""" + +when true: + # bug #2637 + + type + OptionKind = enum + None, + Some + + Option*[T] = object + case kind: OptionKind + of None: + discard + of Some: + value*: T + + proc none*[T](): Option[T] = + Option[T](kind: None) + + proc none*(T: typedesc): Option[T] = none[T]() + + + proc test(): Option[int] = + int.none + + echo test() + diff --git a/tests/closure/tclosure4.nim b/tests/closure/tclosure4.nim index 8e08376b6..10c7cac54 100644 --- a/tests/closure/tclosure4.nim +++ b/tests/closure/tclosure4.nim @@ -1,5 +1,5 @@ -import json, tables +import json, tables, sequtils proc run(json_params: TTable) = let json_elems = json_params["files"].elems diff --git a/tests/collections/tapply.nim b/tests/collections/tapply.nim new file mode 100644 index 000000000..2b7464216 --- /dev/null +++ b/tests/collections/tapply.nim @@ -0,0 +1,11 @@ +discard """ + output: '''true''' +""" + +import sequtils + +var x = @[1, 2, 3] +x.apply(proc(x: var int) = x = x+10) +x.apply(proc(x: int): int = x+100) +x.applyIt(it+5000) +echo x == @[5111, 5112, 5113] diff --git a/tests/collections/tmapit.nim b/tests/collections/tmapit.nim new file mode 100644 index 000000000..b2afa9429 --- /dev/null +++ b/tests/collections/tmapit.nim @@ -0,0 +1,33 @@ +discard """ + output: '''true +true''' +""" + +import sequtils + +var x = @[1, 2, 3] +# This mapIt call will run with preallocation because ``len`` is available. +var y = x.mapIt($(it+10)) +echo y == @["11", "12", "13"] + +type structureWithoutLen = object + a: array[5, int] + +iterator items(s: structureWithoutLen): int {.inline.} = + yield s.a[0] + yield s.a[1] + yield s.a[2] + yield s.a[3] + yield s.a[4] + +var st: structureWithoutLen +st.a[0] = 0 +st.a[1] = 1 +st.a[2] = 2 +st.a[3] = 3 +st.a[4] = 4 + +# this will run without preallocating the result +# since ``len`` is not available +var r = st.mapIt($(it+10)) +echo r == @["10", "11", "12", "13", "14"] diff --git a/tests/compiles/trecursive_generic_in_compiles.nim b/tests/compiles/trecursive_generic_in_compiles.nim new file mode 100644 index 000000000..77bf0bb02 --- /dev/null +++ b/tests/compiles/trecursive_generic_in_compiles.nim @@ -0,0 +1,98 @@ +# bug #3313 +import unittest, future + +type + ListNodeKind = enum + lnkNil, lnkCons + List*[T] = ref object + ## List ADT + case kind: ListNodeKind + of lnkNil: + discard + of lnkCons: + value: T + next: List[T] not nil + +proc Cons*[T](head: T, tail: List[T]): List[T] = + ## Constructs non empty list + List[T](kind: lnkCons, value: head, next: tail) + +proc Nil*[T](): List[T] = + ## Constructs empty list + List[T](kind: lnkNil) + +proc head*[T](xs: List[T]): T = + ## Returns list's head + xs.value + +# TODO +# proc headOption*[T](xs: List[T]): Option[T] = ??? + +proc tail*[T](xs: List[T]): List[T] = + ## Returns list's tail + case xs.kind + of lnkCons: xs.next + else: xs + +proc isEmpty*(xs: List): bool = + ## Checks if list is empty + xs.kind == lnkNil + +proc `==`*[T](xs, ys: List[T]): bool = + ## Compares two lists + if (xs.isEmpty, ys.isEmpty) == (true, true): true + elif (xs.isEmpty, ys.isEmpty) == (false, false): xs.head == ys.head and xs.tail == ys.tail + else: false + +proc asList*[T](xs: varargs[T]): List[T] = + ## Creates list from varargs + proc initListImpl(i: int, xs: openarray[T]): List[T] = + if i > high(xs): + Nil[T]() + else: + Cons(xs[i], initListImpl(i+1, xs)) + initListImpl(0, xs) + +proc foldRight*[T,U](xs: List[T], z: U, f: (T, U) -> U): U = + case xs.isEmpty + of true: z + else: f(xs.head, xs.tail.foldRight(z, f)) + +proc dup*[T](xs: List[T]): List[T] = + ## Duplicates the list + xs.foldRight(Nil[T](), (x: T, xs: List[T]) => Cons(x, xs)) + +type + ListFormat = enum + lfADT, lfSTD + +proc asString[T](xs: List[T], f = lfSTD): string = + proc asAdt(xs: List[T]): string = + case xs.isEmpty + of true: "Nil" + else: "Cons(" & $xs.head & ", " & xs.tail.asAdt & ")" + + proc asStd(xs: List[T]): string = + "List(" & xs.foldLeft("", (s: string, v: T) => + (if s == "": $v else: s & ", " & $v)) & ")" + + case f + of lfADT: xs.asAdt + else: xs.asStd + +proc `$`*[T](xs: List[T]): string = + ## Converts list to string + result = xs.asString + +proc foldLeft*[T,U](xs: List[T], z: U, f: (U, T) -> U): U = + case xs.isEmpty + of true: z + else: foldLeft(xs.tail, f(z, xs.head), f) + +suite "unittest compilation error": + + test "issue 3313": + let lst = lc[$x | (x <- 'a'..'z'), string].asList + + let lstCopy = lst.dup + check: lstCopy == lst diff --git a/tests/cpp/trawsockets.nim b/tests/cpp/tnativesockets.nim index bc129de57..6108380a8 100644 --- a/tests/cpp/trawsockets.nim +++ b/tests/cpp/tnativesockets.nim @@ -2,4 +2,4 @@ discard """ cmd: "nim cpp $file" """ -import rawsockets +import nativesockets diff --git a/tests/enum/tenummix.nim b/tests/enum/tenummix.nim index 4352cdd81..c7db4e056 100644 --- a/tests/enum/tenummix.nim +++ b/tests/enum/tenummix.nim @@ -1,6 +1,6 @@ discard """ - file: "tenummix.nim" - line: 11 + tfile: "tenummix.nim" + tline: 11 errormsg: "type mismatch" """ diff --git a/tests/gc/gcemscripten.nim b/tests/gc/gcemscripten.nim new file mode 100644 index 000000000..bbef13d98 --- /dev/null +++ b/tests/gc/gcemscripten.nim @@ -0,0 +1,59 @@ +discard """ + outputsub: "77\n77" +""" + +## Check how GC/Alloc works in Emscripten +import strutils + +type + X = ref XObj + XObj = object + name: string + value: int +when defined(allow_print): + const print = true +else: + const print = false + +proc myResult3*(i:int):X {.exportc.} = + if print: echo "3" + new(result) + if print: echo "3-2" + result.value = i + +proc myResult5*(i:int, x:X):X {.exportc.} = + if print: echo "5" + system.GC_fullCollect() + new(result) + if print: echo "5-2" + result.value = i + x.value = i+1 + if result.value == x.value: + echo "This should not happen. Just allocated variable points to parameter" + +proc myResult2*(val: string, i: int): X {.exportc.} = + if print: echo "2-1" + result = myResult3(i) + if print: echo "2-2" + system.GC_fullCollect() + if print: echo "2-3" + var t = new(X) + if print: echo "2-4" + result.name = val + if t.name == "qwe": + echo "This should not happen. Variable is GC collected and new one on same place are allocated." + if print: echo "2-5" + +proc myResult4*(val: string, i: int): X {.exportc.} = + if print: echo "4-1" + result = myResult5(i, X()) + if print: echo "4-2" + +var x = myResult2("qwe", 77) +echo intToStr(x.value) + +var x2 = myResult4("qwe", 77) +echo intToStr(x2.value) + + + diff --git a/tests/generics/tinferredgenericprocs.nim b/tests/generics/tinferredgenericprocs.nim index 5cbeabb94..359c71ba8 100644 --- a/tests/generics/tinferredgenericprocs.nim +++ b/tests/generics/tinferredgenericprocs.nim @@ -5,6 +5,7 @@ discard """ 3''' """ +import sequtils # https://github.com/Araq/Nim/issues/797 proc foo[T](s:T):string = $s diff --git a/tests/generics/tmap_auto.nim b/tests/generics/tmap_auto.nim new file mode 100644 index 000000000..572556722 --- /dev/null +++ b/tests/generics/tmap_auto.nim @@ -0,0 +1,13 @@ +import future, sequtils + +let x = map(@[1, 2, 3], x => x+10) +assert x == @[11, 12, 13] + +let y = map(@[(1,"a"), (2,"b"), (3,"c")], x => $x[0] & x[1]) +assert y == @["1a", "2b", "3c"] + +proc eatsTwoArgProc[T,S,U](a: T, b: S, f: proc(t: T, s: S): U): U = + f(a,b) + +let z = eatsTwoArgProc(1, "a", (t,s) => $t & s) +assert z == "1a" diff --git a/tests/macros/tgensym.nim b/tests/macros/tgensym.nim index b3aef0a2c..a4d1a3606 100644 --- a/tests/macros/tgensym.nim +++ b/tests/macros/tgensym.nim @@ -1,6 +1,6 @@ -import rawsockets, asyncdispatch, macros +import nativesockets, asyncdispatch, macros var p = newDispatcher() -var sock = newAsyncRawSocket() +var sock = newAsyncNativeSocket() proc convertReturns(node, retFutureSym: NimNode): NimNode {.compileTime.} = case node.kind diff --git a/tests/manyloc/keineschweine/lib/zlib_helpers.nim b/tests/manyloc/keineschweine/lib/zlib_helpers.nim index 5241a77c0..076475964 100644 --- a/tests/manyloc/keineschweine/lib/zlib_helpers.nim +++ b/tests/manyloc/keineschweine/lib/zlib_helpers.nim @@ -1,4 +1,4 @@ -import zlib +import zip/zlib proc compress*(source: string): string = var diff --git a/tests/manyloc/nake/nakefile.nim b/tests/manyloc/nake/nakefile.nim index 6dc453e8d..2fe07ec17 100644 --- a/tests/manyloc/nake/nakefile.nim +++ b/tests/manyloc/nake/nakefile.nim @@ -1,5 +1,5 @@ import nake -import httpclient, zipfiles, times, math +import httpclient, zip/zipfiles, times, math nakeImports randomize() diff --git a/tests/metatype/tprocbothmeta.nim b/tests/metatype/tprocbothmeta.nim index ad12c5d26..ba061dda2 100644 --- a/tests/metatype/tprocbothmeta.nim +++ b/tests/metatype/tprocbothmeta.nim @@ -1,5 +1,5 @@ -proc myFun[A,B](x: A): B = +proc myFun[A](x: A): auto = result = float(x+10) proc myMap[T,S](sIn: seq[T], f: proc (q: T): S): seq[S] = diff --git a/tests/metatype/tunresolved_return_type.nim b/tests/metatype/tunresolved_return_type.nim new file mode 100644 index 000000000..f67e065ea --- /dev/null +++ b/tests/metatype/tunresolved_return_type.nim @@ -0,0 +1,20 @@ +discard """ + errormsg: "cannot instantiate: 'T'" + line: 12 +""" + +# bug #2594 + + +type + ResultValue* = int64 + +proc toNumber[T: int|uint|int64|uint64](v: ResultValue): T = + if v < low(T) or v > high(T): + raise newException(RangeError, "protocol error") + return T(v) + +#proc toNumber[T](v: int32): T = +# return (v) + +echo toNumber(23) diff --git a/tests/method/tmapper.nim b/tests/method/tmapper.nim index 0008d9033..75b36e69a 100644 --- a/tests/method/tmapper.nim +++ b/tests/method/tmapper.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "invalid declaration order; cannot attach 'step' to method defined here: tmapper.nim(22,7)" + errormsg: "invalid declaration order; cannot attach 'step' to method defined here: tests/method/tmapper.nim(22,7)" line: 25 """ diff --git a/tests/misc/tnot.nim b/tests/misc/tnot.nim index 60d23c035..8c75c6bc0 100644 --- a/tests/misc/tnot.nim +++ b/tests/misc/tnot.nim @@ -1,6 +1,6 @@ discard """ - file: "tnot.nim" - line: 14 + tfile: "tnot.nim" + tline: 14 errormsg: "type mismatch" """ # BUG: following compiles, but should not: @@ -17,6 +17,3 @@ proc main = echo "No" main() - - - diff --git a/tests/modules/texport.nim b/tests/modules/texport.nim index 0890fb369..a8c217ab8 100644 --- a/tests/modules/texport.nim +++ b/tests/modules/texport.nim @@ -5,7 +5,7 @@ discard """ import mexporta # bug #1029: -from rawsockets import accept +from nativesockets import accept # B.TMyObject has been imported implicitly here: var x: TMyObject diff --git a/tests/newconfig/tfoo.nim b/tests/newconfig/tfoo.nim index 0ace7c88a..d593d4a75 100644 --- a/tests/newconfig/tfoo.nim +++ b/tests/newconfig/tfoo.nim @@ -4,4 +4,7 @@ discard """ msg: '''[NimScript] exec: gcc -v''' """ +when not defined(definedefine): + {.fatal: "wrong nim script configuration".} + echo "hello world!" diff --git a/tests/newconfig/tfoo.nims b/tests/newconfig/tfoo.nims index 90205cddb..519a868d5 100644 --- a/tests/newconfig/tfoo.nims +++ b/tests/newconfig/tfoo.nims @@ -3,6 +3,9 @@ mode = ScriptMode.Whatif exec "gcc -v" +# test that ospaths actually compiles: +import ospaths + --forceBuild task listDirs, "lists every subdirectory": @@ -10,5 +13,6 @@ task listDirs, "lists every subdirectory": echo "DIR ", x task default, "default target": + --define: definedefine setCommand "c" diff --git a/tests/objects/tillegal_recursion.nim b/tests/objects/tillegal_recursion.nim index 171a04f87..222139101 100644 --- a/tests/objects/tillegal_recursion.nim +++ b/tests/objects/tillegal_recursion.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "illegal recursion in type 'object'" + errormsg: "inheritance only works with non-final objects" line: 7 """ # bug #1691 diff --git a/tests/overload/toverprc.nim b/tests/overload/toverprc.nim index 78831f744..112eae096 100644 --- a/tests/overload/toverprc.nim +++ b/tests/overload/toverprc.nim @@ -5,7 +5,7 @@ yay''' # Test overloading of procs when used as function pointers -import strutils +import strutils, sequtils proc parseInt(x: float): int {.noSideEffect.} = discard proc parseInt(x: bool): int {.noSideEffect.} = discard diff --git a/tests/parallel/tparfind.nim b/tests/parallel/tparfind.nim new file mode 100644 index 000000000..9de5012f5 --- /dev/null +++ b/tests/parallel/tparfind.nim @@ -0,0 +1,28 @@ +discard """ + output: "500" +""" + +import threadpool, sequtils + +{.experimental.} + +proc linearFind(a: openArray[int]; x, offset: int): int = + for i, y in a: + if y == x: return i+offset + result = -1 + +proc parFind(a: seq[int]; x: int): int = + var results: array[4, int] + parallel: + if a.len >= 4: + let chunk = a.len div 4 + results[0] = spawn linearFind(a[0 ..< chunk], x, 0) + results[1] = spawn linearFind(a[chunk ..< chunk*2], x, chunk) + results[2] = spawn linearFind(a[chunk*2 ..< chunk*3], x, chunk*2) + results[3] = spawn linearFind(a[chunk*3 ..< a.len], x, chunk*3) + result = max(results) + + +let data = toSeq(0..1000) +echo parFind(data, 500) + diff --git a/tests/parser/tcommand_as_expr.nim b/tests/parser/tcommand_as_expr.nim index 730e9cbb7..a244c8767 100644 --- a/tests/parser/tcommand_as_expr.nim +++ b/tests/parser/tcommand_as_expr.nim @@ -5,6 +5,7 @@ discard """ 77''' """ #import math +import sequtils proc optarg(x:int, y:int = 0):int = x + 3 * y proc singlearg(x:int):int = 20*x diff --git a/tests/pragmas/tbitsize.nim b/tests/pragmas/tbitsize.nim new file mode 100644 index 000000000..7a44944d2 --- /dev/null +++ b/tests/pragmas/tbitsize.nim @@ -0,0 +1,22 @@ +discard """ +ccodeCheck: "\\i @'unsigned int flag:1;' .*" +""" + +type + bits* = object + flag* {.bitsize: 1.}: cuint + opts* {.bitsize: 4.}: cint + +var + b: bits + +assert b.flag == 0 +b.flag = 1 +assert b.flag == 1 +b.flag = 2 +assert b.flag == 0 + +b.opts = 7 +assert b.opts == 7 +b.opts = 9 +assert b.opts == -7 diff --git a/tests/rational/trat_float.nim b/tests/rational/trat_float.nim new file mode 100644 index 000000000..24797c4a0 --- /dev/null +++ b/tests/rational/trat_float.nim @@ -0,0 +1,9 @@ +discard """ + file: "trat_float.nim" + line: "9,19" + errormsg: '''type mismatch: got''' +""" +import rationals +var + # this fails - no floats as num or den + r = initRational(1.0'f, 1.0'f) diff --git a/tests/rational/trat_init.nim b/tests/rational/trat_init.nim new file mode 100644 index 000000000..df29ff6e3 --- /dev/null +++ b/tests/rational/trat_init.nim @@ -0,0 +1,10 @@ +discard """ + file: "trat_init.nim" + exitcode: "1" +""" +import rationals +var + z = Rational[int](num: 0, den: 1) + o = initRational(num=1, den=1) + a = initRational(1, 2) + r = initRational(1, 0) # this fails - no zero denominator diff --git a/tests/stdlib/tmemfiles1.nim b/tests/stdlib/tmemfiles1.nim new file mode 100644 index 000000000..8b66dfcc1 --- /dev/null +++ b/tests/stdlib/tmemfiles1.nim @@ -0,0 +1,12 @@ +discard """ + file: "tmemfiles1.nim" +""" +import memfiles, os +var + mm: MemFile + fn = "test.mmap" +# Create a new file +mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 20) +mm.close() +mm.close() +if fileExists(fn): removeFile(fn) diff --git a/tests/stdlib/tmemfiles2.nim b/tests/stdlib/tmemfiles2.nim new file mode 100644 index 000000000..026443e93 --- /dev/null +++ b/tests/stdlib/tmemfiles2.nim @@ -0,0 +1,39 @@ +discard """ + file: "tmemfiles2.nim" + disabled: true + output: '''Full read size: 20 +Half read size: 10 Data: Hello''' +""" +# doesn't work on windows. fmReadWrite doesn't create a file. +import memfiles, os +var + mm, mm_full, mm_half: MemFile + fn = "test.mmap" + p: pointer + +if fileExists(fn): removeFile(fn) + +# Create a new file, data all zeros +mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 20) +mm.close() + +# read, change +mm_full = memfiles.open(fn, mode = fmWrite, mappedSize = -1) +echo "Full read size: ",mm_full.size +p = mm_full.mapMem(fmReadWrite, 20, 0) +var p2 = cast[cstring](p) +p2[0] = 'H' +p2[1] = 'e' +p2[2] = 'l' +p2[3] = 'l' +p2[4] = 'o' +p2[5] = '\0' +mm_full.unmapMem(p, 20) +mm_full.close() + +# read half, and verify data change +mm_half = memfiles.open(fn, mode = fmRead, mappedSize = 10) +echo "Half read size: ",mm_half.size, " Data: ", cast[cstring](mm_half.mem) +mm_half.close() + +if fileExists(fn): removeFile(fn) diff --git a/tests/stdlib/tstreams2.nim b/tests/stdlib/tstreams2.nim new file mode 100644 index 000000000..90102d8e3 --- /dev/null +++ b/tests/stdlib/tstreams2.nim @@ -0,0 +1,13 @@ +discard """ + file: "tstreams2.nim" + output: '''fs is: nil''' +""" +import streams +var + fs = newFileStream("amissingfile.txt") + line = "" +echo "fs is: ",repr(fs) +if not isNil(fs): + while fs.readLine(line): + echo line + fs.close() diff --git a/tests/stdlib/tunittest.nim b/tests/stdlib/tunittest.nim index 4d2a2a340..4b210c23b 100644 --- a/tests/stdlib/tunittest.nim +++ b/tests/stdlib/tunittest.nim @@ -1,4 +1,4 @@ -import unittest +import unittest, sequtils proc doThings(spuds: var int): int = diff --git a/tests/system/tfloatToString.nim b/tests/system/tfloatToString.nim deleted file mode 100644 index bb45a91d7..000000000 --- a/tests/system/tfloatToString.nim +++ /dev/null @@ -1,22 +0,0 @@ -discard """ - output:'''2.3242 -2.982 -123912.1 -123912.1823 -5.0 -1e+100 -inf --inf -nan -''' -""" - -echo($(2.3242)) -echo($(2.982)) -echo($(123912.1)) -echo($(123912.1823)) -echo($(5.0)) -echo($(1e100)) -echo($(1e1000000)) -echo($(-1e1000000)) -echo($(0.0/0.0)) diff --git a/tests/system/toString.nim b/tests/system/toString.nim index 52e7a4b92..a2337f5dd 100644 --- a/tests/system/toString.nim +++ b/tests/system/toString.nim @@ -1,9 +1,42 @@ discard """ output:'''@[23, 45] -@[, foo, bar]''' +@[, foo, bar] +{a, b, c} +2.3242 +2.982 +123912.1 +123912.1823 +5.0 +1e+100 +inf +-inf +nan +nil +nil''' """ echo($(@[23, 45])) echo($(@["", "foo", "bar"])) #echo($(["", "foo", "bar"])) #echo($([23, 45])) + +# bug #2395 + +let alphaSet: set[char] = {'a'..'c'} +echo alphaSet + +echo($(2.3242)) +echo($(2.982)) +echo($(123912.1)) +echo($(123912.1823)) +echo($(5.0)) +echo($(1e100)) +echo($(1e1000000)) +echo($(-1e1000000)) +echo($(0.0/0.0)) + +# nil tests +var x: seq[string] +var y: string +echo(x) +echo(y) diff --git a/tests/system/tsettostring.nim b/tests/system/tsettostring.nim deleted file mode 100644 index c6846ee99..000000000 --- a/tests/system/tsettostring.nim +++ /dev/null @@ -1,8 +0,0 @@ -discard """ - output: "{a, b, c}" -""" - -# bug #2395 - -let alphaSet: set[char] = {'a'..'c'} -echo alphaSet diff --git a/tests/template/sunset.tmpl b/tests/template/sunset.tmpl index 6475bac4e..465b12a5e 100644 --- a/tests/template/sunset.tmpl +++ b/tests/template/sunset.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl +#? stdtmpl #proc sunsetTemplate*(current, ticker, content: string, # tabs: openarray[array[0..1, string]]): string = # result = "" diff --git a/tests/template/twrongmapit.nim b/tests/template/twrongmapit.nim index 0a6d694f6..df695fcd6 100644 --- a/tests/template/twrongmapit.nim +++ b/tests/template/twrongmapit.nim @@ -27,6 +27,6 @@ when ATTEMPT == 0: # bug #1543 import sequtils -(var i = @[""];i).mapIt(it) +(var i = @[""];i).applyIt(it) # now works: echo "##", i[0], "##" diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 4de1edeee..3166942ec 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -89,8 +89,11 @@ proc runBasicDLLTest(c, r: var TResults, cat: Category, options: string) = var libpath = getEnv"LD_LIBRARY_PATH".string # Temporarily add the lib directory to LD_LIBRARY_PATH: putEnv("LD_LIBRARY_PATH", "lib:" & libpath) + defer: putEnv("LD_LIBRARY_PATH", libpath) var serverDll = DynlibFormat % "server" safeCopyFile("tests/dll" / serverDll, "lib" / serverDll) + var nimrtlDll = DynlibFormat % "nimrtl" + safeCopyFile("tests/dll" / nimrtlDll, "lib" / nimrtlDll) testSpec r, makeTest("tests/dll/client.nim", options & " -d:useNimRtl", cat, actionRun) @@ -114,13 +117,23 @@ proc gcTests(r: var TResults, cat: Category, options: string) = testSpec r, makeTest("tests/gc" / filename, options & " -d:release -d:useRealtimeGC", cat, actionRun) - template test(filename: expr): stmt = + template testWithoutBoehm(filename: expr): stmt = testWithoutMs filename testSpec r, makeTest("tests/gc" / filename, options & " --gc:markAndSweep", cat, actionRun) testSpec r, makeTest("tests/gc" / filename, options & " -d:release --gc:markAndSweep", cat, actionRun) - + template test(filename: expr): stmt = + testWithoutBoehm filename + when not defined(windows): + # AR: cannot find any boehm.dll on the net, right now, so disabled + # for windows: + testSpec r, makeTest("tests/gc" / filename, options & + " --gc:boehm", cat, actionRun) + testSpec r, makeTest("tests/gc" / filename, options & + " -d:release --gc:boehm", cat, actionRun) + + test "gcemscripten" test "growobjcrash" test "gcbench" test "gcleak" @@ -130,9 +143,9 @@ proc gcTests(r: var TResults, cat: Category, options: string) = test "gcleak4" # Disabled because it works and takes too long to run: #test "gcleak5" - test "weakrefs" + testWithoutBoehm "weakrefs" test "cycleleak" - test "closureleak" + testWithoutBoehm "closureleak" testWithoutMs "refarrayleak" test "stackrefleak" @@ -339,7 +352,7 @@ proc `&?.`(a, b: string): string = # candidate for the stdlib? result = if a.endswith(b): a else: a & b -proc processCategory(r: var TResults, cat: Category, options: string) = +proc processCategory(r: var TResults, cat: Category, options: string, fileGlob: string = "t*.nim") = case cat.string.normalize of "rodfiles": discard # Disabled for now @@ -376,5 +389,5 @@ proc processCategory(r: var TResults, cat: Category, options: string) = of "nimble-all": testNimblePackages(r, cat, pfAll) else: - for name in os.walkFiles("tests" & DirSep &.? cat.string / "t*.nim"): + for name in os.walkFiles("tests" & DirSep &.? cat.string / fileGlob): testSpec r, makeTest(name, options, cat) diff --git a/tests/testament/specs.nim b/tests/testament/specs.nim index 99640f22c..bab17d2cd 100644 --- a/tests/testament/specs.nim +++ b/tests/testament/specs.nim @@ -44,6 +44,8 @@ type file*, cmd*: string outp*: string line*, column*: int + tfile*: string + tline*, tcolumn*: int exitCode*: int msg*: string ccodeCheck*: string @@ -101,6 +103,9 @@ proc specDefaults*(result: var TSpec) = result.cmd = cmdTemplate result.line = 0 result.column = 0 + result.tfile = "" + result.tline = 0 + result.tcolumn = 0 proc parseSpec*(filename: string): TSpec = specDefaults(result) @@ -116,6 +121,9 @@ proc parseSpec*(filename: string): TSpec = of "file": result.file = e.value of "line": discard parseInt(e.value, result.line) of "column": discard parseInt(e.value, result.column) + of "tfile": result.tfile = e.value + of "tline": discard parseInt(e.value, result.tline) + of "tcolumn": discard parseInt(e.value, result.tcolumn) of "output": result.action = actionRun result.outp = e.value diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index b138c9909..636093a7f 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -23,6 +23,7 @@ const Command: all run all tests c|category <category> run all the tests of a certain category + r|run <test> run single test file html [commit] generate $1 from the database; uses the latest commit or a specific one (use -1 for the commit before latest etc) @@ -52,6 +53,8 @@ type let pegLineError = peg"{[^(]*} '(' {\d+} ', ' {\d+} ') ' ('Error') ':' \s* {.*}" + pegLineTemplate = + peg"{[^(]*} '(' {\d+} ', ' {\d+} ') ' 'template/generic instantiation from here'.*" pegOtherError = peg"'Error:' \s* {.*}" pegSuccess = peg"'Hint: operation successful'.*" pegOfInterest = pegLineError / pegOtherError @@ -65,6 +68,7 @@ proc callCompiler(cmdTemplate, filename, options: string, let outp = p.outputStream var suc = "" var err = "" + var tmpl = "" var x = newStringOfCap(120) result.nimout = "" while outp.readLine(x.TaintedString) or running(p): @@ -72,6 +76,9 @@ proc callCompiler(cmdTemplate, filename, options: string, if x =~ pegOfInterest: # `err` should contain the last error/warning message err = x + elif x =~ pegLineTemplate and err == "": + # `tmpl` contains the last template expansion before the error + tmpl = x elif x =~ pegSuccess: suc = x close(p) @@ -80,6 +87,13 @@ proc callCompiler(cmdTemplate, filename, options: string, result.outp = "" result.line = 0 result.column = 0 + result.tfile = "" + result.tline = 0 + result.tcolumn = 0 + if tmpl =~ pegLineTemplate: + result.tfile = extractFilename(matches[0]) + result.tline = parseInt(matches[1]) + result.tcolumn = parseInt(matches[2]) if err =~ pegLineError: result.file = extractFilename(matches[0]) result.line = parseInt(matches[1]) @@ -153,7 +167,7 @@ proc addResult(r: var TResults, test: TTest, proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest) = if strip(expected.msg) notin strip(given.msg): r.addResult(test, expected.msg, given.msg, reMsgsDiffer) - elif extractFilename(expected.file) != extractFilename(given.file) and + elif expected.tfile == "" and extractFilename(expected.file) != extractFilename(given.file) and "internal error:" notin expected.msg: r.addResult(test, expected.file, given.file, reFilesDiffer) elif expected.line != given.line and expected.line != 0 or @@ -161,6 +175,14 @@ proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest) = r.addResult(test, $expected.line & ':' & $expected.column, $given.line & ':' & $given.column, reLinesDiffer) + elif expected.tfile != "" and extractFilename(expected.tfile) != extractFilename(given.tfile) and + "internal error:" notin expected.msg: + r.addResult(test, expected.tfile, given.tfile, reFilesDiffer) + elif expected.tline != given.tline and expected.tline != 0 or + expected.tcolumn != given.tcolumn and expected.tcolumn != 0: + r.addResult(test, $expected.tline & ':' & $expected.tcolumn, + $given.tline & ':' & $given.tcolumn, + reLinesDiffer) else: r.addResult(test, expected.msg, given.msg, reSuccess) inc(r.passed) @@ -212,6 +234,8 @@ proc compilerOutputTests(test: TTest, given: var TSpec, expected: TSpec; expectedmsg = expected.nimout givenmsg = given.nimout.strip nimoutCheck(test, expectedmsg, given) + else: + givenmsg = given.nimout.strip if given.err == reSuccess: inc(r.passed) r.addResult(test, expectedmsg, givenmsg, given.err) @@ -279,7 +303,7 @@ proc testSpec(r: var TResults, test: TTest) = return let exeCmd = (if isJsTarget: nodejs & " " else: "") & exeFile - let (buf, exitCode) = execCmdEx(exeCmd) + var (buf, exitCode) = execCmdEx(exeCmd, options = {poStdErrToStdOut}) let bufB = if expected.sortoutput: makeDeterministic(strip(buf.string)) else: strip(buf.string) let expectedOut = strip(expected.outp) @@ -376,6 +400,11 @@ proc main() = var cat = Category(p.key) p.next processCategory(r, cat, p.cmdLineRest.string) + of "r", "run": + let (dir, file) = splitPath(p.key.string) + let (_, subdir) = splitPath(dir) + var cat = Category(subdir) + processCategory(r, cat, p.cmdLineRest.string, file) of "html": var commit = 0 discard parseInt(p.cmdLineRest.string, commit) diff --git a/tests/typerel/t2plus.nim b/tests/typerel/t2plus.nim new file mode 100644 index 000000000..08378b804 --- /dev/null +++ b/tests/typerel/t2plus.nim @@ -0,0 +1,22 @@ +discard """ + output: "2.0" +""" + +{.warning[TypelessParam]: off.} + +import future + +# bug #3329 + +proc foldRight[T,U](lst: seq[T], v: U, f: (T, U) -> U): U = + result = v + for x in lst: + result = f(x, result) + +proc mean[T: SomeNumber](xs: seq[T]): T = + xs.foldRight(0.T, (xBAZ: auto, yBAZ: auto) => xBAZ + yBAZ) / T(xs.len) + +when isMainModule: + let x = mean(@[1.float, 2, 3]) + echo x + diff --git a/tests/vm/tsimpleglobals.nim b/tests/vm/tsimpleglobals.nim new file mode 100644 index 000000000..27bfdce50 --- /dev/null +++ b/tests/vm/tsimpleglobals.nim @@ -0,0 +1,16 @@ +discard """ + msg: "abc xyz bb" +""" + +# bug #2473 +type + Test = tuple[a,b: string] + +static: + var s:seq[Test] = @[(a:"a", b:"b")] + s[0] = (a:"aa", b:"bb") + + var x: Test + x.a = "abc" + x.b = "xyz" + echo x.a, " ", x.b, " ", s[0].b diff --git a/tests/vm/twrongconst.nim b/tests/vm/twrongconst.nim index 68ab2757c..424ed080e 100644 --- a/tests/vm/twrongconst.nim +++ b/tests/vm/twrongconst.nim @@ -1,6 +1,6 @@ discard """ errormsg: "cannot evaluate at compile time: x" - line: 9 + line: 7 """ var x: array[100, char] diff --git a/tests/vm/tyaytypedesc.nim b/tests/vm/tyaytypedesc.nim new file mode 100644 index 000000000..a3ad9b707 --- /dev/null +++ b/tests/vm/tyaytypedesc.nim @@ -0,0 +1,21 @@ +discard """ + output: "ntWhitespace" +""" + +# bug #3357 + +type NodeType* = enum + ntWhitespace + +type TokenType* = enum + ttWhitespace + +proc enumTable*[A, B, C](a: openarray[tuple[key: A, val: B]], ret: typedesc[C]): C = + for item in a: + result[item.key] = item.val + +const tokenTypeToNodeType = { + ttWhitespace: ntWhitespace, +}.enumTable(array[ttWhitespace..ttWhitespace, NodeType]) + +echo tokenTypeToNodeType[ttWhitespace] |