diff options
author | Araq <rumpf_a@web.de> | 2013-07-07 16:05:17 -0700 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-07-07 16:05:17 -0700 |
commit | 6feedc9cff8f2c6916e6b4eedfa68088978fe059 (patch) | |
tree | 9ee2b1aba15f8577d934d4588ec1684f702b962a /tests | |
parent | bd1c878af46cc9fc8292ceff437fb261c796572f (diff) | |
parent | 2f0f1d0a3fcd462a5ff3273a6d414c6e8944d8ac (diff) | |
download | Nim-6feedc9cff8f2c6916e6b4eedfa68088978fe059.tar.gz |
Merge pull request #515 from gradha/pr_idetools_improvements
Idetools improvements
Diffstat (limited to 'tests')
-rw-r--r-- | tests/caas/idetools_api.nim | 43 | ||||
-rw-r--r-- | tests/caas/idetools_api.txt | 15 | ||||
-rw-r--r-- | tests/caas/suggest-compile.txt | 6 | ||||
-rw-r--r-- | tests/caas/suggest-invalid-source.txt | 26 | ||||
-rw-r--r-- | tests/caasdriver.nim | 42 |
5 files changed, 92 insertions, 40 deletions
diff --git a/tests/caas/idetools_api.nim b/tests/caas/idetools_api.nim index 6327f4c22..8f1061e27 100644 --- a/tests/caas/idetools_api.nim +++ b/tests/caas/idetools_api.nim @@ -1,4 +1,4 @@ -import unicode, sequtils +import unicode, sequtils, macros, re proc test_enums() = var o: Tfile @@ -41,3 +41,44 @@ 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))) + +proc findVowelPosition(text: string) = + var found = -1 + block loops: + for i, letter in pairs(text): + for j in ['a', 'e', 'i', 'o', 'u']: + if letter == j: + found = i + break loops # leave both for-loops + echo found + +findVowelPosition("Zerg") # should output 1, position of vowel. + +macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} = + ## Expect docstrings + let exp = callsite() + template expectBody(errorTypes, lineInfoLit: expr, + body: stmt): PNimrodNode {.dirty.} = + try: + body + assert false + except errorTypes: + nil + + var body = exp[exp.len - 1] + + var errorTypes = newNimNode(nnkBracket) + for i in countup(1, exp.len - 2): + errorTypes.add(exp[i]) + + result = getAst(expectBody(errorTypes, exp.lineinfo, body)) + +proc err = + raise newException(EArithmetic, "some exception") + +proc testMacro() = + expect(EArithmetic): + err() + +testMacro() +let notAModule = re"(\w+)=(.*)" diff --git a/tests/caas/idetools_api.txt b/tests/caas/idetools_api.txt index c4c22399e..035590dc3 100644 --- a/tests/caas/idetools_api.txt +++ b/tests/caas/idetools_api.txt @@ -42,3 +42,18 @@ def\tskField\t$MODULE.TPerson.name\tbad_string\t > idetools --track:$TESTNIM,43,7 --def $SILENT def\tskMethod\t$MODULE.eval\tproc \(PPlusExpr\): int\t + +> idetools --track:$TESTNIM,47,8 --def $SILENT +def\tskLabel\t$MODULE.findVowelPosition.loops\t\t +# For some reason the use of the label with break displaces its position. +> idetools --track:$TESTNIM,52,16 --def $SILENT +def\tskLabel\t$MODULE.findVowelPosition.loops\t\t + +# Displaced macro usage by one character. +> idetools --track:$TESTNIM,80,2 --def $SILENT +def\tskMacro\t$MODULE.expect\tproc \(varargs\[expr\], stmt\): stmt\t + +# The syntax for extended raw string literals should not be returned as module +# but as the proc re() inside the re module. +> idetools --track:$TESTNIM,84,17 --def $SILENT +!def\tskModule diff --git a/tests/caas/suggest-compile.txt b/tests/caas/suggest-compile.txt index 66ae795ed..a322908ac 100644 --- a/tests/caas/suggest-compile.txt +++ b/tests/caas/suggest-compile.txt @@ -1,7 +1,13 @@ main.nim +# This example shows how the suggest feature can be used on a partial file +# using the --trackDirty switch. > idetools --trackDirty:main_dirty.nim,$TESTNIM,12,7 --suggest $SILENT skField\tx skField\ty +# Repeating the query in caas should work always and retrieve same output. +CaasRun > idetools --trackDirty:main_dirty.nim,$TESTNIM,12,7 --suggest $SILENT +CaasRun skField\tx +CaasRun skField\ty > c --verbosity:0 --hints:on SuccessX diff --git a/tests/caas/suggest-invalid-source.txt b/tests/caas/suggest-invalid-source.txt new file mode 100644 index 000000000..7f8f1213d --- /dev/null +++ b/tests/caas/suggest-invalid-source.txt @@ -0,0 +1,26 @@ +main_dirty.nim +# A variant of the suggest-compile.txt, instead of using a "base" correct +# source, this one uses the "broken" main_dirty.nim which won't compile. The +# test tries to stress idetools to still provide a valid answer if possible, +# and at least provide the same output with repeated queries rather than dying +# after the first compilation error. + +# The first query should work and provide valid suggestions. +> idetools --track:$TESTNIM,12,6 --suggest $SILENT +skField\tx +skField\ty + +# Repeating the query should work too. +> idetools --track:$TESTNIM,12,6 --suggest $SILENT +skField\tx +skField\ty + +# Expect now a compilation failure. +> c +!SuccessX +invalid indentation + +# Repeating suggestions *after broken compilation* should work too. +> idetools --track:$TESTNIM,12,6 --suggest $SILENT +skField\tx +skField\ty diff --git a/tests/caasdriver.nim b/tests/caasdriver.nim index f6f3d4e38..28f0bae9b 100644 --- a/tests/caasdriver.nim +++ b/tests/caasdriver.nim @@ -2,45 +2,7 @@ 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). -## -## 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. -## -## The rest of the line is treated as a regular expression, so be careful -## 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 -## 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 +## Please read docs/idetools.txt for information about this. type @@ -84,6 +46,8 @@ proc startNimrodSession(project, script: string, mode: TRunMode): if mode == SymbolProcRun: removeDir(nimcacheDir / result.nimcache) + else: + removeDir(nimcacheDir / "nimcache") if mode == CaasRun: result.nim = startProcess(NimrodBin, workingDir = dir, |