From 089529c16aa45926eb64395e27b8e56b46f4aa92 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 11 Aug 2018 05:03:42 +0200 Subject: [PATCH 1/6] Preliminary check for test category folder existence (#8579) Warn the user if nothing is executed. --- tests/testament/categories.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index f7cd0815cf..95521449af 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -523,5 +523,9 @@ proc processCategory(r: var TResults, cat: Category, options: string) = # We can't test it because it depends on a third party. discard # TODO: Move untestable tests to someplace else, i.e. nimble repo. else: + var testsRun = 0 for name in os.walkFiles("tests" & DirSep &.? cat.string / "t*.nim"): testSpec r, makeTest(name, options, cat) + inc testsRun + if testsRun == 0: + echo "[Warning] - Invalid category specified \"", cat.string, "\", no tests were run" From ba7c874a7df6e96dee2d7647a3f554d7476d3ae6 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 12 Aug 2018 20:41:48 +0200 Subject: [PATCH 2/6] Mysterious fix for #8550 (#8561) Replacing the `for` body with a nkEmpty node is not the right thing to do. --- compiler/transf.nim | 7 ++----- tests/closure/t8550.nim | 12 ++++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 tests/closure/t8550.nim diff --git a/compiler/transf.nim b/compiler/transf.nim index dae8d1ee6d..c3bc29891a 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -539,11 +539,8 @@ proc transformFor(c: PTransf, n: PNode): PTransNode = if call.kind notin nkCallKinds or call.sons[0].kind != nkSym or call.sons[0].typ.callConv == ccClosure: n.sons[length-1] = transformLoopBody(c, n.sons[length-1]).PNode - if not c.tooEarly: - n.sons[length-2] = transform(c, n.sons[length-2]).PNode - result[1] = lambdalifting.liftForLoop(c.graph, n, getCurrOwner(c)).PTransNode - else: - result[1] = newNode(nkEmpty).PTransNode + n.sons[length-2] = transform(c, n.sons[length-2]).PNode + result[1] = lambdalifting.liftForLoop(c.graph, n, getCurrOwner(c)).PTransNode discard c.breakSyms.pop return result diff --git a/tests/closure/t8550.nim b/tests/closure/t8550.nim new file mode 100644 index 0000000000..153246f085 --- /dev/null +++ b/tests/closure/t8550.nim @@ -0,0 +1,12 @@ +discard """ + output: "@[\"42\"]" +""" + +proc chk_fail(): seq[string] = + iterator x(): int {.closure.} = yield 42 + proc f(cl: iterator(): int {.closure.}): seq[string] = + result = @[] + for i in cl(): result.add($i) + result = f(x) + +echo(chk_fail()) From 3cb963f1147b79a96f98373fe4db9c7da5717919 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 12 Aug 2018 20:43:30 +0200 Subject: [PATCH 3/6] Fixes 8616 (#8617) * Don't leave dangling forward references to types Fixes #8616 * Add a test case for #8616 --- compiler/ccgstmts.nim | 2 +- tests/ccgbugs/pkg8616/rtarray.nim | 2 ++ tests/ccgbugs/pkg8616/scheduler.nim | 10 ++++++++++ tests/ccgbugs/t8616.nim | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/ccgbugs/pkg8616/rtarray.nim create mode 100644 tests/ccgbugs/pkg8616/scheduler.nim create mode 100644 tests/ccgbugs/t8616.nim diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 54759edb33..81e3fe4a7c 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -1130,8 +1130,8 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) = patchAsgnStmtListExpr(patchedTree, e, ri) genStmts(p, patchedTree) return - var a: TLoc + discard getTypeDesc(p.module, le.typ.skipTypes(skipPtrs)) if le.kind in {nkDerefExpr, nkHiddenDeref}: genDeref(p, le, a, enforceDeref=true) else: diff --git a/tests/ccgbugs/pkg8616/rtarray.nim b/tests/ccgbugs/pkg8616/rtarray.nim new file mode 100644 index 0000000000..286dbb8cd0 --- /dev/null +++ b/tests/ccgbugs/pkg8616/rtarray.nim @@ -0,0 +1,2 @@ +proc head*[T](pp: var array[1,T]): var T = + result = pp[0] diff --git a/tests/ccgbugs/pkg8616/scheduler.nim b/tests/ccgbugs/pkg8616/scheduler.nim new file mode 100644 index 0000000000..0730000c4a --- /dev/null +++ b/tests/ccgbugs/pkg8616/scheduler.nim @@ -0,0 +1,10 @@ +import rtarray + +type + T = tuple[x:int] + +var + arr: array[1,T] + +proc init*() = + discard head(arr) diff --git a/tests/ccgbugs/t8616.nim b/tests/ccgbugs/t8616.nim new file mode 100644 index 0000000000..54068652a2 --- /dev/null +++ b/tests/ccgbugs/t8616.nim @@ -0,0 +1,4 @@ +import pkg8616 / scheduler + +when isMainModule: + init() From e839c01f5b8b9fbe0d297be9d9bf8a429b49a1b1 Mon Sep 17 00:00:00 2001 From: Naveen Arunachalam Date: Sun, 12 Aug 2018 16:10:06 -0400 Subject: [PATCH 4/6] Clarify usage of "Test" argument in Koch (#8613) Minor change to help people (e.g. like myself) who are starting out :) Currently, the readme mentions the use of `./koch tests cat async`, but the help text for koch doesn't mention it. Helptexts are modified accordingly. --- koch.nim | 3 ++- tests/testament/tester.nim | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/koch.nim b/koch.nim index ad6a774e86..aa36d94a10 100644 --- a/koch.nim +++ b/koch.nim @@ -57,7 +57,8 @@ Commands for core developers: zip builds the installation zip package xz builds the installation tar.xz package testinstall test tar.xz package; Unix only! - tests [options] run the testsuite + tests [options] run the testsuite (run a subset of tests by + specifying a category, e.g. `tests cat async`) temp options creates a temporary compiler for testing winrelease creates a Windows release pushcsource push generated C sources to its repo diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index 136a509e46..9558257a64 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -22,7 +22,7 @@ const Command: all run all tests - c|category run all the tests of a certain category + c|cat|category run all the tests of a certain category r|run run single test file html generate $1 from the database Arguments: From ee29370f6039df749f8b3a450b545ea220b6bd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Montes?= Date: Mon, 13 Aug 2018 11:42:50 +0200 Subject: [PATCH 5/6] Fixed 7478: splitLines keepEol option (#8621) --- lib/pure/strutils.nim | 33 +++++++++++++++++++++------------ tests/stdlib/tstrutil.nim | 9 ++++++++- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index f8c5f9a916..be7ff60a21 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -624,12 +624,13 @@ iterator rsplit*(s: string, sep: string, maxsplit: int = -1, ## Substrings are separated from the right by the string `sep` rsplitCommon(s, sep, maxsplit, sep.len) -iterator splitLines*(s: string): string = +iterator splitLines*(s: string, keepEol = false): string = ## Splits the string `s` into its containing lines. ## ## Every `character literal `_ newline ## combination (CR, LF, CR-LF) is supported. The result strings contain no - ## trailing ``\n``. + ## trailing end of line characters unless parameter ``keepEol`` is set to + ## ``true``. ## ## Example: ## @@ -649,22 +650,30 @@ iterator splitLines*(s: string): string = ## "" var first = 0 var last = 0 + var eolpos = 0 while true: while last < s.len and s[last] notin {'\c', '\l'}: inc(last) - yield substr(s, first, last-1) - # skip newlines: - if last >= s.len: break - if s[last] == '\l': inc(last) - elif s[last] == '\c': - inc(last) - if last < s.len and s[last] == '\l': inc(last) + + eolpos = last + if last < s.len: + if s[last] == '\l': inc(last) + elif s[last] == '\c': + inc(last) + if last < s.len and s[last] == '\l': inc(last) + + yield substr(s, first, if keepEol: last-1 else: eolpos-1) + + # no eol characters consumed means that the string is over + if eolpos == last: + break + first = last -proc splitLines*(s: string): seq[string] {.noSideEffect, +proc splitLines*(s: string, keepEol = false): seq[string] {.noSideEffect, rtl, extern: "nsuSplitLines".} = ## The same as the `splitLines <#splitLines.i,string>`_ iterator, but is a ## proc that returns a sequence of substrings. - accumulateResult(splitLines(s)) + accumulateResult(splitLines(s, keepEol=keepEol)) proc countLines*(s: string): int {.noSideEffect, rtl, extern: "nsuCountLines".} = @@ -908,7 +917,7 @@ proc parseOctInt*(s: string): int {.noSideEffect, ## `s` are ignored. let L = parseutils.parseOct(s, result, 0) if L != s.len or L == 0: - raise newException(ValueError, "invalid oct integer: " & s) + raise newException(ValueError, "invalid oct integer: " & s) proc parseHexInt*(s: string): int {.noSideEffect, procvar, rtl, extern: "nsuParseHexInt".} = diff --git a/tests/stdlib/tstrutil.nim b/tests/stdlib/tstrutil.nim index 4d4081d390..f0ee755f7c 100644 --- a/tests/stdlib/tstrutil.nim +++ b/tests/stdlib/tstrutil.nim @@ -199,6 +199,12 @@ proc testRFind = assert "0123456789ABCDEFGAH".rfind({'A'..'C'}, 13) == 12 assert "0123456789ABCDEFGAH".rfind({'G'..'H'}, 13) == -1 +proc testSplitLines() = + let fixture = "a\nb\rc\r\nd" + assert len(fixture.splitLines) == 4 + assert splitLines(fixture) == @["a", "b", "c", "d"] + assert splitLines(fixture, keepEol=true) == @["a\n", "b\r", "c\r\n", "d"] + proc testCountLines = proc assertCountLines(s: string) = assert s.countLines == s.splitLines.len assertCountLines("") @@ -229,7 +235,7 @@ proc testParseInts = assert "72".parseHexInt == 114 assert "FF".parseHexInt == 255 assert "ff".parseHexInt == 255 - assert "fF".parseHexInt == 255 + assert "fF".parseHexInt == 255 assert "0x7_2".parseHexInt == 114 rejectParse "".parseHexInt rejectParse "_".parseHexInt @@ -252,6 +258,7 @@ proc testParseInts = testDelete() testFind() testRFind() +testSplitLines() testCountLines() testParseInts() From aa1cdebdc206857902081b4862dad2c2990179e8 Mon Sep 17 00:00:00 2001 From: cooldome Date: Mon, 13 Aug 2018 15:02:20 +0200 Subject: [PATCH 6/6] Converters to take into account constraints. Fixes #7520 (#8593) --- compiler/sigmatch.nim | 4 ++++ .../converter/tconverter_with_constraint.nim | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/converter/tconverter_with_constraint.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 5afa1b0312..c665aad7f2 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1809,6 +1809,10 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType, # see tests/tgenericconverter: let srca = typeRel(m, src, a) if srca notin {isEqual, isGeneric, isSubtype}: continue + + let constraint = c.converters[i].typ.n[1].sym.constraint + if not constraint.isNil and not matchNodeKinds(constraint, arg): + continue let destIsGeneric = containsGenericType(dest) if destIsGeneric: diff --git a/tests/converter/tconverter_with_constraint.nim b/tests/converter/tconverter_with_constraint.nim new file mode 100644 index 0000000000..7932644340 --- /dev/null +++ b/tests/converter/tconverter_with_constraint.nim @@ -0,0 +1,20 @@ + +discard """ + file: "tconverter_with_constraint.nim" + line: 20 + errormsg: "type mismatch: got " +""" + +type + MyType = distinct int + +converter to_mytype(m: int{lit}): MyType = + m.MyType + +proc myproc(m: MyType) = + echo m.int, ".MyType" + +myproc(1) # call by literal is ok + +var x: int = 12 +myproc(x) # should fail \ No newline at end of file