diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/async/tfuturestream.nim | 53 | ||||
-rw-r--r-- | tests/ccgbugs/twrong_method.nim | 27 | ||||
-rw-r--r-- | tests/collections/thashes.nim | 15 | ||||
-rw-r--r-- | tests/errmsgs/tshow_asgn.nim | 15 | ||||
-rw-r--r-- | tests/method/tautonotgeneric.nim (renamed from tests/metatype/tautonotgeneric.nim) | 13 | ||||
-rw-r--r-- | tests/method/tgeneric_methods2.nim | 15 | ||||
-rw-r--r-- | tests/misc/parsecomb.nim | 10 | ||||
-rw-r--r-- | tests/osproc/ta.nim | 3 | ||||
-rw-r--r-- | tests/osproc/ta_in.nim | 5 | ||||
-rw-r--r-- | tests/osproc/ta_out.nim | 16 | ||||
-rw-r--r-- | tests/osproc/tstdin.nim | 2 | ||||
-rw-r--r-- | tests/osproc/tstdout.nim | 29 | ||||
-rw-r--r-- | tests/pragmas/tused.nim | 32 | ||||
-rw-r--r-- | tests/stdlib/thttpclient.nim | 10 | ||||
-rw-r--r-- | tests/stdlib/tunittest.nim | 15 | ||||
-rw-r--r-- | tests/template/mgensym_generic_cross_module.nim | 14 | ||||
-rw-r--r-- | tests/template/tgensym_generic_cross_module.nim | 14 | ||||
-rw-r--r-- | tests/template/tgensym_label.nim | 18 | ||||
-rw-r--r-- | tests/threads/tonthreadcreation.nim | 11 |
19 files changed, 288 insertions, 29 deletions
diff --git a/tests/async/tfuturestream.nim b/tests/async/tfuturestream.nim new file mode 100644 index 000000000..9a8e986a0 --- /dev/null +++ b/tests/async/tfuturestream.nim @@ -0,0 +1,53 @@ +discard """ + file: "tfuturestream.nim" + exitcode: 0 + output: ''' +0 +1 +2 +3 +4 +5 +Done +Finished +''' +""" +import asyncdispatch + +var fs = newFutureStream[int]() + +proc alpha() {.async.} = + for i in 0 .. 5: + await sleepAsync(1000) + await fs.write(i) + + echo("Done") + fs.complete() + +proc beta() {.async.} = + while not fs.finished: + let (hasValue, value) = await fs.read() + if hasValue: + echo(value) + + echo("Finished") + +asyncCheck alpha() +waitFor beta() + +# TODO: Something like this should work eventually. +# proc delta(): FutureStream[string] {.async.} = +# for i in 0 .. 5: +# await sleepAsync(1000) +# result.put($i) + +# return "" + +# proc omega() {.async.} = +# let fut = delta() +# while not fut.finished(): +# echo(await fs.takeAsync()) + +# echo("Finished") + +# waitFor omega() \ No newline at end of file diff --git a/tests/ccgbugs/twrong_method.nim b/tests/ccgbugs/twrong_method.nim new file mode 100644 index 000000000..9879c6114 --- /dev/null +++ b/tests/ccgbugs/twrong_method.nim @@ -0,0 +1,27 @@ +discard """ + cmd: "nim c -d:release $file" + output: '''correct method''' +""" +# bug #5439 +type + Control* = ref object of RootObj + + ControlImpl* = ref object of Control + + Container* = ref object of ControlImpl + + ContainerImpl* = ref object of Container + +method testProc*(control: Control) {.base.} = echo "wrong method" + +method testProc*(container: Container) = echo "correct method" + +proc main() + +main() # wrong method called + +proc main() = + var container = new ContainerImpl + container.testProc() + +# main() # correct method called diff --git a/tests/collections/thashes.nim b/tests/collections/thashes.nim index b9c639414..76b99313c 100644 --- a/tests/collections/thashes.nim +++ b/tests/collections/thashes.nim @@ -72,4 +72,19 @@ block: var t = initTable[int, int]() t[0] = 0 +# Check hashability of all integer types (issue #5429) +block: + let intTables = ( + newTable[int, string](), + newTable[int8, string](), + newTable[int16, string](), + newTable[int32, string](), + newTable[int64, string](), + newTable[uint, string](), + newTable[uint8, string](), + newTable[uint16, string](), + newTable[uint32, string](), + newTable[uint64, string](), + ) + echo "true" diff --git a/tests/errmsgs/tshow_asgn.nim b/tests/errmsgs/tshow_asgn.nim new file mode 100644 index 000000000..250f786e2 --- /dev/null +++ b/tests/errmsgs/tshow_asgn.nim @@ -0,0 +1,15 @@ +discard """ + errormsg: "type mismatch: got (int) but expected 'cshort = int16'" + line: 12 + column: 10 + file: "tshow_asgn.nim" +""" + +# bug #5430 + +proc random*[T](x: Slice[T]): T = + ## For a slice `a .. b` returns a value in the range `a .. b-1`. + result = int(x.b - x.a) + x.a + +let slice = 10.cshort..15.cshort +discard slice.random diff --git a/tests/metatype/tautonotgeneric.nim b/tests/method/tautonotgeneric.nim index a55ae488e..f0d6932f9 100644 --- a/tests/metatype/tautonotgeneric.nim +++ b/tests/method/tautonotgeneric.nim @@ -1,15 +1,24 @@ discard """ - output: "wof!" + output: '''wof! +wof!''' """ # bug #1659 type Animal = ref object {.inheritable.} type Dog = ref object of Animal -method say(a: Animal): auto = "wat!" +method say(a: Animal): auto {.base.} = "wat!" method say(a: Dog): auto = "wof!" proc saySomething(a: Animal): auto = a.say() + +method ec(a: Animal): auto {.base.} = echo "wat!" +method ec(a: Dog): auto = echo "wof!" + +proc ech(a: Animal): auto = a.ec() + + var a = Dog() echo saySomething(a) +ech a diff --git a/tests/method/tgeneric_methods2.nim b/tests/method/tgeneric_methods2.nim new file mode 100644 index 000000000..6e761dc48 --- /dev/null +++ b/tests/method/tgeneric_methods2.nim @@ -0,0 +1,15 @@ +#5432 +type + Iterator[T] = ref object of RootObj + +# base methods with `T` in the return type are okay +method methodThatWorks*[T](i: Iterator[T]): T {.base.} = + discard + +# base methods without `T` (void or basic types) fail +method methodThatFails*[T](i: Iterator[T]) {.base.} = + discard + +type + SpecificIterator1 = ref object of Iterator[string] + SpecificIterator2 = ref object of Iterator[int] diff --git a/tests/misc/parsecomb.nim b/tests/misc/parsecomb.nim index 05fe97ad1..4ff2f65d2 100644 --- a/tests/misc/parsecomb.nim +++ b/tests/misc/parsecomb.nim @@ -29,10 +29,10 @@ method runInput[T, O](self: Parser[T, O], inp: Input[T]): Result[T, O] = # XXX: above needed for now, as without the `tmp` bit below, it compiles to invalid C. tmp(self)(inp) -method run*[T, O](self: Parser[T, O], toks: seq[T]): Result[T, O] = +proc run*[T, O](self: Parser[T, O], toks: seq[T]): Result[T, O] = self.runInput(Input[T](toks: toks, index: 0)) -method chain*[T, O1, O2](self: Parser[T, O1], nextp: proc (v: O1): Parser[T, O2]): Parser[T, O2] = +proc chain*[T, O1, O2](self: Parser[T, O1], nextp: proc (v: O1): Parser[T, O2]): Parser[T, O2] = result = proc (inp: Input[T]): Result[T, O2] = let r = self.runInput(inp) case r.kind: @@ -41,7 +41,7 @@ method chain*[T, O1, O2](self: Parser[T, O1], nextp: proc (v: O1): Parser[T, O2] of rkFailure: Result[T, O2](kind: rkFailure) -method skip[T](self: Input[T], n: int): Input[T] = +method skip[T](self: Input[T], n: int): Input[T] {.base.} = Input[T](toks: self.toks, index: self.index + n) proc pskip*[T](n: int): Parser[T, tuple[]] = @@ -69,11 +69,11 @@ proc `+`*[T, O](first: Parser[T, O], second: Parser[T, O]): Parser[T, O] = # end of primitives (definitions involving Parser(..)) -method map*[T, O1, O2](self: Parser[T, O1], p: proc (v: O1): O2): Parser[T, O2] = +proc map*[T, O1, O2](self: Parser[T, O1], p: proc (v: O1): O2): Parser[T, O2] = self.chain(proc (v: O1): Parser[T, O2] = unit[T, O2](p(v))) -method then*[T, O1, O2](self: Parser[T, O1], next: Parser[T, O2]): Parser[T, O2] = +proc then*[T, O1, O2](self: Parser[T, O1], next: Parser[T, O2]): Parser[T, O2] = self.chain(proc (v: O1): Parser[T, O2] = next) diff --git a/tests/osproc/ta.nim b/tests/osproc/ta.nim deleted file mode 100644 index 5ebcc7f14..000000000 --- a/tests/osproc/ta.nim +++ /dev/null @@ -1,3 +0,0 @@ -import strutils -let x = stdin.readLine() -echo x.parseInt + 5 diff --git a/tests/osproc/ta_in.nim b/tests/osproc/ta_in.nim new file mode 100644 index 000000000..b46890f6e --- /dev/null +++ b/tests/osproc/ta_in.nim @@ -0,0 +1,5 @@ +# This file is prefixed with an "a", because other tests +# depend on it and it must be compiled first. +import strutils +let x = stdin.readLine() +echo x.parseInt + 5 diff --git a/tests/osproc/ta_out.nim b/tests/osproc/ta_out.nim new file mode 100644 index 000000000..f7091a7f6 --- /dev/null +++ b/tests/osproc/ta_out.nim @@ -0,0 +1,16 @@ +# This file is prefixed with an "a", because other tests +# depend on it and it must be compiled first. +stdout.writeLine("to stdout") +stdout.flushFile() +stdout.writeLine("to stdout") +stdout.flushFile() + +stderr.writeLine("to stderr") +stderr.flushFile() +stderr.writeLine("to stderr") +stderr.flushFile() + +stdout.writeLine("to stdout") +stdout.flushFile() +stdout.writeLine("to stdout") +stdout.flushFile() diff --git a/tests/osproc/tstdin.nim b/tests/osproc/tstdin.nim index b491c2500..d94c34192 100644 --- a/tests/osproc/tstdin.nim +++ b/tests/osproc/tstdin.nim @@ -4,7 +4,7 @@ discard """ """ import osproc, os, streams -const filename = when defined(Windows): "ta.exe" else: "ta" +const filename = when defined(Windows): "ta_in.exe" else: "ta_in" doAssert fileExists(getCurrentDir() / "tests" / "osproc" / filename) diff --git a/tests/osproc/tstdout.nim b/tests/osproc/tstdout.nim new file mode 100644 index 000000000..0cb5bd9c0 --- /dev/null +++ b/tests/osproc/tstdout.nim @@ -0,0 +1,29 @@ +discard """ + output: '''-------------------------------------- +to stdout +to stdout +to stderr +to stderr +to stdout +to stdout +-------------------------------------- +''' +""" +import osproc, os, streams + +const filename = when defined(Windows): "ta_out.exe" else: "ta_out" + +doAssert fileExists(getCurrentDir() / "tests" / "osproc" / filename) + +var p = startProcess(filename, getCurrentDir() / "tests" / "osproc", + options={poStdErrToStdOut}) + +let outputStream = p.outputStream +var x = newStringOfCap(120) +var output = "" +while outputStream.readLine(x.TaintedString): + output.add(x & "\n") + +echo "--------------------------------------" +stdout.write output +echo "--------------------------------------" diff --git a/tests/pragmas/tused.nim b/tests/pragmas/tused.nim index f3126bd45..4a317f874 100644 --- a/tests/pragmas/tused.nim +++ b/tests/pragmas/tused.nim @@ -1,13 +1,35 @@ discard """ - output: '''8''' + nimout: ''' +compile start +tused.nim(15, 8) Hint: 'tused.echoSub(a: int, b: int)' is declared but not used [XDeclaredButNotUsed] +compile end''' + output: "8\n8" """ -template implementArithOps(T) = +static: + echo "compile start" + +template implementArithOpsOld(T) = + proc echoAdd(a, b: T) = + echo a + b + proc echoSub(a, b: T) = + echo a - b + +template implementArithOpsNew(T) = proc echoAdd(a, b: T) {.used.} = echo a + b proc echoSub(a, b: T) {.used.} = echo a - b -# no warning produced for the unused 'echoSub' -implementArithOps(int) -echoAdd 3, 5 +block: + # should produce warning for the unused 'echoSub' + implementArithOpsOld(int) + echoAdd 3, 5 + +block: + # no warning produced for the unused 'echoSub' + implementArithOpsNew(int) + echoAdd 3, 5 + +static: + echo "compile end" diff --git a/tests/stdlib/thttpclient.nim b/tests/stdlib/thttpclient.nim index 7b1111f9b..62c1ebee7 100644 --- a/tests/stdlib/thttpclient.nim +++ b/tests/stdlib/thttpclient.nim @@ -13,7 +13,9 @@ proc asyncTest() {.async.} = var client = newAsyncHttpClient() var resp = await client.request("http://example.com/") doAssert(resp.code.is2xx) - doAssert("<title>Example Domain</title>" in resp.body) + var body = await resp.body + body = await resp.body # Test caching + doAssert("<title>Example Domain</title>" in body) resp = await client.request("http://example.com/404") doAssert(resp.code.is4xx) @@ -47,7 +49,8 @@ proc asyncTest() {.async.} = echo("Downloaded ", progress, " of ", total) echo("Current rate: ", speed div 1000, "kb/s") client.onProgressChanged = onProgressChanged - discard await client.getContent("http://speedtest-ams2.digitalocean.com/100mb.test") + await client.downloadFile("http://speedtest-ams2.digitalocean.com/100mb.test", + "100mb.test") client.close() @@ -94,7 +97,8 @@ proc syncTest() = echo("Downloaded ", progress, " of ", total) echo("Current rate: ", speed div 1000, "kb/s") client.onProgressChanged = onProgressChanged - discard client.getContent("http://speedtest-ams2.digitalocean.com/100mb.test") + client.downloadFile("http://speedtest-ams2.digitalocean.com/100mb.test", + "100mb.test") client.close() diff --git a/tests/stdlib/tunittest.nim b/tests/stdlib/tunittest.nim index e87cd3508..3f8601323 100644 --- a/tests/stdlib/tunittest.nim +++ b/tests/stdlib/tunittest.nim @@ -1,5 +1,11 @@ +discard """ + nimout: "compile start\ncompile end" +""" + import unittest, sequtils +static: + echo "compile start" proc doThings(spuds: var int): int = spuds = 24 @@ -10,9 +16,9 @@ test "#964": check spuds == 24 -from strutils import toUpper +from strutils import toUpperAscii test "#1384": - check(@["hello", "world"].map(toUpper) == @["HELLO", "WORLD"]) + check(@["hello", "world"].map(toUpperAscii) == @["HELLO", "WORLD"]) import options @@ -57,7 +63,7 @@ suite "suite with only teardown": suite "suite with only setup": setup: - var testVar = "from setup" + var testVar {.used.} = "from setup" test "unittest with only setup 1": check testVar == "from setup" @@ -89,3 +95,6 @@ suite "bug #4494": var tags = @[1, 2, 3, 4, 5] check: allIt(0..3, tags[it] != tags[it + 1]) + +static: + echo "compile end" diff --git a/tests/template/mgensym_generic_cross_module.nim b/tests/template/mgensym_generic_cross_module.nim new file mode 100644 index 000000000..80b681db4 --- /dev/null +++ b/tests/template/mgensym_generic_cross_module.nim @@ -0,0 +1,14 @@ + +template makeDomElement(x: untyped, name: string = nil) = + const tag {.gensym.} = if name == nil: astToStr(x) else: name + + proc x*(p: int|float) = + echo tag, p + + proc x*(p: string|cstring) = + echo tag, p + +#proc wrappedUp[T](x: T) = +# mixin foo, bar +makeDomElement(foo, "foo") +makeDomElement(bar) diff --git a/tests/template/tgensym_generic_cross_module.nim b/tests/template/tgensym_generic_cross_module.nim new file mode 100644 index 000000000..856ab676d --- /dev/null +++ b/tests/template/tgensym_generic_cross_module.nim @@ -0,0 +1,14 @@ +discard """ + output: '''foo55 +foo8.0 +fooaha +bar7''' +""" +# bug #5419 +import mgensym_generic_cross_module + +foo(55) +foo 8.0 +foo "aha" +bar 7 + diff --git a/tests/template/tgensym_label.nim b/tests/template/tgensym_label.nim new file mode 100644 index 000000000..fd3b0a1ee --- /dev/null +++ b/tests/template/tgensym_label.nim @@ -0,0 +1,18 @@ + +# bug #5417 +import macros + +macro genBody: untyped = + let sbx = genSym(nskLabel, "test") + when true: + result = quote do: + block `sbx`: + break `sbx` + else: + template foo(s1, s2) = + block s1: + break s2 + result = getAst foo(sbx, sbx) + +proc test() = + genBody() diff --git a/tests/threads/tonthreadcreation.nim b/tests/threads/tonthreadcreation.nim index 5d9b777b8..f588a21c9 100644 --- a/tests/threads/tonthreadcreation.nim +++ b/tests/threads/tonthreadcreation.nim @@ -7,19 +7,16 @@ var someGlobal: string = "some string here" perThread {.threadvar.}: string -proc setPerThread() = - {.gcsafe.}: - deepCopy(perThread, someGlobal) - -proc threadDied() {.gcsafe} = +proc threadDied() {.gcsafe.} = echo "dying ", perThread proc foo() {.thread.} = + onThreadDestruction threadDied + {.gcsafe.}: + deepCopy(perThread, someGlobal) echo perThread proc main = - onThreadCreation setPerThread - onThreadDestruction threadDied var t: Thread[void] createThread[void](t, foo) t.joinThread() |