Merge branch 'master' into newparser

This commit is contained in:
Araq 2013-05-04 19:10:12 +02:00
commit 23bd3ccd8b
31 changed files with 277 additions and 63 deletions

View file

@ -0,0 +1,7 @@
main.nim
> c
SuccessX
> c
! Processing
SuccessX

View file

@ -0,0 +1,9 @@
main.nim
> c
SuccessX
> idetools --track:main.nim,5,18 --def main.nim
strutils.toUpper
SuccessX
> idetools --track:main.nim,5,18 --def main.nim
strutils.toUpper
SuccessX

View file

@ -0,0 +1,7 @@
main.nim
> idetools --track:main.nim,5,18 --def main.nim
strutils.toUpper
SuccessX
> c
SuccessX

3
tests/caas/imported.nim Normal file
View file

@ -0,0 +1,3 @@
proc `+++`*(a,b: string): string =
return a & " " & b

7
tests/caas/main.nim Normal file
View file

@ -0,0 +1,7 @@
import imported, strutils
proc main =
var t1 = "text"
var t2 = t1.toUpper
echo(t1 +++ t2)

86
tests/caasdriver.nim Normal file
View file

@ -0,0 +1,86 @@
import osproc, streams, os, strutils, re
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,
args = ["serve", "--server.type:stdin", project])
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):
if line.string == "": break
result.add(line.string & "\n")
else:
result = "FAILED TO EXECUTE: " & command & "\n" & result
break
proc close(session: var TNimrodSession) {.destructor.} =
session.nim.close
proc doScenario(script: string, output: PStream): bool =
result = true
var f = open(script)
var project = TaintedString("")
if f.readLine(project):
var
s = startNimrodSession(script.dirname / project.string)
tline = TaintedString("")
lastOutput = ""
ln = 1
while f.readLine(tline):
var line = tline.string
inc ln
if line.strip.len == 0: continue
if line.startsWith(">"):
lastOutput = s.doCommand(line.substr(1).strip)
output.writeln line, "\n", lastOutput
else:
var expectMatch = true
var pattern = line
if line.startsWith("!"):
pattern = line.substr(1).strip
expectMatch = false
var actualMatch = lastOutput.find(re(pattern)) != -1
if expectMatch == actualMatch:
output.writeln "SUCCESS ", line
else:
output.writeln "FAILURE ", line
result = false
iterator caasTestsRunner*(filter = ""): tuple[test, output: string,
status: bool] =
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)
when isMainModule:
var filter = ""
if paramCount() > 0: filter = paramStr(1)
for t, o, r in caasTestsRunner(filter):
echo t, "\n", o

View file

@ -1,12 +1,14 @@
discard """
file: "tbug499771.nim"
output: "TSubRange: 5 from 1 to 10"
output: '''TSubRange: 5 from 1 to 10
true true true'''
"""
type TSubRange = range[1 .. 10]
type
TSubRange = range[1 .. 10]
TEnum = enum A, B, C
var sr: TSubRange = 5
echo("TSubRange: " & $sr & " from " & $low(TSubRange) & " to " &
$high(TSubRange))
const cset = {A} + {B}
echo A in cset, " ", B in cset, " ", C notin cset

View file

@ -1,7 +0,0 @@
discard """
file: "tlenopenarray.nim"
output: "1"
"""
echo len([1_000_000]) #OUT 1

View file

@ -0,0 +1,26 @@
discard """
output: "direct\nopenarray\nvarargs"
"""
proc withDirectType(args: string) =
echo "direct"
proc withDirectType[T](arg: T) =
echo "generic"
proc withOpenArray(args: openarray[string]) =
echo "openarray"
proc withOpenArray[T](arg: T) =
echo "generic"
proc withVarargs(args: varargs[string]) =
echo "varargs"
proc withVarargs[T](arg: T) =
echo "generic"
withDirectType "string"
withOpenArray "string"
withVarargs "string"

14
tests/run/tvarious1.nim Normal file
View file

@ -0,0 +1,14 @@
discard """
file: "tlenopenarray.nim"
output: '''1
0'''
"""
echo len([1_000_000]) #OUT 1
type
TArray = array[0..3, int]
TVector = distinct array[0..3, int]
proc `[]`(v: TVector; idx: int): int = TArray(v)[idx]
var v: TVector
echo v[2]

View file

@ -11,7 +11,7 @@
import
parseutils, strutils, pegs, os, osproc, streams, parsecfg, browsers, json,
marshal, cgi, parseopt
marshal, cgi, parseopt, caasdriver
const
cmdTemplate = r"nimrod cc --hints:on $# $#"
@ -38,6 +38,7 @@ type
reExeNotFound,
reIgnored, # test is ignored
reSuccess # test was successful
TTarget = enum
targetC, targetCpp, targetObjC, targetJS
@ -363,6 +364,10 @@ proc outputJSON(reject, compile, run: TResults) =
var s = pretty(doc)
writeFile(jsonFile, s)
proc runCaasTests(r: var TResults) =
for test, output, status in caasTestsRunner():
r.addResult(test, "", output, if status: reSuccess else: reOutputsDiffer)
proc main() =
os.putenv "NIMTEST_NO_COLOR", "1"
os.putenv "NIMTEST_OUTPUT_LVL", "PRINT_FAILURES"
@ -404,6 +409,7 @@ proc main() =
writeResults(runJson, r)
of "special":
runSpecialTests(r, p.cmdLineRest.string)
runCaasTests(r)
writeResults(runJson, r)
of "rodfiles":
runRodFiles(r, p.cmdLineRest.string)