Merge branch 'devel' of github.com:nim-lang/Nim into devel

This commit is contained in:
Andreas Rumpf 2016-04-19 12:11:18 +02:00
commit ef9a9b119d
35 changed files with 590 additions and 176 deletions

View file

@ -24,7 +24,7 @@ proc main() {.async.} =
var file = openAsync(fn, fmAppend)
await file.write("\ntest2")
let errorTest = file.readAll()
await errorTest
echo await errorTest
doAssert errorTest.failed
file.close()
file = openAsync(fn, fmRead)

View file

@ -0,0 +1,9 @@
type
Map {.importcpp: "std::map", header: "<map>".} [T,U] = object
proc cInitMap(T: typedesc, U: typedesc): Map[T,U] {.importcpp: "std::map<'*1,'*2>()", nodecl.}
proc initMap[T, U](): Map[T, U] =
result = cInitMap(T, U)
var x: Map[cstring, cint] = initMap[cstring, cint]()

51
tests/js/tclosures.nim Normal file
View file

@ -0,0 +1,51 @@
discard """
action: run
"""
import math, strutils
const consolePrefix = "jsCallbacks"
asm """
var callback = []
function regCallback (fn) { callback.push (fn); }
function runCallbacks () {
var result = "\n"
var n = 0
for (var fn in callback) {
n += 1
result += "("+String (n)+")"
result += callback [fn] ()
result += "\n"
}
return result
}
function print (text) { console.log (text); }
"""
proc consoleprint (str:cstring): void {.importc: "print", noDecl.}
proc print* (a: varargs[string, `$`]) = consoleprint "$1: $2" % [consolePrefix, join (a, " ")]
type CallbackProc {.importc.} = proc () : cstring
proc regCallback (fn:CallbackProc) {.importc.}
proc runCallbacks ():cstring {.importc.}
proc `*` (s:string, n:Natural) : string = s.repeat (n)
proc outer (i:Natural) : (string, int) =
let c = $char (random (93) + 33)
let n = random (40)
let s = c * n
proc inner () : cstring = ("[$1]" % $n) & s & " <--"
regCallback (inner)
return (s, n)
var expected = "\n"
for i in 1 .. 10:
let (s, n) = outer (i)
expected &= ("($1)[$2]" % [$i, $n]) & s & " <--"
expected &= "\n"
let results = runCallbacks ()
doAssert(expected == results)

View file

@ -107,6 +107,15 @@ proc specDefaults*(result: var TSpec) =
result.tline = 0
result.tcolumn = 0
proc parseTargets*(value: string): set[TTarget] =
for v in value.normalize.split:
case v
of "c": result.incl(targetC)
of "cpp", "c++": result.incl(targetCpp)
of "objc": result.incl(targetObjC)
of "js": result.incl(targetJS)
else: echo "target ignored: " & v
proc parseSpec*(filename: string): TSpec =
specDefaults(result)
result.file = filename

View file

@ -33,6 +33,7 @@ Options:
--print also print results to the console
--failing only show failing/ignored tests
--pedantic return non-zero status code if there are failures
--targets:"c c++ js objc" run tests for specified targets (default: all)
""" % resultsFile
type
@ -60,6 +61,8 @@ let
pegSuccess = peg"'Hint: operation successful'.*"
pegOfInterest = pegLineError / pegOtherError
var targets = {low(TTarget)..high(TTarget)}
proc callCompiler(cmdTemplate, filename, options: string,
target: TTarget): TSpec =
let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
@ -275,6 +278,11 @@ proc analyzeAndConsolidateOutput(s: string): string =
proc testSpec(r: var TResults, test: TTest) =
# major entry point for a single test
if test.target notin targets:
r.addResult(test, "", "", reIgnored)
inc(r.skipped)
return
let tname = test.name.addFileExt(".nim")
inc(r.total)
var expected: TSpec
@ -336,7 +344,7 @@ proc testSpec(r: var TResults, test: TTest) =
reExitCodesDiffer)
return
if bufB != expectedOut:
if bufB != expectedOut and expected.action != actionRunNoSpec:
if not (expected.substr and expectedOut in bufB):
given.err = reOutputsDiffer
r.addResult(test, expected.outp, bufB, reOutputsDiffer)
@ -394,6 +402,7 @@ proc main() =
var optPrintResults = false
var optFailing = false
var optPedantic = false
var p = initOptParser()
p.next()
while p.kind == cmdLongoption:
@ -401,6 +410,7 @@ proc main() =
of "print", "verbose": optPrintResults = true
of "failing": optFailing = true
of "pedantic": optPedantic = true
of "targets": targets = parseTargets(p.val.string)
else: quit Usage
p.next()
if p.kind != cmdArgument: quit Usage

View file

@ -1,6 +1,7 @@
discard """
output: '''48
hel'''
hel
lo'''
"""
template optZero{x+x}(x: int): int = x*3
@ -15,3 +16,8 @@ s[0] = "hello"
s[0] = substr(s[0], 0, 2)
echo s[0]
# Test varargs matching
proc someVarargProc(k: varargs[string]) = doAssert(false) # this should not get called
template someVarargProcSingleArg{someVarargProc([a])}(a: string) = echo a
someVarargProc("lo")