Merge branch 'devel' into feature/3691

This commit is contained in:
Dominik Picheta 2017-02-07 18:34:05 +01:00 • committed by GitHub
commit d5bb5e832b
84 changed files with 1381 additions and 492 deletions

View file

@ -0,0 +1,36 @@
discard """
exitcode: 0
output: ""
"""
import asyncdispatch, net, os, nativesockets
# bug: https://github.com/nim-lang/Nim/issues/5279
proc setupServerSocket(hostname: string, port: Port): AsyncFD =
let fd = newNativeSocket()
if fd == osInvalidSocket:
raiseOSError(osLastError())
setSockOptInt(fd, SOL_SOCKET, SO_REUSEADDR, 1)
var aiList = getAddrInfo(hostname, port)
if bindAddr(fd, aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32:
freeAddrInfo(aiList)
raiseOSError(osLastError())
freeAddrInfo(aiList)
if listen(fd) != 0:
raiseOSError(osLastError())
setBlocking(fd, false)
result = fd.AsyncFD
register(result)
const port = Port(5614)
for i in 0..100:
let serverFd = setupServerSocket("localhost", port)
serverFd.accept().callback = proc(fut: Future[AsyncFD]) =
if not fut.failed:
fut.read().closeSocket()
var fd = newAsyncNativeSocket()
waitFor fd.connect("localhost", port)
serverFd.closeSocket()
fd.closeSocket()

View file

@ -0,0 +1,17 @@
discard """
output: '''@[1, 2, 3, 4]'''
"""
# bug #5314
import asyncdispatch
proc bar(): Future[int] {.async.} =
await sleepAsync(500)
result = 3
proc foo(): Future[seq[int]] {.async.} =
await sleepAsync(500)
result = @[1, 2, await bar(), 4] # <--- The bug is here
echo waitFor foo()

View file

@ -1,9 +1,6 @@
discard """
output: '''
OK
OK
OK
OK
'''
"""
@ -31,11 +28,50 @@ when defined(upcoming):
var fut = waitEvent(event)
asyncCheck(delayedSet(event, 500))
waitFor(fut or sleepAsync(1000))
if fut.finished:
echo "OK"
else:
if not fut.finished:
echo "eventTest: Timeout expired before event received!"
proc eventTest5304() =
# Event should not be signaled if it was uregistered,
# even in case, when poll() was not called yet.
# Issue #5304.
var unregistered = false
let e = newAsyncEvent()
addEvent(e) do (fd: AsyncFD) -> bool:
assert(not unregistered)
e.setEvent()
e.unregister()
unregistered = true
poll()
proc eventTest5298() =
# Event must raise `AssertionError` if event was unregistered twice.
# Issue #5298.
let e = newAsyncEvent()
var eventReceived = false
addEvent(e) do (fd: AsyncFD) -> bool:
eventReceived = true
return true
e.setEvent()
while not eventReceived:
poll()
try:
e.unregister()
except AssertionError:
discard
e.close()
proc eventTest5331() =
# Event must not raise any exceptions while was unregistered inside of
# own callback.
# Issue #5331.
let e = newAsyncEvent()
addEvent(e) do (fd: AsyncFD) -> bool:
e.unregister()
e.close()
e.setEvent()
poll()
when ioselSupportedPlatform or defined(windows):
import osproc
@ -56,7 +92,6 @@ when defined(upcoming):
proc timerTest() =
waitFor(waitTimer(200))
echo "OK"
proc processTest() =
when defined(windows):
@ -70,7 +105,7 @@ when defined(upcoming):
var fut = waitProcess(process)
waitFor(fut or waitTimer(2000))
if fut.finished and process.peekExitCode() == 0:
echo "OK"
discard
else:
echo "processTest: Timeout expired before process exited!"
@ -92,23 +127,31 @@ when defined(upcoming):
var fut = waitSignal(posix.SIGINT)
asyncCheck(delayedSignal(posix.SIGINT, 500))
waitFor(fut or waitTimer(1000))
if fut.finished:
echo "OK"
else:
if not fut.finished:
echo "signalTest: Timeout expired before signal received!"
when ioselSupportedPlatform:
timerTest()
eventTest()
eventTest5304()
eventTest5298()
eventTest5331()
processTest()
signalTest()
echo "OK"
elif defined(windows):
timerTest()
eventTest()
eventTest5304()
eventTest5298()
eventTest5331()
processTest()
echo "OK"
else:
eventTest()
echo "OK\nOK\nOK"
eventTest5304()
eventTest5298()
eventTest5331()
echo "OK"
else:
echo "OK\nOK\nOK\nOK"
echo "OK"

View file

@ -1,7 +1,7 @@
discard """
output: "1"
cmd: r"nim c --hints:on $options -d:release $file"
ccodecheck: "'NI volatile state0;'"
ccodecheck: "'NI volatile state;'"
"""
# bug #1539

View file

@ -190,28 +190,26 @@ block zeroHashKeysTest:
doZeroHashValueTest(toOrderedTable[string,string]({"egg": "sausage"}),
"", "spam")
# Until #4448 is fixed, these tests will fail
when false:
block clearTableTest:
var t = data.toTable
assert t.len() != 0
t.clear()
assert t.len() == 0
block clearTableTest:
var t = data.toTable
assert t.len() != 0
t.clear()
assert t.len() == 0
block clearOrderedTableTest:
var t = data.toOrderedTable
assert t.len() != 0
t.clear()
assert t.len() == 0
block clearOrderedTableTest:
var t = data.toOrderedTable
assert t.len() != 0
t.clear()
assert t.len() == 0
block clearCountTableTest:
var t = initCountTable[string]()
t.inc("90", 3)
t.inc("12", 2)
t.inc("34", 1)
assert t.len() != 0
t.clear()
assert t.len() == 0
block clearCountTableTest:
var t = initCountTable[string]()
t.inc("90", 3)
t.inc("12", 2)
t.inc("34", 1)
assert t.len() != 0
t.clear()
assert t.len() == 0
proc orderedTableSortTest() =
var t = initOrderedTable[string, int](2)

View file

@ -1,6 +1,6 @@
#
# fsmonitor test
#
discard """
disabled: windows
"""
import unittest
import fsmonitor
@ -9,4 +9,3 @@ suite "fsmonitor":
test "should not raise OSError, bug# 3611":
let m = newMonitor()
m.add("foo", {MonitorCloseWrite, MonitorCloseNoWrite})

View file

@ -7,7 +7,8 @@ Filter Iterator: 7
Filter: [3, 5, 7]
FilterIt: [1, 3, 7]
Concat: [1, 3, 5, 7, 2, 4, 6]
Deduplicate: [1, 2, 3, 4, 5, 7]'''
Deduplicate: [1, 2, 3, 4, 5, 7]
@[()]'''
"""
@ -52,4 +53,12 @@ echo "Concat: ", $$(concatseq)
var seq3 = @[1,2,3,4,5,5,5,7]
var dedupseq = deduplicate(seq3)
echo "Deduplicate: ", $$(dedupseq)
# bug #4973
type
SomeObj = object
OtherObj = object
field: SomeObj
let aSeq = @[OtherObj(field: SomeObj())]
let someObjSeq = aSeq.mapIt(it.field)
echo someObjSeq

55
tests/stdlib/tstring.nim Normal file
View file

@ -0,0 +1,55 @@
discard """
file: "tstring.nim"
output: "OK"
"""
const characters = "abcdefghijklmnopqrstuvwxyz"
const numbers = "1234567890"
var s: string
proc test_string_slice() =
# test "slice of length == len(characters)":
# replace characters completely by numbers
s = characters
s[0..^1] = numbers
doAssert s == numbers
# test "slice of length > len(numbers)":
# replace characters by slice of same length
s = characters
s[1..16] = numbers
doAssert s == "a1234567890rstuvwxyz"
# test "slice of length == len(numbers)":
# replace characters by slice of same length
s = characters
s[1..10] = numbers
doAssert s == "a1234567890lmnopqrstuvwxyz"
# test "slice of length < len(numbers)":
# replace slice of length. and insert remaining chars
s = characters
s[1..4] = numbers
doAssert s == "a1234567890fghijklmnopqrstuvwxyz"
# test "slice of length == 1":
# replace first character. and insert remaining 9 chars
s = characters
s[1..1] = numbers
doAssert s == "a1234567890cdefghijklmnopqrstuvwxyz"
# test "slice of length == 0":
# insert chars at slice start index
s = characters
s[2..1] = numbers
doAssert s == "ab1234567890cdefghijklmnopqrstuvwxyz"
# test "slice of negative length":
# same as slice of zero length
s = characters
s[2..0] = numbers
doAssert s == "ab1234567890cdefghijklmnopqrstuvwxyz"
echo("OK")
test_string_slice()

View file

@ -0,0 +1,21 @@
template mathPerComponent(op: untyped): untyped =
proc op*[N,T](v,u: array[N,T]): array[N,T] {.inline.} =
for i in 0 ..< len(result):
result[i] = `*`(v[i], u[i])
mathPerComponent(`***`)
# bug #5285
when true:
if isMainModule:
var v1: array[3, float64]
var v2: array[3, float64]
echo repr(v1 *** v2)
proc foo(): void =
var v1: array[4, float64]
var v2: array[4, float64]
echo repr(v1 *** v2)
foo()

View file

@ -6,7 +6,7 @@ discard """
var i {.compileTime.} = 2
template defineId*(t: typedesc): stmt =
template defineId*(t: typedesc) =
const id {.genSym.} = i
static: inc(i)
proc idFor*(T: typedesc[t]): int {.inline, raises: [].} = id

View file

@ -284,9 +284,9 @@ proc compileExample(r: var TResults, pattern, options: string, cat: Category) =
testNoSpec r, makeTest(test, options, cat)
proc testStdlib(r: var TResults, pattern, options: string, cat: Category) =
var disabledSet = disabledFiles.toSet()
for test in os.walkFiles(pattern):
if test notin disabledSet:
let name = extractFilename(test)
if name notin disabledFiles:
let contents = readFile(test).string
if contents.contains("when isMainModule"):
testSpec r, makeTest(test, options, cat, actionRunNoSpec)

View file

@ -108,12 +108,6 @@ proc callCompiler(cmdTemplate, filename, options: string,
elif suc =~ pegSuccess:
result.err = reSuccess
if result.err == reNimcCrash and
("Your platform is not supported" in result.msg or
"cannot open 'sdl'" in result.msg or
"cannot open 'opengl'" in result.msg):
result.err = reIgnored
proc callCCompiler(cmdTemplate, filename, options: string,
target: TTarget): TSpec =
let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
@ -393,9 +387,14 @@ proc makeTest(test, options: string, cat: Category, action = actionCompile,
result = TTest(cat: cat, name: test, options: options,
target: target, action: action, startTime: epochTime())
const
# array of modules disabled from compilation test of stdlib.
disabledFiles = ["-"]
when defined(windows):
const
# array of modules disabled from compilation test of stdlib.
disabledFiles = ["coro.nim", "fsmonitor.nim"]
else:
const
# array of modules disabled from compilation test of stdlib.
disabledFiles = ["-"]
include categories
@ -460,7 +459,9 @@ proc main() =
backend.close()
if optPedantic:
var failed = r.total - r.passed - r.skipped
if failed > 0 : quit(QuitFailure)
if failed > 0:
echo "FAILURE! total: ", r.total, " passed: ", r.passed, " skipped: ", r.skipped
quit(QuitFailure)
if paramCount() == 0:
quit Usage

View file

@ -0,0 +1,38 @@
discard """
nimout: '''0
0
0
{hallo: 123, welt: 456}'''
"""
import tables
# bug #5327
type
MyType* = object
counter: int
proc foo(t: var MyType) =
echo t.counter
proc bar(t: MyType) =
echo t.counter
static:
var myValue: MyType
myValue.foo # works nicely
var refValue: ref MyType
refValue.new
refValue[].foo # fails to compile
refValue[].bar # works again nicely
static:
var otherTable = newTable[string, string]()
otherTable["hallo"] = "123"
otherTable["welt"] = "456"
echo otherTable

View file

@ -1,5 +1,5 @@
discard """
msg: '''2
nimout: '''2
3
4:2
Got Hi
@ -13,7 +13,7 @@ import macros, tables, strtabs
var ZOOT{.compileTime.} = initTable[int, int](2)
var iii {.compiletime.} = 1
macro zoo:stmt=
macro zoo: untyped =
ZOOT[iii] = iii*2
inc iii
echo iii
@ -22,7 +22,7 @@ zoo
zoo
macro tupleUnpack: stmt =
macro tupleUnpack: untyped =
var (y,z) = (4, 2)
echo y, ":", z
@ -32,14 +32,14 @@ tupleUnpack
var x {.compileTime.}: StringTableRef
macro addStuff(stuff, body: expr): stmt {.immediate.} =
macro addStuff(stuff, body: untyped): untyped =
result = newNimNode(nnkStmtList)
if x.isNil:
x = newStringTable(modeStyleInsensitive)
x[$stuff] = ""
macro dump(): stmt =
macro dump(): untyped =
result = newNimNode(nnkStmtList)
for y in x.keys: echo "Got ", y

View file

@ -0,0 +1,30 @@
discard """
nimout: "static done"
"""
# bug #5269
proc assertEq[T](arg0, arg1: T): void =
assert arg0 == arg1, $arg0 & " == " & $arg1
type
MyType = object
str: string
a: int
block:
var localValue = MyType(str: "Original strning, (OK)", a: 0)
var valueCopy = localValue
valueCopy.a = 123
valueCopy.str = "Modified strning, (not OK when in localValue)"
assertEq(localValue.str, "Original strning, (OK)")
assertEq(localValue.a, 0)
static:
var localValue = MyType(str: "Original strning, (OK)", a: 0)
var valueCopy = localValue
valueCopy.a = 123
valueCopy.str = "Modified strning, (not OK when in localValue)"
assertEq(localValue.str, "Original strning, (OK)")
assertEq(localValue.a, 0)
echo "static done"