From 2793170feddab3e2124216c695de45ae7c541477 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 7 Jun 2013 18:25:57 +0200 Subject: [PATCH 01/13] Makes caasdriver exit with number of errors. Also displays result and separator after each test. --- .gitignore | 3 +++ tests/caasdriver.nim | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 7bca71531..93dae69ba 100644 --- a/.gitignore +++ b/.gitignore @@ -167,4 +167,7 @@ examples/cross_calculator/android/tags /run.json /testresults.html /testresults.json +/tests/caas/imported +/tests/caas/main +/tests/caasdriver /tools/nimgrep diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index 3f3d3671e..7472cfdeb 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -18,9 +18,9 @@ proc startNimrodSession*(project: string): TNimrodSession = proc doCommand*(session: var TNimrodSession, command: string): string = session.nim.inputStream.write(command & "\n") session.nim.inputStream.flush - + result = "" - + while true: var line = TaintedString("") if session.nim.outputStream.readLine(line): @@ -38,7 +38,7 @@ proc doScenario(script: string, output: PStream): bool = var f = open(script) var project = TaintedString("") - + if f.readLine(project): var s = startNimrodSession(script.dirname / project.string) @@ -78,9 +78,14 @@ iterator caasTestsRunner*(filter = ""): tuple[test, output: string, yield (scenario, outStream.data, r) when isMainModule: - var filter = "" + var + filter = "" + failures = 0 if paramCount() > 0: filter = paramStr(1) - - for t, o, r in caasTestsRunner(filter): - echo t, "\n", o - + + for test, output, result in caasTestsRunner(filter): + echo test, "\n", output, "-> ", $result, "\n-----" + if not result: + failures += 1 + + quit(failures) From 18725aab28b7a6a58926b34c263252f77cf94b7d Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 7 Jun 2013 18:32:43 +0200 Subject: [PATCH 02/13] Adds verbose switch, by default reports only failures. --- tests/caasdriver.nim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index 7472cfdeb..b36b6f5b7 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -81,10 +81,20 @@ when isMainModule: var filter = "" failures = 0 - if paramCount() > 0: filter = paramStr(1) + verbose = false + + for i in 0..ParamCount() - 1: + let param = paramStr(i + 1) + case param + of "verbose": verbose = true + else: filter = param + + if verbose and len(filter) > 0: + echo "Running only test cases matching filter '$1'" % [filter] for test, output, result in caasTestsRunner(filter): - echo test, "\n", output, "-> ", $result, "\n-----" + if not result or verbose: + echo test, "\n", output, "-> ", $result, "\n-----" if not result: failures += 1 From 298f546be0ec4fa5ff1d8877780d002d4edf242c Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 7 Jun 2013 18:47:31 +0200 Subject: [PATCH 03/13] Adds embedded comment describing program usage. --- tests/caasdriver.nim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index b36b6f5b7..f319512b9 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -1,5 +1,27 @@ import osproc, streams, os, strutils, re +## Compiler as a service tester. +## +## This test cases uses the txt files in the caas/ subdirectory. +## Each of the text files inside encodes a session with the compiler. +## The first line indicates the main project file. Lines starting with '>' +## indicate a command to be sent to the compiler and the lines following a +## command include checks for expected or forbidden output (! for forbidden). +## +## You can optionally pass parameters at the command line to modify the +## behaviour of the test suite. By default only tests which fail will be echoed +## to stdout. If you want to see all the output pass the word "verbose" as a +## parameter. +## +## If you don't want to run all the test case files, you can pass any substring +## as a parameter. Only files matching the passed substring will be run. The +## filtering doesn't use any globbing metacharacters, it's a plain match. +## +## Example to run only "*-compile*.txt" tests in verbose mode: +## +## ./caasdriver verbose -compile + + type TNimrodSession* = object nim: PProcess From 9b0e03cb2e87d325cca232ccd36a3e2735c3a5c9 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 7 Jun 2013 18:51:52 +0200 Subject: [PATCH 04/13] Replaces dirname with osproc.parentDir. --- tests/caasdriver.nim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index f319512b9..9d3e91b22 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -26,15 +26,13 @@ type TNimrodSession* = object nim: PProcess -proc dirname(path: string): string = path.splitPath()[0] - var TesterDir = getAppDir() NimrodBin = TesterDir / "../bin/nimrod" proc startNimrodSession*(project: string): TNimrodSession = result.nim = startProcess(NimrodBin, - workingDir = project.dirname, + workingDir = project.parentDir, args = ["serve", "--server.type:stdin", project]) proc doCommand*(session: var TNimrodSession, command: string): string = @@ -63,7 +61,7 @@ proc doScenario(script: string, output: PStream): bool = if f.readLine(project): var - s = startNimrodSession(script.dirname / project.string) + s = startNimrodSession(script.parentDir / project.string) tline = TaintedString("") lastOutput = "" ln = 1 From 8f76092b89212ed9f691d288d11dc660dacc9d52 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 7 Jun 2013 19:47:33 +0200 Subject: [PATCH 05/13] Runs all caas tests also in process mode. This requires changing a little bit the test cases to avoid specifying the filename as the last parameter. The trackDirty switch still doesn't work for process mode. Also revers some SuccessX which I think were hidden in the amount of output verbosity. --- tests/caas/compile-suggest.txt | 2 +- tests/caas/compile-then-def.txt | 8 ++-- tests/caas/def-def-compile.txt | 8 ++-- tests/caas/def-then-compile.txt | 4 +- tests/caas/suggest-compile.txt | 2 +- tests/caasdriver.nim | 75 ++++++++++++++++++++++++--------- 6 files changed, 67 insertions(+), 32 deletions(-) diff --git a/tests/caas/compile-suggest.txt b/tests/caas/compile-suggest.txt index 4e2ab9729..3cc0ee0cb 100644 --- a/tests/caas/compile-suggest.txt +++ b/tests/caas/compile-suggest.txt @@ -1,7 +1,7 @@ main.nim > c SuccessX -> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest main.nim +> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest skField\tx skField\ty diff --git a/tests/caas/compile-then-def.txt b/tests/caas/compile-then-def.txt index a5080c50d..839ca1532 100644 --- a/tests/caas/compile-then-def.txt +++ b/tests/caas/compile-then-def.txt @@ -1,9 +1,9 @@ main.nim > c SuccessX -> idetools --track:main.nim,5,18 --def main.nim +> idetools --track:main.nim,5,18 --def strutils.toUpper -SuccessX -> idetools --track:main.nim,5,18 --def main.nim +! SuccessX +> idetools --track:main.nim,5,18 --def strutils.toUpper -SuccessX +! SuccessX diff --git a/tests/caas/def-def-compile.txt b/tests/caas/def-def-compile.txt index 64002aff1..05ea5a1aa 100644 --- a/tests/caas/def-def-compile.txt +++ b/tests/caas/def-def-compile.txt @@ -1,10 +1,10 @@ main.nim -> idetools --track:main.nim,5,18 --def main.nim +> idetools --track:main.nim,5,18 --def strutils.toUpper -SuccessX -> idetools --track:main.nim,5,18 --def main.nim +! SuccessX +> idetools --track:main.nim,5,18 --def strutils.toUpper -SuccessX +! SuccessX > c SuccessX diff --git a/tests/caas/def-then-compile.txt b/tests/caas/def-then-compile.txt index efa4dcbb3..7e755cff2 100644 --- a/tests/caas/def-then-compile.txt +++ b/tests/caas/def-then-compile.txt @@ -1,7 +1,7 @@ main.nim -> idetools --track:main.nim,5,18 --def main.nim +> idetools --track:main.nim,5,18 --def strutils.toUpper -SuccessX +! SuccessX > c SuccessX diff --git a/tests/caas/suggest-compile.txt b/tests/caas/suggest-compile.txt index 49d0dc431..76756c86e 100644 --- a/tests/caas/suggest-compile.txt +++ b/tests/caas/suggest-compile.txt @@ -1,5 +1,5 @@ main.nim -> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest main.nim +> idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest skField\tx skField\ty > c diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index 9d3e91b22..2f482a810 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -23,19 +23,30 @@ import osproc, streams, os, strutils, re type + TRunMode = enum + ProcRun, CaasRun + TNimrodSession* = object - nim: PProcess + nim: PProcess # Holds the open process for CaasRun sessions, nil otherwise. + mode: TRunMode # Stores the type of run mode the session was started with. + lastOutput: string # Preserves the last output, needed for ProcRun mode. + filename: string # Appended to each command starting with '>'. var TesterDir = getAppDir() NimrodBin = TesterDir / "../bin/nimrod" -proc startNimrodSession*(project: string): TNimrodSession = - result.nim = startProcess(NimrodBin, - workingDir = project.parentDir, - args = ["serve", "--server.type:stdin", project]) +proc startNimrodSession(project: string, mode: TRunMode): TNimrodSession = + let (dir, name) = project.SplitPath + result.mode = mode + result.lastOutput = "" + result.filename = name + if mode == CaasRun: + result.nim = startProcess(NimrodBin, workingDir = dir, + args = ["serve", "--server.type:stdin", name]) -proc doCommand*(session: var TNimrodSession, command: string): string = +proc doCaasCommand(session: var TNimrodSession, command: string): string = + assert session.mode == CaasRun session.nim.inputStream.write(command & "\n") session.nim.inputStream.flush @@ -50,10 +61,34 @@ proc doCommand*(session: var TNimrodSession, command: string): string = result = "FAILED TO EXECUTE: " & command & "\n" & result break -proc close(session: var TNimrodSession) {.destructor.} = - session.nim.close +proc doProcCommand(session: var TNimrodSession, command: string): string = + assert session.mode == ProcRun + except: result = "FAILED TO EXECUTE: " & command & "\n" & result + var + process = startProcess(NimrodBin, args = command.split) + stream = outputStream(process) + line = TaintedString("") -proc doScenario(script: string, output: PStream): bool = + result = "" + while stream.readLine(line): + if result.len > 0: result &= "\n" + result &= line.string + + process.close() + +proc doCommand(session: var TNimrodSession, command: string) = + if session.mode == CaasRun: + session.lastOutput = doCaasCommand(session, + command & " " & session.filename) + else: + session.lastOutput = doProcCommand(session, + command & " " & session.filename) + +proc close(session: var TNimrodSession) {.destructor.} = + if session.mode == CaasRun: + session.nim.close + +proc doScenario(script: string, output: PStream, mode: TRunMode): bool = result = true var f = open(script) @@ -61,9 +96,8 @@ proc doScenario(script: string, output: PStream): bool = if f.readLine(project): var - s = startNimrodSession(script.parentDir / project.string) + s = startNimrodSession(script.parentDir / project.string, mode) tline = TaintedString("") - lastOutput = "" ln = 1 while f.readLine(tline): @@ -72,8 +106,8 @@ proc doScenario(script: string, output: PStream): bool = if line.strip.len == 0: continue if line.startsWith(">"): - lastOutput = s.doCommand(line.substr(1).strip) - output.writeln line, "\n", lastOutput + s.doCommand(line.substr(1).strip) + output.writeln line, "\n", s.lastOutput else: var expectMatch = true var pattern = line @@ -81,7 +115,7 @@ proc doScenario(script: string, output: PStream): bool = pattern = line.substr(1).strip expectMatch = false - var actualMatch = lastOutput.find(re(pattern)) != -1 + var actualMatch = s.lastOutput.find(re(pattern)) != -1 if expectMatch == actualMatch: output.writeln "SUCCESS ", line @@ -90,12 +124,13 @@ proc doScenario(script: string, output: PStream): bool = result = false iterator caasTestsRunner*(filter = ""): tuple[test, output: string, - status: bool] = + status: bool, mode: TRunMode] = for scenario in os.walkFiles(TesterDir / "caas/*.txt"): if filter.len > 0 and find(scenario, filter) == -1: continue - var outStream = newStringStream() - let r = doScenario(scenario, outStream) - yield (scenario, outStream.data, r) + for mode in [CaasRun, ProcRun]: + var outStream = newStringStream() + let r = doScenario(scenario, outStream, mode) + yield (scenario, outStream.data, r, mode) when isMainModule: var @@ -112,9 +147,9 @@ when isMainModule: if verbose and len(filter) > 0: echo "Running only test cases matching filter '$1'" % [filter] - for test, output, result in caasTestsRunner(filter): + for test, output, result, mode in caasTestsRunner(filter): if not result or verbose: - echo test, "\n", output, "-> ", $result, "\n-----" + echo test, "\n", output, "-> ", $mode, ":", $result, "\n-----" if not result: failures += 1 From 1d813167c4464e3d955764ca54a1df51817ace4d Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 7 Jun 2013 20:26:09 +0200 Subject: [PATCH 06/13] Implements prefixes for comments or specific mode runs. --- tests/caas/basic-recompile.txt | 5 ++++- tests/caas/compile-suggest.txt | 5 +++-- tests/caas/suggest-compile.txt | 5 +++-- tests/caasdriver.nim | 39 ++++++++++++++++++++++++++++------ 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/tests/caas/basic-recompile.txt b/tests/caas/basic-recompile.txt index 9c943fe88..d869944b9 100644 --- a/tests/caas/basic-recompile.txt +++ b/tests/caas/basic-recompile.txt @@ -2,6 +2,9 @@ main.nim > c SuccessX > c -! Processing +# The "Processing" string will be found always in proc mode since each +# compilation command will generate it. We need to test it only in Caas mode to +# verify the server is not recompiling again the file. +CaasRun ! Processing SuccessX diff --git a/tests/caas/compile-suggest.txt b/tests/caas/compile-suggest.txt index 3cc0ee0cb..f90fc5aa1 100644 --- a/tests/caas/compile-suggest.txt +++ b/tests/caas/compile-suggest.txt @@ -1,7 +1,8 @@ main.nim > c SuccessX +# Ugh, undocumented trackDirty, how is it supposed to work? Fails in proc mode. > idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest -skField\tx -skField\ty +CaasRun skField\tx +CaasRun skField\ty diff --git a/tests/caas/suggest-compile.txt b/tests/caas/suggest-compile.txt index 76756c86e..897d14f52 100644 --- a/tests/caas/suggest-compile.txt +++ b/tests/caas/suggest-compile.txt @@ -1,7 +1,8 @@ main.nim +# Ugh, undocumented trackDirty, how is it supposed to work? Fails in proc mode. > idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest -skField\tx -skField\ty +CaasRun skField\tx +CaasRun skField\ty > c SuccessX diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index 2f482a810..d6f4a8bd6 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -3,10 +3,23 @@ import osproc, streams, os, strutils, re ## Compiler as a service tester. ## ## This test cases uses the txt files in the caas/ subdirectory. -## Each of the text files inside encodes a session with the compiler. -## The first line indicates the main project file. Lines starting with '>' -## indicate a command to be sent to the compiler and the lines following a -## command include checks for expected or forbidden output (! for forbidden). +## +## Each of the text files inside encodes a session with the compiler: +## +## The first line indicates the main project file. +## +## Lines starting with '>' indicate a command to be sent to the compiler and +## the lines following a command include checks for expected or forbidden +## output (! for forbidden). +## +## If a line starts with '#' it will be ignored completely, so you can use that +## for comments. +## +## All the tests are run both in ProcRun (each command creates a separate +## process) and CaasRun (first command starts up a server and it is reused for +## the rest) modes. Since some cases are specific to either ProcRun or CaasRun +## modes, you can prefix a line with the mode and the line will be processed +## only in that mode. ## ## You can optionally pass parameters at the command line to modify the ## behaviour of the test suite. By default only tests which fail will be echoed @@ -32,6 +45,8 @@ type lastOutput: string # Preserves the last output, needed for ProcRun mode. filename: string # Appended to each command starting with '>'. +const modes = [CaasRun, ProcRun] + var TesterDir = getAppDir() NimrodBin = TesterDir / "../bin/nimrod" @@ -103,9 +118,21 @@ proc doScenario(script: string, output: PStream, mode: TRunMode): bool = while f.readLine(tline): var line = tline.string inc ln + + # Filter lines by run mode, removing the prefix if the mode is current. + for testMode in modes: + if line.startsWith($testMode): + if testMode != mode: + line = "" + else: + line = line[len($testMode)..len(line) - 1].strip + break + if line.strip.len == 0: continue - if line.startsWith(">"): + if line.startsWith("#"): + continue + elif line.startsWith(">"): s.doCommand(line.substr(1).strip) output.writeln line, "\n", s.lastOutput else: @@ -127,7 +154,7 @@ iterator caasTestsRunner*(filter = ""): tuple[test, output: string, status: bool, mode: TRunMode] = for scenario in os.walkFiles(TesterDir / "caas/*.txt"): if filter.len > 0 and find(scenario, filter) == -1: continue - for mode in [CaasRun, ProcRun]: + for mode in modes: var outStream = newStringStream() let r = doScenario(scenario, outStream, mode) yield (scenario, outStream.data, r, mode) From f11a3b2324290cfebc328284c6f74287e7652e44 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 7 Jun 2013 21:24:45 +0200 Subject: [PATCH 07/13] Adds generic idetools api test case. At the moment three lines of the test case fail in proc mode. --- .gitignore | 1 + tests/caas/idetools_api.nim | 23 +++++++++++++++++++++ tests/caas/idetools_api.txt | 41 +++++++++++++++++++++++++++++++++++++ tests/caasdriver.nim | 6 +++++- 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/caas/idetools_api.nim create mode 100644 tests/caas/idetools_api.txt diff --git a/.gitignore b/.gitignore index 93dae69ba..025c4ca35 100644 --- a/.gitignore +++ b/.gitignore @@ -167,6 +167,7 @@ examples/cross_calculator/android/tags /run.json /testresults.html /testresults.json +/tests/caas/idetools_api /tests/caas/imported /tests/caas/main /tests/caasdriver diff --git a/tests/caas/idetools_api.nim b/tests/caas/idetools_api.nim new file mode 100644 index 000000000..930d26429 --- /dev/null +++ b/tests/caas/idetools_api.nim @@ -0,0 +1,23 @@ +import unicode, sequtils + +proc test_enums() = + var o: Tfile + if o.open("files " & "test.txt", fmWrite): + o.write("test") + o.close() + +proc test_iterators(filename = "tests.nim") = + let + input = readFile(filename) + letters = toSeq(runes(string(input))) + for letter in letters: echo int(letter) + +const SOME_SEQUENCE = @[1, 2] +type + bad_string = distinct string + TPerson = object of TObject + name*: bad_string + age: int + +proc adder(a, b: int): int = + result = a + b diff --git a/tests/caas/idetools_api.txt b/tests/caas/idetools_api.txt new file mode 100644 index 000000000..eaa91cd5f --- /dev/null +++ b/tests/caas/idetools_api.txt @@ -0,0 +1,41 @@ +idetools_api.nim +> c +SuccessX +> idetools --track:idetools_api.nim,4,11 --def +def\tskType\tsystem.TFile\tTFile +> idetools --track:idetools_api.nim,5,7 --def +def\tskProc\tsystem.Open\tproc \(var TFile, string, TFileMode, int\): bool +> idetools --track:idetools_api.nim,5,21 --def +def\tskProc\tsystem.\&\tproc \(string, string\): string\{.noSideEffect.\} +> idetools --track:idetools_api.nim,5,38 --def +def\tskEnumField\tsystem.TFileMode.fmWrite\tTFileMode +> idetools --track:idetools_api.nim,7,6 --def +def\tskProc\tsystem.Close\tproc \(TFile\) +> idetools --track:idetools_api.nim,12,23 --def +def\tskIterator\tunicode.runes\titerator \(string\): TRune +> idetools --track:idetools_api.nim,12,15 --def +def\tskTemplate\tsequtils.toSeq\tproc \(expr\): expr +> idetools --track:idetools_api.nim,15,7 --def + +# ProcRun mode will fail the next line, because the type is returned empty. +def\tskConst\tidetools_api.SOME_SEQUENCE\tseq\[int\]\t +> idetools --track:idetools_api.nim,15,23 --def +def\tskProc\tsystem.@\tproc \(array\[IDX, T\]\): seq\[T\]\{.noSideEffect.\} +> idetools --track:idetools_api.nim,17,3 --def + +# ProcRun mode will fail the next line, because the type is returned empty. +def\tskType\tidetools_api.bad_string\tbad_string\t +> idetools --track:idetools_api.nim,11,24 --def +def\tskParam\tidetools_api.test_iterators.filename\tstring +> idetools --track:idetools_api.nim,6,5 --def +def\tskVar\tidetools_api.test_enums.o\tTFile +> idetools --track:idetools_api.nim,12,34 --def +def\tskLet\tidetools_api.test_iterators.input\tTaintedString +> idetools --track:idetools_api.nim,13,35 --def +def\tskForVar\tidetools_api.test_iterators.letter\tTRune +> idetools --track:idetools_api.nim,23,3 --def +def\tskResult\tidetools_api.adder.result\tint +> idetools --track:idetools_api.nim,19,6 --def + +# ProcRun mode will fail the next line, because the type is returned empty. +def\tskField\tidetools_api.TPerson.name\tbad_string\t diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index d6f4a8bd6..e1270f08a 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -21,6 +21,9 @@ import osproc, streams, os, strutils, re ## modes, you can prefix a line with the mode and the line will be processed ## only in that mode. ## +## The rest of the line is treated as a regular expression, so be careful +## escaping metacharacters like parenthesis. +## ## You can optionally pass parameters at the command line to modify the ## behaviour of the test suite. By default only tests which fail will be echoed ## to stdout. If you want to see all the output pass the word "verbose" as a @@ -142,7 +145,8 @@ proc doScenario(script: string, output: PStream, mode: TRunMode): bool = pattern = line.substr(1).strip expectMatch = false - var actualMatch = s.lastOutput.find(re(pattern)) != -1 + let actualMatch = + s.lastOutput.find(re(pattern, flags = {reStudy})) != -1 if expectMatch == actualMatch: output.writeln "SUCCESS ", line From 0d333fdcb446a89e079d0722ef140c1d7c3bbf39 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 7 Jun 2013 21:38:07 +0200 Subject: [PATCH 08/13] Adds idetools test case. Refs #416. --- .gitignore | 1 + tests/caas/issue_416.nim | 17 +++++++++++++++++ tests/caas/issue_416.txt | 14 ++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/caas/issue_416.nim create mode 100644 tests/caas/issue_416.txt diff --git a/.gitignore b/.gitignore index 025c4ca35..b57f95571 100644 --- a/.gitignore +++ b/.gitignore @@ -169,6 +169,7 @@ examples/cross_calculator/android/tags /testresults.json /tests/caas/idetools_api /tests/caas/imported +/tests/caas/issue_416 /tests/caas/main /tests/caasdriver /tools/nimgrep diff --git a/tests/caas/issue_416.nim b/tests/caas/issue_416.nim new file mode 100644 index 000000000..d52f611d6 --- /dev/null +++ b/tests/caas/issue_416.nim @@ -0,0 +1,17 @@ +import unicode, sequtils + +proc test() = + let input = readFile("weird.nim") + for letter in runes(string(input)): + echo int(letter) + +when 1 > 0: + proc failtest() = + let + input = readFile("weird.nim") + letters = toSeq(runes(string(input))) + for letter in letters: + echo int(letter) + +when isMainModule: + test() diff --git a/tests/caas/issue_416.txt b/tests/caas/issue_416.txt new file mode 100644 index 000000000..7f81c2b2c --- /dev/null +++ b/tests/caas/issue_416.txt @@ -0,0 +1,14 @@ +issue_416.nim +> c +SuccessX +> idetools --track:issue_416.nim,12,28 --def +def\tskType\tsystem.string\tstring +> idetools --track:issue_416.nim,12,35 --def +def\tskLet\tissue_416.failtest.input\tTaintedString + +# The following fail because they seem shifted one colum to the right. +> idetools --track:issue_416.nim,12,16 --def +def\tskTemplate\tsequtils.toSeq\tproc \(expr\): expr +> idetools --track:issue_416.nim,12,22 --def +def\tskIterator\tunicode.runes\titerator \(string\): TRune + From 27ebd3ce2e411458d2f06b633285b1ba0a9b096d Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 7 Jun 2013 21:43:27 +0200 Subject: [PATCH 09/13] Adds comments to output, can help debug failure logs. --- tests/caasdriver.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index e1270f08a..2de046a11 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -134,6 +134,7 @@ proc doScenario(script: string, output: PStream, mode: TRunMode): bool = if line.strip.len == 0: continue if line.startsWith("#"): + output.writeln line continue elif line.startsWith(">"): s.doCommand(line.substr(1).strip) From b0e71709657d9c2d8b00b762a710b230a2cc8149 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 7 Jun 2013 22:06:04 +0200 Subject: [PATCH 10/13] Adds idetools testcase. Refs #416. --- .gitignore | 1 + tests/caas/issue_452.nim | 8 ++++++++ tests/caas/issue_452.txt | 11 +++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/caas/issue_452.nim create mode 100644 tests/caas/issue_452.txt diff --git a/.gitignore b/.gitignore index b57f95571..f05ca2016 100644 --- a/.gitignore +++ b/.gitignore @@ -170,6 +170,7 @@ examples/cross_calculator/android/tags /tests/caas/idetools_api /tests/caas/imported /tests/caas/issue_416 +/tests/caas/issue_452 /tests/caas/main /tests/caasdriver /tools/nimgrep diff --git a/tests/caas/issue_452.nim b/tests/caas/issue_452.nim new file mode 100644 index 000000000..46cff6241 --- /dev/null +++ b/tests/caas/issue_452.nim @@ -0,0 +1,8 @@ +const + VERSION_STR1* = "0.5.0" ## Idetools shifts this one column. + VERSION_STR2 = "0.5.0" ## This one is ok. + VERSION_STR3* = "0.5.0" ## Bad. + VERSION_STR4 = "0.5.0" ## Ok. + +proc forward1*(): string = result = "" +proc forward2(): string = result = "" diff --git a/tests/caas/issue_452.txt b/tests/caas/issue_452.txt new file mode 100644 index 000000000..5db60516c --- /dev/null +++ b/tests/caas/issue_452.txt @@ -0,0 +1,11 @@ +issue_452.nim +> c +SuccessX +> idetools --track:issue_452.nim,2,2 --def +def\tskConst\tissue_452.VERSION_STR1\tstring +> idetools --track:issue_452.nim,3,2 --def +def\tskConst\tissue_452.VERSION_STR2\tstring +> idetools --track:issue_452.nim,7,5 --def +def\tskProc\tissue_452.forward1\tproc \(\): string\t +> idetools --track:issue_452.nim,8,5 --def +def\tskProc\tissue_452.forward2\tproc \(\): string\t From 1bbabd1e81ab8dfcb15287594c4479141b8c21a0 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Sat, 8 Jun 2013 20:47:26 +0200 Subject: [PATCH 11/13] Removes CaasRun prefix from suggest-compile.txt test. The --trackDirty switch should work the same for ProcRun, so it's a bug that it doesn't dump the same suggestion information as in server mode. --- tests/caas/suggest-compile.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/caas/suggest-compile.txt b/tests/caas/suggest-compile.txt index 897d14f52..a74d4dc21 100644 --- a/tests/caas/suggest-compile.txt +++ b/tests/caas/suggest-compile.txt @@ -1,8 +1,8 @@ main.nim # Ugh, undocumented trackDirty, how is it supposed to work? Fails in proc mode. > idetools --trackDirty:main_dirty.nim,main.nim,12,7 --suggest -CaasRun skField\tx -CaasRun skField\ty +skField\tx +skField\ty > c SuccessX From d8f349f2019a33fd1b284d863736b5301301ad6d Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Mon, 10 Jun 2013 22:01:00 +0200 Subject: [PATCH 12/13] Fixes caasdriver for --taintMode:on compilation. --- tests/caasdriver.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index 2de046a11..87360ed34 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -171,7 +171,7 @@ when isMainModule: verbose = false for i in 0..ParamCount() - 1: - let param = paramStr(i + 1) + let param = string(paramStr(i + 1)) case param of "verbose": verbose = true else: filter = param From b7a4a9a6ce0d0a0a844875af946124b45fadb01a Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Mon, 10 Jun 2013 22:06:38 +0200 Subject: [PATCH 13/13] Fixes usage of public API caasTestsRunner in tester. --- tests/tester.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/tester.nim b/tests/tester.nim index 8c8e31fe8..e10b89761 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -365,8 +365,9 @@ proc outputJSON(reject, compile, run: TResults) = writeFile(jsonFile, s) proc runCaasTests(r: var TResults) = - for test, output, status in caasTestsRunner(): - r.addResult(test, "", output, if status: reSuccess else: reOutputsDiffer) + for test, output, status, mode in caasTestsRunner(): + r.addResult(test, "", output & "-> " & $mode, + if status: reSuccess else: reOutputsDiffer) proc main() = os.putenv "NIMTEST_NO_COLOR", "1"