From c7a4412f8ae0edef821fa5d7e64cb200eb4a9830 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Mon, 10 Jun 2013 19:14:36 +0200 Subject: [PATCH 1/7] Adds skMethod example to idetools api test. --- tests/caas/idetools_api.nim | 20 ++++++++++++++++++++ tests/caas/idetools_api.txt | 3 +++ 2 files changed, 23 insertions(+) diff --git a/tests/caas/idetools_api.nim b/tests/caas/idetools_api.nim index 930d264292..6327f4c227 100644 --- a/tests/caas/idetools_api.nim +++ b/tests/caas/idetools_api.nim @@ -21,3 +21,23 @@ type proc adder(a, b: int): int = result = a + b + +type + PExpr = ref object of TObject ## abstract base class for an expression + PLiteral = ref object of PExpr + x: int + PPlusExpr = ref object of PExpr + a, b: PExpr + +# watch out: 'eval' relies on dynamic binding +method eval(e: PExpr): int = + # override this base method + quit "to override!" + +method eval(e: PLiteral): int = e.x +method eval(e: PPlusExpr): int = eval(e.a) + eval(e.b) + +proc newLit(x: int): PLiteral = PLiteral(x: x) +proc newPlus(a, b: PExpr): PPlusExpr = PPlusExpr(a: a, b: b) + +echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) diff --git a/tests/caas/idetools_api.txt b/tests/caas/idetools_api.txt index eaa91cd5f6..f2b513481d 100644 --- a/tests/caas/idetools_api.txt +++ b/tests/caas/idetools_api.txt @@ -39,3 +39,6 @@ def\tskResult\tidetools_api.adder.result\tint # ProcRun mode will fail the next line, because the type is returned empty. def\tskField\tidetools_api.TPerson.name\tbad_string\t + +> idetools --track:idetools_api.nim,43,7 --def +def\tskMethod\tidetools_api.eval\tproc \(PPlusExpr\): int\t From b0ba4caf64a51af3b345fc22fe1595f34b93e8ed Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Mon, 10 Jun 2013 23:06:49 +0200 Subject: [PATCH 2/7] Renames test cases to be more human friendly. --- .gitignore | 4 ++-- tests/caas/issue_416.txt | 14 -------------- ...{issue_416.nim => issue_416_template_shift.nim} | 0 tests/caas/issue_416_template_shift.txt | 14 ++++++++++++++ tests/caas/issue_452.txt | 11 ----------- .../{issue_452.nim => issue_452_export_shift.nim} | 0 tests/caas/issue_452_export_shift.txt | 11 +++++++++++ 7 files changed, 27 insertions(+), 27 deletions(-) delete mode 100644 tests/caas/issue_416.txt rename tests/caas/{issue_416.nim => issue_416_template_shift.nim} (100%) create mode 100644 tests/caas/issue_416_template_shift.txt delete mode 100644 tests/caas/issue_452.txt rename tests/caas/{issue_452.nim => issue_452_export_shift.nim} (100%) create mode 100644 tests/caas/issue_452_export_shift.txt diff --git a/.gitignore b/.gitignore index f05ca2016d..dc63ebb4c9 100644 --- a/.gitignore +++ b/.gitignore @@ -169,8 +169,8 @@ examples/cross_calculator/android/tags /testresults.json /tests/caas/idetools_api /tests/caas/imported -/tests/caas/issue_416 -/tests/caas/issue_452 +/tests/caas/issue_416_template_shift +/tests/caas/issue_452_export_shift /tests/caas/main /tests/caasdriver /tools/nimgrep diff --git a/tests/caas/issue_416.txt b/tests/caas/issue_416.txt deleted file mode 100644 index 7f81c2b2c5..0000000000 --- a/tests/caas/issue_416.txt +++ /dev/null @@ -1,14 +0,0 @@ -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 - diff --git a/tests/caas/issue_416.nim b/tests/caas/issue_416_template_shift.nim similarity index 100% rename from tests/caas/issue_416.nim rename to tests/caas/issue_416_template_shift.nim diff --git a/tests/caas/issue_416_template_shift.txt b/tests/caas/issue_416_template_shift.txt new file mode 100644 index 0000000000..3a494bd57f --- /dev/null +++ b/tests/caas/issue_416_template_shift.txt @@ -0,0 +1,14 @@ +issue_416_template_shift.nim +> c +SuccessX +> idetools --track:issue_416_template_shift.nim,12,28 --def +def\tskType\tsystem.string\tstring +> idetools --track:issue_416_template_shift.nim,12,35 --def +def\tskLet\tissue_416_template_shift.failtest.input\tTaintedString + +# The following fail because they seem shifted one colum to the right. +> idetools --track:issue_416_template_shift.nim,12,16 --def +def\tskTemplate\tsequtils.toSeq\tproc \(expr\): expr +> idetools --track:issue_416_template_shift.nim,12,22 --def +def\tskIterator\tunicode.runes\titerator \(string\): TRune + diff --git a/tests/caas/issue_452.txt b/tests/caas/issue_452.txt deleted file mode 100644 index 5db60516cb..0000000000 --- a/tests/caas/issue_452.txt +++ /dev/null @@ -1,11 +0,0 @@ -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 diff --git a/tests/caas/issue_452.nim b/tests/caas/issue_452_export_shift.nim similarity index 100% rename from tests/caas/issue_452.nim rename to tests/caas/issue_452_export_shift.nim diff --git a/tests/caas/issue_452_export_shift.txt b/tests/caas/issue_452_export_shift.txt new file mode 100644 index 0000000000..02ba053f1c --- /dev/null +++ b/tests/caas/issue_452_export_shift.txt @@ -0,0 +1,11 @@ +issue_452_export_shift.nim +> c +SuccessX +> idetools --track:issue_452_export_shift.nim,2,2 --def +def\tskConst\tissue_452_export_shift.VERSION_STR1\tstring +> idetools --track:issue_452_export_shift.nim,3,2 --def +def\tskConst\tissue_452_export_shift.VERSION_STR2\tstring +> idetools --track:issue_452_export_shift.nim,7,5 --def +def\tskProc\tissue_452_export_shift.forward1\tproc \(\): string\t +> idetools --track:issue_452_export_shift.nim,8,5 --def +def\tskProc\tissue_452_export_shift.forward2\tproc \(\): string\t From fe18117fb28df5ffee28e2e4d720452ddfc89fff Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Mon, 10 Jun 2013 23:07:36 +0200 Subject: [PATCH 3/7] Adds idetools testcase for dynamic dispatch. Refs #477. --- .gitignore | 1 + tests/caas/issue_477_dynamic_dispatch.nim | 19 +++++++++++++++++++ tests/caas/issue_477_dynamic_dispatch.txt | 5 +++++ 3 files changed, 25 insertions(+) create mode 100644 tests/caas/issue_477_dynamic_dispatch.nim create mode 100644 tests/caas/issue_477_dynamic_dispatch.txt diff --git a/.gitignore b/.gitignore index dc63ebb4c9..eb2e27e9e8 100644 --- a/.gitignore +++ b/.gitignore @@ -171,6 +171,7 @@ examples/cross_calculator/android/tags /tests/caas/imported /tests/caas/issue_416_template_shift /tests/caas/issue_452_export_shift +/tests/caas/issue_477_dynamic_dispatch /tests/caas/main /tests/caasdriver /tools/nimgrep diff --git a/tests/caas/issue_477_dynamic_dispatch.nim b/tests/caas/issue_477_dynamic_dispatch.nim new file mode 100644 index 0000000000..6e6b21ef0f --- /dev/null +++ b/tests/caas/issue_477_dynamic_dispatch.nim @@ -0,0 +1,19 @@ +type + TThing = object of TObject + TUnit = object of TThing + x: int + +method collide(a, b: TThing) {.inline.} = + quit "to override!" + +method collide(a: TThing, b: TUnit) {.inline.} = + echo "collide1" + +method collide(a: TUnit, b: TThing) {.inline.} = + echo "collide2" + +var + a, b: TUnit + +when isMainModule: + collide(a, b) # output: 2 diff --git a/tests/caas/issue_477_dynamic_dispatch.txt b/tests/caas/issue_477_dynamic_dispatch.txt new file mode 100644 index 0000000000..068a9d022b --- /dev/null +++ b/tests/caas/issue_477_dynamic_dispatch.txt @@ -0,0 +1,5 @@ +issue_477_dynamic_dispatch.nim +> c --run +SuccessX +> idetools --track:issue_477_dynamic_dispatch.nim,19,5 --def +def\tskMethod\tissue_477_dynamic_dispatch.collide\tproc \(TUnit, TThing\)\{.inline.\} From 41c51a11d3a9edcc4e5fbc2d3bc3e0e0b357f6ff Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Tue, 11 Jun 2013 16:49:04 +0200 Subject: [PATCH 4/7] Adds $TESTNIM and $MODULE as variables to test cases. --- tests/caas/compile-suggest.txt | 2 +- tests/caas/compile-then-def.txt | 4 +- tests/caas/def-def-compile.txt | 4 +- tests/caas/def-then-compile.txt | 2 +- tests/caas/idetools_api.txt | 52 ++++++++++++------------- tests/caas/issue_416_template_shift.txt | 10 ++--- tests/caas/issue_452_export_shift.txt | 16 ++++---- tests/caas/suggest-compile.txt | 2 +- tests/caasdriver.nim | 32 ++++++++++----- 9 files changed, 69 insertions(+), 55 deletions(-) diff --git a/tests/caas/compile-suggest.txt b/tests/caas/compile-suggest.txt index f90fc5aa1b..55d3f87332 100644 --- a/tests/caas/compile-suggest.txt +++ b/tests/caas/compile-suggest.txt @@ -2,7 +2,7 @@ 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 +> idetools --trackDirty:main_dirty.nim,$TESTNIM,12,7 --suggest CaasRun skField\tx CaasRun skField\ty diff --git a/tests/caas/compile-then-def.txt b/tests/caas/compile-then-def.txt index 839ca15327..66ff293469 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 +> idetools --track:$TESTNIM,5,18 --def strutils.toUpper ! SuccessX -> idetools --track:main.nim,5,18 --def +> idetools --track:$TESTNIM,5,18 --def strutils.toUpper ! SuccessX diff --git a/tests/caas/def-def-compile.txt b/tests/caas/def-def-compile.txt index 05ea5a1aa5..12ba7e993c 100644 --- a/tests/caas/def-def-compile.txt +++ b/tests/caas/def-def-compile.txt @@ -1,8 +1,8 @@ main.nim -> idetools --track:main.nim,5,18 --def +> idetools --track:$TESTNIM,5,18 --def strutils.toUpper ! SuccessX -> idetools --track:main.nim,5,18 --def +> idetools --track:$TESTNIM,5,18 --def strutils.toUpper ! SuccessX > c diff --git a/tests/caas/def-then-compile.txt b/tests/caas/def-then-compile.txt index 7e755cff26..e44af7f63e 100644 --- a/tests/caas/def-then-compile.txt +++ b/tests/caas/def-then-compile.txt @@ -1,5 +1,5 @@ main.nim -> idetools --track:main.nim,5,18 --def +> idetools --track:$TESTNIM,5,18 --def strutils.toUpper ! SuccessX > c diff --git a/tests/caas/idetools_api.txt b/tests/caas/idetools_api.txt index f2b513481d..bc1dc6a5f4 100644 --- a/tests/caas/idetools_api.txt +++ b/tests/caas/idetools_api.txt @@ -1,44 +1,44 @@ idetools_api.nim > c SuccessX -> idetools --track:idetools_api.nim,4,11 --def +> idetools --track:$TESTNIM,4,11 --def def\tskType\tsystem.TFile\tTFile -> idetools --track:idetools_api.nim,5,7 --def +> idetools --track:$TESTNIM,5,7 --def def\tskProc\tsystem.Open\tproc \(var TFile, string, TFileMode, int\): bool -> idetools --track:idetools_api.nim,5,21 --def +> idetools --track:$TESTNIM,5,21 --def def\tskProc\tsystem.\&\tproc \(string, string\): string\{.noSideEffect.\} -> idetools --track:idetools_api.nim,5,38 --def +> idetools --track:$TESTNIM,5,38 --def def\tskEnumField\tsystem.TFileMode.fmWrite\tTFileMode -> idetools --track:idetools_api.nim,7,6 --def +> idetools --track:$TESTNIM,7,6 --def def\tskProc\tsystem.Close\tproc \(TFile\) -> idetools --track:idetools_api.nim,12,23 --def +> idetools --track:$TESTNIM,12,23 --def def\tskIterator\tunicode.runes\titerator \(string\): TRune -> idetools --track:idetools_api.nim,12,15 --def +> idetools --track:$TESTNIM,12,15 --def def\tskTemplate\tsequtils.toSeq\tproc \(expr\): expr -> idetools --track:idetools_api.nim,15,7 --def +> idetools --track:$TESTNIM,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\tskConst\t$MODULE.SOME_SEQUENCE\tseq\[int\]\t +> idetools --track:$TESTNIM,15,23 --def def\tskProc\tsystem.@\tproc \(array\[IDX, T\]\): seq\[T\]\{.noSideEffect.\} -> idetools --track:idetools_api.nim,17,3 --def +> idetools --track:$TESTNIM,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 +def\tskType\t$MODULE.bad_string\tbad_string\t +> idetools --track:$TESTNIM,11,24 --def +def\tskParam\t$MODULE.test_iterators.filename\tstring +> idetools --track:$TESTNIM,6,5 --def +def\tskVar\t$MODULE.test_enums.o\tTFile +> idetools --track:$TESTNIM,12,34 --def +def\tskLet\t$MODULE.test_iterators.input\tTaintedString +> idetools --track:$TESTNIM,13,35 --def +def\tskForVar\t$MODULE.test_iterators.letter\tTRune +> idetools --track:$TESTNIM,23,3 --def +def\tskResult\t$MODULE.adder.result\tint +> idetools --track:$TESTNIM,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 +def\tskField\t$MODULE.TPerson.name\tbad_string\t -> idetools --track:idetools_api.nim,43,7 --def -def\tskMethod\tidetools_api.eval\tproc \(PPlusExpr\): int\t +> idetools --track:$TESTNIM,43,7 --def +def\tskMethod\t$MODULE.eval\tproc \(PPlusExpr\): int\t diff --git a/tests/caas/issue_416_template_shift.txt b/tests/caas/issue_416_template_shift.txt index 3a494bd57f..951a21612a 100644 --- a/tests/caas/issue_416_template_shift.txt +++ b/tests/caas/issue_416_template_shift.txt @@ -1,14 +1,14 @@ issue_416_template_shift.nim > c SuccessX -> idetools --track:issue_416_template_shift.nim,12,28 --def +> idetools --track:$TESTNIM,12,28 --def def\tskType\tsystem.string\tstring -> idetools --track:issue_416_template_shift.nim,12,35 --def -def\tskLet\tissue_416_template_shift.failtest.input\tTaintedString +> idetools --track:$TESTNIM,12,35 --def +def\tskLet\t$MODULE.failtest.input\tTaintedString # The following fail because they seem shifted one colum to the right. -> idetools --track:issue_416_template_shift.nim,12,16 --def +> idetools --track:$TESTNIM,12,16 --def def\tskTemplate\tsequtils.toSeq\tproc \(expr\): expr -> idetools --track:issue_416_template_shift.nim,12,22 --def +> idetools --track:$TESTNIM,12,22 --def def\tskIterator\tunicode.runes\titerator \(string\): TRune diff --git a/tests/caas/issue_452_export_shift.txt b/tests/caas/issue_452_export_shift.txt index 02ba053f1c..56ba0b74f7 100644 --- a/tests/caas/issue_452_export_shift.txt +++ b/tests/caas/issue_452_export_shift.txt @@ -1,11 +1,11 @@ issue_452_export_shift.nim > c SuccessX -> idetools --track:issue_452_export_shift.nim,2,2 --def -def\tskConst\tissue_452_export_shift.VERSION_STR1\tstring -> idetools --track:issue_452_export_shift.nim,3,2 --def -def\tskConst\tissue_452_export_shift.VERSION_STR2\tstring -> idetools --track:issue_452_export_shift.nim,7,5 --def -def\tskProc\tissue_452_export_shift.forward1\tproc \(\): string\t -> idetools --track:issue_452_export_shift.nim,8,5 --def -def\tskProc\tissue_452_export_shift.forward2\tproc \(\): string\t +> idetools --track:$TESTNIM,2,2 --def +def\tskConst\t$MODULE.VERSION_STR1\tstring +> idetools --track:$TESTNIM,3,2 --def +def\tskConst\t$MODULE.VERSION_STR2\tstring +> idetools --track:$TESTNIM,7,5 --def +def\tskProc\t$MODULE.forward1\tproc \(\): string\t +> idetools --track:$TESTNIM,8,5 --def +def\tskProc\t$MODULE.forward2\tproc \(\): string\t diff --git a/tests/caas/suggest-compile.txt b/tests/caas/suggest-compile.txt index a74d4dc219..45e3915486 100644 --- a/tests/caas/suggest-compile.txt +++ b/tests/caas/suggest-compile.txt @@ -1,6 +1,6 @@ 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 +> idetools --trackDirty:main_dirty.nim,$TESTNIM,12,7 --suggest skField\tx skField\ty > c diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index 87360ed340..d4838dc399 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -22,7 +22,12 @@ import osproc, streams, os, strutils, re ## only in that mode. ## ## The rest of the line is treated as a regular expression, so be careful -## escaping metacharacters like parenthesis. +## escaping metacharacters like parenthesis. Before the line is processed as a +## regular expression, some basic variables are searched for and replaced in +## the tests. The variables which will be replaced are: +## +## - $TESTNIM: filename specified in the first line of the script. +## - $MODULE: like $TESTNIM but without extension, useful for expected output. ## ## 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 @@ -46,26 +51,35 @@ type 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 '>'. + filename: string # Appended to each command starting with '>'. Also a var. + modname: string # Like filename but without extension. -const modes = [CaasRun, ProcRun] +const + modes = [CaasRun, ProcRun] + filenameReplaceVar = "$TESTNIM" + moduleReplaceVar = "$MODULE" var TesterDir = getAppDir() NimrodBin = TesterDir / "../bin/nimrod" +proc replaceVars(session: var TNimrodSession, text: string): string = + result = text.replace(filenameReplaceVar, session.filename) + result = result.replace(moduleReplaceVar, session.modname) + proc startNimrodSession(project: string, mode: TRunMode): TNimrodSession = - let (dir, name) = project.SplitPath + let (dir, name, ext) = project.splitFile result.mode = mode result.lastOutput = "" - result.filename = name + result.filename = name & ext + result.modname = name if mode == CaasRun: result.nim = startProcess(NimrodBin, workingDir = dir, args = ["serve", "--server.type:stdin", name]) proc doCaasCommand(session: var TNimrodSession, command: string): string = assert session.mode == CaasRun - session.nim.inputStream.write(command & "\n") + session.nim.inputStream.write(session.replaceVars(command) & "\n") session.nim.inputStream.flush result = "" @@ -83,7 +97,7 @@ 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) + process = startProcess(NimrodBin, args = session.replaceVars(command).split) stream = outputStream(process) line = TaintedString("") @@ -141,9 +155,9 @@ proc doScenario(script: string, output: PStream, mode: TRunMode): bool = output.writeln line, "\n", s.lastOutput else: var expectMatch = true - var pattern = line + var pattern = s.replaceVars(line) if line.startsWith("!"): - pattern = line.substr(1).strip + pattern = pattern.substr(1).strip expectMatch = false let actualMatch = From 10c441deed6b9ee176f59ef3ee015f99a54c4f46 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Tue, 11 Jun 2013 16:15:14 +0200 Subject: [PATCH 5/7] Enables trackDirty query for idetools proc mode. --- tests/caas/compile-suggest.txt | 5 ++--- tests/caas/suggest-compile.txt | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/caas/compile-suggest.txt b/tests/caas/compile-suggest.txt index 55d3f87332..6170603470 100644 --- a/tests/caas/compile-suggest.txt +++ b/tests/caas/compile-suggest.txt @@ -1,8 +1,7 @@ main.nim > c SuccessX -# Ugh, undocumented trackDirty, how is it supposed to work? Fails in proc mode. > idetools --trackDirty:main_dirty.nim,$TESTNIM,12,7 --suggest -CaasRun skField\tx -CaasRun skField\ty +skField\tx +skField\ty diff --git a/tests/caas/suggest-compile.txt b/tests/caas/suggest-compile.txt index 45e3915486..ac61872361 100644 --- a/tests/caas/suggest-compile.txt +++ b/tests/caas/suggest-compile.txt @@ -1,5 +1,4 @@ main.nim -# Ugh, undocumented trackDirty, how is it supposed to work? Fails in proc mode. > idetools --trackDirty:main_dirty.nim,$TESTNIM,12,7 --suggest skField\tx skField\ty From 28041461b7366433c22acc8257c9a5e8a0bd3b40 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Tue, 11 Jun 2013 17:23:48 +0200 Subject: [PATCH 6/7] Adds symbol proc run mode as suggested by Zahary. To avoid collision each test case uses a different nimcache directory based on the input test filename. --- .gitignore | 2 ++ tests/caasdriver.nim | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index eb2e27e9e8..a52319eff0 100644 --- a/.gitignore +++ b/.gitignore @@ -167,6 +167,7 @@ examples/cross_calculator/android/tags /run.json /testresults.html /testresults.json +/tests/caas/SymbolProcRun.*/ /tests/caas/idetools_api /tests/caas/imported /tests/caas/issue_416_template_shift @@ -175,3 +176,4 @@ examples/cross_calculator/android/tags /tests/caas/main /tests/caasdriver /tools/nimgrep +no changes added to commit (use "git add" and/or "git commit -a") diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index d4838dc399..619ce9b6a8 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -45,7 +45,7 @@ import osproc, streams, os, strutils, re type TRunMode = enum - ProcRun, CaasRun + ProcRun, CaasRun, SymbolProcRun TNimrodSession* = object nim: PProcess # Holds the open process for CaasRun sessions, nil otherwise. @@ -53,9 +53,10 @@ type lastOutput: string # Preserves the last output, needed for ProcRun mode. filename: string # Appended to each command starting with '>'. Also a var. modname: string # Like filename but without extension. + nimcache: string # Input script based name for the nimcache dir. const - modes = [CaasRun, ProcRun] + modes = [CaasRun, ProcRun, SymbolProcRun] filenameReplaceVar = "$TESTNIM" moduleReplaceVar = "$MODULE" @@ -67,12 +68,14 @@ proc replaceVars(session: var TNimrodSession, text: string): string = result = text.replace(filenameReplaceVar, session.filename) result = result.replace(moduleReplaceVar, session.modname) -proc startNimrodSession(project: string, mode: TRunMode): TNimrodSession = +proc startNimrodSession(project, script: string, mode: TRunMode): + TNimrodSession = let (dir, name, ext) = project.splitFile result.mode = mode result.lastOutput = "" result.filename = name & ext result.modname = name + result.nimcache = "SymbolProcRun." & script.splitFile.name if mode == CaasRun: result.nim = startProcess(NimrodBin, workingDir = dir, args = ["serve", "--server.type:stdin", name]) @@ -94,7 +97,7 @@ proc doCaasCommand(session: var TNimrodSession, command: string): string = break proc doProcCommand(session: var TNimrodSession, command: string): string = - assert session.mode == ProcRun + assert session.mode == ProcRun or session.mode == SymbolProcRun except: result = "FAILED TO EXECUTE: " & command & "\n" & result var process = startProcess(NimrodBin, args = session.replaceVars(command).split) @@ -113,6 +116,13 @@ proc doCommand(session: var TNimrodSession, command: string) = session.lastOutput = doCaasCommand(session, command & " " & session.filename) else: + var command = command + # For symbol runs we prepend the necessary parameters to avoid clobbering + # the normal nimcache. + if session.mode == SymbolProcRun: + command = "--symbolFiles:on --nimcache:" & session.nimcache & + " " & command + echo "Running ", command session.lastOutput = doProcCommand(session, command & " " & session.filename) @@ -128,7 +138,7 @@ proc doScenario(script: string, output: PStream, mode: TRunMode): bool = if f.readLine(project): var - s = startNimrodSession(script.parentDir / project.string, mode) + s = startNimrodSession(script.parentDir / project.string, script, mode) tline = TaintedString("") ln = 1 From b4ea608b65ea7637f29cd65827ab46e44bc08017 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Tue, 11 Jun 2013 22:34:09 +0200 Subject: [PATCH 7/7] Removes the nimcache symbol directory for each run. --- tests/caasdriver.nim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index 619ce9b6a8..cd27839c78 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -75,7 +75,13 @@ proc startNimrodSession(project, script: string, mode: TRunMode): result.lastOutput = "" result.filename = name & ext result.modname = name - result.nimcache = "SymbolProcRun." & script.splitFile.name + + let (nimcacheDir, nimcacheName, nimcacheExt) = script.splitFile + result.nimcache = "SymbolProcRun." & nimcacheName + + if mode == SymbolProcRun: + removeDir(nimcacheDir / result.nimcache) + if mode == CaasRun: result.nim = startProcess(NimrodBin, workingDir = dir, args = ["serve", "--server.type:stdin", name]) @@ -122,7 +128,6 @@ proc doCommand(session: var TNimrodSession, command: string) = if session.mode == SymbolProcRun: command = "--symbolFiles:on --nimcache:" & session.nimcache & " " & command - echo "Running ", command session.lastOutput = doProcCommand(session, command & " " & session.filename)