diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/async/tasyncfilewrite.nim | 17 | ||||
-rw-r--r-- | tests/collections/ttables.nim | 15 | ||||
-rw-r--r-- | tests/macros/tgettypeinst.nim | 65 | ||||
-rw-r--r-- | tests/stdlib/thttpclient.nim | 20 | ||||
-rw-r--r-- | tests/testament/specs.nim | 11 | ||||
-rw-r--r-- | tests/testament/tester.nim | 6 |
6 files changed, 101 insertions, 33 deletions
diff --git a/tests/async/tasyncfilewrite.nim b/tests/async/tasyncfilewrite.nim new file mode 100644 index 000000000..cda612bae --- /dev/null +++ b/tests/async/tasyncfilewrite.nim @@ -0,0 +1,17 @@ +discard """ + output: '''string 1 +string 2 +string 3''' +""" +# bug #5532 +import os, asyncfile, asyncdispatch + +removeFile("test.txt") +let f = openAsync("test.txt", fmWrite) +var futs = newSeq[Future[void]]() +for i in 1..3: + futs.add(f.write("string " & $i & "\n")) +waitFor(all(futs)) +f.close() +echo readFile("test.txt") + diff --git a/tests/collections/ttables.nim b/tests/collections/ttables.nim index a2988e841..01dab44fc 100644 --- a/tests/collections/ttables.nim +++ b/tests/collections/ttables.nim @@ -235,6 +235,21 @@ block withKeyTest: except KeyError: discard +block takeTest: + var t = initTable[string, int]() + t["key"] = 123 + + var val = 0 + assert(t.take("key", val)) + assert(val == 123) + + val = -1 + assert(not t.take("key", val)) + assert(val == -1) + + assert(not t.take("otherkey", val)) + assert(val == -1) + proc orderedTableSortTest() = var t = initOrderedTable[string, int](2) for key, val in items(data): t[key] = val diff --git a/tests/macros/tgettypeinst.nim b/tests/macros/tgettypeinst.nim index 255eff949..f89aa5e0b 100644 --- a/tests/macros/tgettypeinst.nim +++ b/tests/macros/tgettypeinst.nim @@ -21,49 +21,67 @@ proc symToIdent(x: NimNode): NimNode = for c in x: result.add symToIdent(c) +# check getTypeInst and getTypeImpl for given symbol x macro testX(x,inst0: typed; recurse: static[bool]; implX: stmt): typed = + # check that getTypeInst(x) equals inst0 let inst = x.getTypeInst - let impl = x.getTypeImpl - let inst0r = inst0.symToIdent.treeRepr let instr = inst.symToIdent.treeRepr - #echo inst0r + let inst0r = inst0.symToIdent.treeRepr #echo instr + #echo inst0r doAssert(instr == inst0r) + + # check that getTypeImpl(x) is correct + # if implX is nil then compare to inst0 + # else we expect implX to be a type definition + # and we extract the implementation from that + let impl = x.getTypeImpl var impl0 = if implX.kind == nnkNilLit: inst0 else: implX[0][2] - let impl0r = impl0.symToIdent.treerepr let implr = impl.symToIdent.treerepr - #echo impl0r + let impl0r = impl0.symToIdent.treerepr #echo implr + #echo impl0r doAssert(implr == impl0r) - template echoString(s:string) = echo s.replace("\n","\n ") + result = newStmtList() + #template echoString(s: string) = echo s.replace("\n","\n ") #result.add getAst(echoString(" " & inst0.repr)) #result.add getAst(echoString(" " & inst.repr)) #result.add getAst(echoString(" " & impl0.repr)) #result.add getAst(echoString(" " & impl.repr)) + if recurse: - template testDecl(n, m :typed) = + # now test using a newly formed variable of type getTypeInst(x) + template testDecl(n,m: typed) = testV(n, false): type _ = m result.add getAst(testDecl(inst.symToIdent, impl.symToIdent)) +# test with a variable (instance) of type template testV(inst, recurse, impl) = block: #echo "testV(" & astToStr(inst) & ", " & $recurse & "):" & astToStr(impl) var x: inst testX(x, inst, recurse, impl) -template testT(inst, recurse) = + +# test with a newly created typedesc (myType) +# using the passed type as the implementation +template testT(impl, recurse) = block: - type myType = inst + type myType = impl testV(myType, recurse): - type _ = inst + type _ = impl +# test a built-in type whose instance is equal to the implementation template test(inst) = testT(inst, false) testV(inst, true, nil) -template test(inst, impl) = testV(inst, true, impl) + +# test a custom type with provided implementation +template test(inst, impl) = + testV(inst, true, impl) type Model = object of RootObj @@ -87,9 +105,12 @@ type value:T Foo[N:static[int],T] = object Bar[N:static[int],T] = object - #baz:Foo[N+1,GenericObject[T]] + #baz:Foo[N+1,GenericObject[T]] # currently fails baz:Foo[N,GenericObject[T]] + Generic[T] = seq[int] + Concrete = Generic[int] + test(bool) test(char) test(int) @@ -97,13 +118,17 @@ test(float) test(ptr int) test(ref int) test(array[1..10,Bar[2,Foo[3,float]]]) +test(array[MyEnum,Bar[2,Foo[3,float]]]) test(distinct Bar[2,Foo[3,float]]) test(tuple[a:int,b:Foo[-1,float]]) -#test(MyEnum): -# type _ = enum -# valueA, valueB, valueC -test(set[MyEnum]) test(seq[int]) +test(set[MyEnum]) +test(proc (a: int, b: Foo[2,float])) +test(proc (a: int, b: Foo[2,float]): Bar[3,int]) + +test(MyEnum): + type _ = enum + valueA, valueB, valueC test(Bar[2,Foo[3,float]]): type _ = object baz: Foo[2, GenericObject[Foo[3, float]]] @@ -118,8 +143,12 @@ test(Tree): value: int left: ref Tree right: ref Tree -test(proc (a: int, b: Foo[2,float])) -test(proc (a: int, b: Foo[2,float]): Bar[3,int]) +test(Concrete): + type _ = Generic[int] +test(Generic[int]): + type _ = seq[int] +test(Generic[float]): + type _ = seq[int] # bug #4862 static: diff --git a/tests/stdlib/thttpclient.nim b/tests/stdlib/thttpclient.nim index 40324d92a..c6a857edb 100644 --- a/tests/stdlib/thttpclient.nim +++ b/tests/stdlib/thttpclient.nim @@ -104,15 +104,17 @@ proc syncTest() = client.close() - # Timeout test. - client = newHttpClient(timeout = 1) - try: - resp = client.request("http://example.com/") - doAssert false, "TimeoutError should have been raised." - except TimeoutError: - discard - except: - doAssert false, "TimeoutError should have been raised." + when false: + # Disabled for now because it causes troubles with AppVeyor + # Timeout test. + client = newHttpClient(timeout = 1) + try: + resp = client.request("http://example.com/") + doAssert false, "TimeoutError should have been raised." + except TimeoutError: + discard + except: + doAssert false, "TimeoutError should have been raised." proc makeIPv6HttpServer(hostname: string, port: Port): AsyncFD = let fd = newNativeSocket(AF_INET6) diff --git a/tests/testament/specs.nim b/tests/testament/specs.nim index 91e8b2ec7..ab24acc70 100644 --- a/tests/testament/specs.nim +++ b/tests/testament/specs.nim @@ -9,8 +9,11 @@ import parseutils, strutils, os, osproc, streams, parsecfg -const - cmdTemplate* = r"compiler" / "nim $target --lib:lib --hints:on -d:testing $options $file" + +var compilerPrefix* = "compiler" / "nim " + +proc cmdTemplate*(): string = + compilerPrefix & "$target --lib:lib --hints:on -d:testing $options $file" type TTestAction* = enum @@ -100,7 +103,7 @@ proc specDefaults*(result: var TSpec) = result.outp = "" result.nimout = "" result.ccodeCheck = "" - result.cmd = cmdTemplate + result.cmd = cmdTemplate() result.line = 0 result.column = 0 result.tfile = "" @@ -173,7 +176,7 @@ proc parseSpec*(filename: string): TSpec = raise newException(ValueError, "cannot interpret as a bool: " & e.value) of "cmd": if e.value.startsWith("nim "): - result.cmd = "compiler" / e.value + result.cmd = compilerPrefix & e.value[4..^1] else: result.cmd = e.value of "ccodecheck": result.ccodeCheck = e.value diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index 2d758ef0d..0f74de013 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -34,6 +34,7 @@ Options: --failing only show failing/ignored tests --pedantic return non-zero status code if there are failures --targets:"c c++ js objc" run tests for specified targets (default: all) + --nim:path use a particular nim executable (default: compiler/nim) """ % resultsFile type @@ -367,7 +368,7 @@ proc testNoSpec(r: var TResults, test: TTest) = # does not extract the spec because the file is not supposed to have any #let tname = test.name.addFileExt(".nim") inc(r.total) - let given = callCompiler(cmdTemplate, test.name, test.options, test.target) + let given = callCompiler(cmdTemplate(), test.name, test.options, test.target) r.addResult(test, "", given.msg, given.err) if given.err == reSuccess: inc(r.passed) @@ -376,7 +377,7 @@ proc testC(r: var TResults, test: TTest) = let tname = test.name.addFileExt(".c") inc(r.total) styledEcho "Processing ", fgCyan, extractFilename(tname) - var given = callCCompiler(cmdTemplate, test.name & ".c", test.options, test.target) + var given = callCCompiler(cmdTemplate(), test.name & ".c", test.options, test.target) if given.err != reSuccess: r.addResult(test, "", given.msg, given.err) elif test.action == actionRun: @@ -424,6 +425,7 @@ proc main() = of "failing": optFailing = true of "pedantic": optPedantic = true of "targets": targets = parseTargets(p.val.string) + of "nim": compilerPrefix = p.val.string else: quit Usage p.next() if p.kind != cmdArgument: quit Usage |