diff options
-rw-r--r-- | tests/caas/basic-recompile.txt | 5 | ||||
-rw-r--r-- | tests/caas/compile-suggest.txt | 5 | ||||
-rw-r--r-- | tests/caas/suggest-compile.txt | 5 | ||||
-rw-r--r-- | 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) |