diff options
author | Aman Gupta <aman@tmm1.net> | 2015-10-13 15:25:40 -0700 |
---|---|---|
committer | Aman Gupta <aman@tmm1.net> | 2015-10-13 15:25:40 -0700 |
commit | e2dbf222e60e00eb3f321151f4f206ed9c606a6c (patch) | |
tree | c513c0051fcb789add33cd3daaaab42344ee1da4 /tests | |
parent | c3415a27d77f302be4f41d5f9bbcdf7c0dd3e80a (diff) | |
parent | 7f4f37eaa20ea8aa5cf8c34e497aaa8245c590b3 (diff) | |
download | Nim-e2dbf222e60e00eb3f321151f4f206ed9c606a6c.tar.gz |
Merge remote-tracking branch 'origin/devel' into appveyor
Diffstat (limited to 'tests')
-rw-r--r-- | tests/actiontable/tactiontable.nim | 1 | ||||
-rw-r--r-- | tests/closure/tclosure4.nim | 2 | ||||
-rw-r--r-- | tests/collections/tapply.nim | 11 | ||||
-rw-r--r-- | tests/collections/tmapit.nim | 33 | ||||
-rw-r--r-- | tests/collections/ttables.nim | 6 | ||||
-rw-r--r-- | tests/collections/ttablesref.nim | 6 | ||||
-rw-r--r-- | tests/generics/tinferredgenericprocs.nim | 1 | ||||
-rw-r--r-- | tests/generics/tmap_auto.nim | 2 | ||||
-rw-r--r-- | tests/misc/teventemitter.nim | 3 | ||||
-rw-r--r-- | tests/newconfig/tfoo.nims | 3 | ||||
-rw-r--r-- | tests/overload/toverprc.nim | 2 | ||||
-rw-r--r-- | tests/parser/tcommand_as_expr.nim | 1 | ||||
-rw-r--r-- | tests/stdlib/tmget.nim | 141 | ||||
-rw-r--r-- | tests/stdlib/tmitems.nim | 2 | ||||
-rw-r--r-- | tests/stdlib/tunittest.nim | 2 | ||||
-rw-r--r-- | tests/template/twrongmapit.nim | 2 | ||||
-rw-r--r-- | tests/testament/backend.nim | 6 | ||||
-rw-r--r-- | tests/testament/categories.nim | 15 | ||||
-rw-r--r-- | tests/testament/htmlgen.nim | 2 | ||||
-rw-r--r-- | tests/testament/tester.nim | 10 |
20 files changed, 227 insertions, 24 deletions
diff --git a/tests/actiontable/tactiontable.nim b/tests/actiontable/tactiontable.nim index 18b0fd388..4560d0f7f 100644 --- a/tests/actiontable/tactiontable.nim +++ b/tests/actiontable/tactiontable.nim @@ -24,4 +24,3 @@ var "D": action4}.toTable actionTable["C"]("arg") - 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/collections/ttables.nim b/tests/collections/ttables.nim index a10606843..a8a182a78 100644 --- a/tests/collections/ttables.nim +++ b/tests/collections/ttables.nim @@ -60,8 +60,12 @@ block tableTest2: t["123"] = 1.5 # test overwriting assert t["123"] == 1.5 - assert t["111"] == 0.0 # deleted + try: + echo t["111"] # deleted + except KeyError: + discard assert(not hasKey(t, "111")) + assert "123" in t assert("111" notin t) diff --git a/tests/collections/ttablesref.nim b/tests/collections/ttablesref.nim index 0b641ebc7..32494f1f2 100644 --- a/tests/collections/ttablesref.nim +++ b/tests/collections/ttablesref.nim @@ -60,8 +60,10 @@ block tableTest2: t["123"] = 1.5 # test overwriting assert t["123"] == 1.5 - assert t["111"] == 0.0 # deleted - assert "123" in t + try: + echo t["111"] # deleted + except KeyError: + discard assert(not hasKey(t, "111")) assert "111" notin t 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 index dea9b571f..572556722 100644 --- a/tests/generics/tmap_auto.nim +++ b/tests/generics/tmap_auto.nim @@ -1,4 +1,4 @@ -import future +import future, sequtils let x = map(@[1, 2, 3], x => x+10) assert x == @[11, 12, 13] diff --git a/tests/misc/teventemitter.nim b/tests/misc/teventemitter.nim index 32cc81be4..7da1a2522 100644 --- a/tests/misc/teventemitter.nim +++ b/tests/misc/teventemitter.nim @@ -18,7 +18,7 @@ proc on*(emitter: var EventEmitter, event: string, if not hasKey(emitter.events, event): var list: DoublyLinkedList[proc(e: EventArgs) {.nimcall.}] add(emitter.events, event, list) #if not, add it. - append(emitter.events.mget(event), fn) + append(emitter.events[event], fn) proc initEmitter(emitter: var EventEmitter) = emitter.events = initTable[string, @@ -30,4 +30,3 @@ var initEmitter(ee) ee.on("print", proc(e: EventArgs) = echo("pie")) ee.emit("print", args) - diff --git a/tests/newconfig/tfoo.nims b/tests/newconfig/tfoo.nims index a2166576d..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": 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/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/stdlib/tmget.nim b/tests/stdlib/tmget.nim new file mode 100644 index 000000000..5792b6282 --- /dev/null +++ b/tests/stdlib/tmget.nim @@ -0,0 +1,141 @@ +discard """ + output: '''Can't access 6 +10 +11 +Can't access 6 +10 +11 +Can't access 6 +10 +11 +Can't access 6 +10 +11 +Can't access 6 +10 +11 +Can't access 6 +10 +11 +Can't access 6 +5 +Can't access 6 +10 +11 +Can't access 6 +10 +11''' +""" + +import tables + +block: + var x = initTable[int, int]() + x[5] = 10 + try: + echo x[6] + except KeyError: + echo "Can't access 6" + echo x[5] + x[5] += 1 + var c = x[5] + echo c + +block: + var x = newTable[int, int]() + x[5] = 10 + try: + echo x[6] + except KeyError: + echo "Can't access 6" + echo x[5] + x[5] += 1 + var c = x[5] + echo c + +block: + var x = initOrderedTable[int, int]() + x[5] = 10 + try: + echo x[6] + except KeyError: + echo "Can't access 6" + echo x[5] + x[5] += 1 + var c = x[5] + echo c + +block: + var x = newOrderedTable[int, int]() + x[5] = 10 + try: + echo x[6] + except KeyError: + echo "Can't access 6" + echo x[5] + x[5] += 1 + var c = x[5] + echo c + +block: + var x = initCountTable[int]() + x[5] = 10 + try: + echo x[6] + except KeyError: + echo "Can't access 6" + echo x[5] + x[5] += 1 + var c = x[5] + echo c + +block: + var x = newCountTable[int]() + x[5] = 10 + try: + echo x[6] + except KeyError: + echo "Can't access 6" + echo x[5] + x[5] += 1 + var c = x[5] + echo c + +import sets + +block: + var x = initSet[int]() + x.incl 5 + try: + echo x[6] + except KeyError: + echo "Can't access 6" + echo x[5] + +import critbits + +block: + var x: CritBitTree[int] + x["5"] = 10 + try: + echo x["6"] + except KeyError: + echo "Can't access 6" + echo x["5"] + x["5"] += 1 + var c = x["5"] + echo c + +import strtabs + +block: + var x = newStringTable() + x["5"] = "10" + try: + echo x["6"] + except KeyError: + echo "Can't access 6" + echo x["5"] + x["5"][1] = '1' + var c = x["5"] + echo c diff --git a/tests/stdlib/tmitems.nim b/tests/stdlib/tmitems.nim index 544ad0334..27ff344e5 100644 --- a/tests/stdlib/tmitems.nim +++ b/tests/stdlib/tmitems.nim @@ -132,5 +132,5 @@ block: </Students>""") for x in d.mitems: x = <>Student(Name=x.attrs["Name"] & "foo") - d.mget(1).attrs["Name"] = "bar" + d[1].attrs["Name"] = "bar" echo d 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/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/backend.nim b/tests/testament/backend.nim index 269835607..671b5c8b7 100644 --- a/tests/testament/backend.nim +++ b/tests/testament/backend.nim @@ -8,7 +8,7 @@ import strutils, db_sqlite, os, osproc -var db: TDbConn +var db: DbConn proc createDb() = db.exec(sql""" @@ -61,7 +61,7 @@ var proc `()`(cmd: string{lit}): string = cmd.execProcess.string.strip -proc getMachine*(db: TDbConn): MachineId = +proc getMachine*(db: DbConn): MachineId = var name = "hostname"() if name.len == 0: name = when defined(posix): getenv"HOSTNAME".string @@ -76,7 +76,7 @@ proc getMachine*(db: TDbConn): MachineId = result = db.insertId(sql"insert into Machine(name, os, cpu) values (?,?,?)", name, system.hostOS, system.hostCPU).MachineId -proc getCommit(db: TDbConn): CommitId = +proc getCommit(db: DbConn): CommitId = const commLen = "commit ".len let hash = "git log -n 1"()[commLen..commLen+10] let branch = "git symbolic-ref --short HEAD"() diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index d9fafaf7f..3bb18d8a2 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -119,12 +119,21 @@ 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" @@ -136,9 +145,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" diff --git a/tests/testament/htmlgen.nim b/tests/testament/htmlgen.nim index 98ccf1170..15960f09a 100644 --- a/tests/testament/htmlgen.nim +++ b/tests/testament/htmlgen.nim @@ -109,7 +109,7 @@ div.tabContent.hide { display: none; } proc td(s: string): string = result = "<td>" & s.substr(0, 200).xmlEncode & "</td>" -proc getCommit(db: TDbConn, c: int): string = +proc getCommit(db: DbConn, c: int): string = var commit = c for thisCommit in db.rows(sql"select id from [Commit] order by id desc"): if commit == 0: result = thisCommit[0] diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index a5e622010..451bee1d1 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -65,7 +65,7 @@ proc callCompiler(cmdTemplate, filename, options: string, let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target], "options", options, "file", filename.quoteShell]) var p = startProcess(command=c[0], args=c[1.. ^1], - options={poStdErrToStdOut, poUseShell}) + options={poStdErrToStdOut, poUsePath}) let outp = p.outputStream var suc = "" var err = "" @@ -215,7 +215,7 @@ proc generatedFile(path, name: string, target: TTarget): string = proc codegenCheck(test: TTest, check: string, given: var TSpec) = try: - let (path, name, ext2) = test.name.splitFile + let (path, name, _) = test.name.splitFile let genFile = generatedFile(path, name, test.target) let contents = readFile(genFile).string if check[0] == '\\': @@ -307,7 +307,7 @@ proc testSpec(r: var TResults, test: TTest) = let isJsTarget = test.target == targetJS var exeFile: string if isJsTarget: - let (dir, file, ext) = splitFile(tname) + let (dir, file, _) = splitFile(tname) exeFile = dir / "nimcache" / file & ".js" # *TODO* hardcoded "nimcache" else: exeFile = changeFileExt(tname, ExeExt) @@ -352,7 +352,7 @@ proc testSpec(r: var TResults, test: TTest) = 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") + #let tname = test.name.addFileExt(".nim") inc(r.total) let given = callCompiler(cmdTemplate, test.name, test.options, test.target) r.addResult(test, "", given.msg, given.err) @@ -368,7 +368,7 @@ proc testC(r: var TResults, test: TTest) = r.addResult(test, "", given.msg, given.err) elif test.action == actionRun: let exeFile = changeFileExt(test.name, ExeExt) - var (buf, exitCode) = execCmdEx(exeFile, options = {poStdErrToStdOut, poUseShell}) + var (_, exitCode) = execCmdEx(exeFile, options = {poStdErrToStdOut, poUsePath}) if exitCode != 0: given.err = reExitCodesDiffer if given.err == reSuccess: inc(r.passed) |