diff options
author | Araq <rumpf_a@web.de> | 2016-12-17 23:04:34 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2016-12-17 23:04:34 +0100 |
commit | 24239c23619e9d64562699b5d890fa2575e9c9cb (patch) | |
tree | 7b68d65e1bc5c12a465dd29814e6328cb25e30b4 /tests | |
parent | 3a4ec7f101f539fb536086b59c84e1b2c095ef82 (diff) | |
parent | d4c33df91996e30ded5f7f2014e7cd49176b5b05 (diff) | |
download | Nim-24239c23619e9d64562699b5d890fa2575e9c9cb.tar.gz |
Merge branch 'devel' into sighashes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/async/tioselectors.nim | 11 | ||||
-rw-r--r-- | tests/async/tupcoming_async.nim | 88 | ||||
-rw-r--r-- | tests/cpp/temitlist.nim | 22 |
3 files changed, 71 insertions, 50 deletions
diff --git a/tests/async/tioselectors.nim b/tests/async/tioselectors.nim index 71d901e69..e6b4196a3 100644 --- a/tests/async/tioselectors.nim +++ b/tests/async/tioselectors.nim @@ -12,11 +12,10 @@ template processTest(t, x: untyped) = if not x: echo(t & " FAILED\r\n") when not defined(windows): - import os, posix, osproc, nativesockets, times + import os, posix, nativesockets, times - const supportedPlatform = defined(macosx) or defined(freebsd) or - defined(netbsd) or defined(openbsd) or - defined(linux) + when ioselSupportedPlatform: + import osproc proc socket_notification_test(): bool = proc create_test_socket(): SocketHandle = @@ -143,7 +142,7 @@ when not defined(windows): selector.close() result = true - when supportedPlatform: + when ioselSupportedPlatform: proc timer_notification_test(): bool = var selector = newSelector[int]() var timer = selector.registerTimer(100, false, 0) @@ -462,7 +461,7 @@ when not defined(windows): when hasThreadSupport: processTest("Multithreaded user event notification test...", mt_event_test()) - when supportedPlatform: + when ioselSupportedPlatform: processTest("Timer notification test...", timer_notification_test()) processTest("Process notification test...", process_notification_test()) processTest("Signal notification test...", signal_notification_test()) diff --git a/tests/async/tupcoming_async.nim b/tests/async/tupcoming_async.nim index 137794afd..7d255f213 100644 --- a/tests/async/tupcoming_async.nim +++ b/tests/async/tupcoming_async.nim @@ -8,11 +8,12 @@ OK """ when defined(upcoming): - import asyncdispatch, times, osproc, streams + import asyncdispatch, times, streams, posix + from ioselectors import ioselSupportedPlatform - const supportedPlatform = defined(linux) or defined(freebsd) or - defined(netbsd) or defined(openbsd) or - defined(macosx) + proc delayedSet(ev: AsyncEvent, timeout: int): Future[void] {.async.} = + await sleepAsync(timeout) + ev.setEvent() proc waitEvent(ev: AsyncEvent, closeEvent = false): Future[void] = var retFuture = newFuture[void]("waitEvent") @@ -25,56 +26,55 @@ when defined(upcoming): addEvent(ev, cb) return retFuture - proc waitTimer(timeout: int): Future[void] = - var retFuture = newFuture[void]("waitTimer") - proc cb(fd: AsyncFD): bool = - retFuture.complete() - addTimer(timeout, true, cb) - return retFuture - - proc waitProcess(p: Process): Future[void] = - var retFuture = newFuture[void]("waitProcess") - proc cb(fd: AsyncFD): bool = - retFuture.complete() - addProcess(p.processID(), cb) - return retFuture - - proc delayedSet(ev: AsyncEvent, timeout: int): Future[void] {.async.} = - await waitTimer(timeout) - ev.setEvent() - - proc timerTest() = - waitFor(waitTimer(200)) - echo "OK" - proc eventTest() = var event = newAsyncEvent() var fut = waitEvent(event) asyncCheck(delayedSet(event, 500)) - waitFor(fut or waitTimer(1000)) + waitFor(fut or sleepAsync(1000)) if fut.finished: echo "OK" else: echo "eventTest: Timeout expired before event received!" - proc processTest() = - when defined(windows): - var process = startProcess("ping.exe", "", - ["127.0.0.1", "-n", "2", "-w", "100"], nil, - {poStdErrToStdOut, poUsePath, poInteractive, - poDemon}) - else: - var process = startProcess("/bin/sleep", "", ["1"], nil, - {poStdErrToStdOut, poUsePath}) - var fut = waitProcess(process) - waitFor(fut or waitTimer(2000)) - if fut.finished and process.peekExitCode() == 0: + when ioselSupportedPlatform or defined(windows): + + import osproc + + proc waitTimer(timeout: int): Future[void] = + var retFuture = newFuture[void]("waitTimer") + proc cb(fd: AsyncFD): bool = + retFuture.complete() + addTimer(timeout, true, cb) + return retFuture + + proc waitProcess(p: Process): Future[void] = + var retFuture = newFuture[void]("waitProcess") + proc cb(fd: AsyncFD): bool = + retFuture.complete() + addProcess(p.processID(), cb) + return retFuture + + proc timerTest() = + waitFor(waitTimer(200)) echo "OK" - else: - echo "processTest: Timeout expired before process exited!" - when supportedPlatform: - import posix + proc processTest() = + when defined(windows): + var process = startProcess("ping.exe", "", + ["127.0.0.1", "-n", "2", "-w", "100"], nil, + {poStdErrToStdOut, poUsePath, poInteractive, + poDemon}) + else: + var process = startProcess("/bin/sleep", "", ["1"], nil, + {poStdErrToStdOut, poUsePath}) + var fut = waitProcess(process) + waitFor(fut or waitTimer(2000)) + if fut.finished and process.peekExitCode() == 0: + echo "OK" + else: + echo "processTest: Timeout expired before process exited!" + + when ioselSupportedPlatform: proc waitSignal(signal: int): Future[void] = var retFuture = newFuture[void]("waitSignal") @@ -97,7 +97,7 @@ when defined(upcoming): else: echo "signalTest: Timeout expired before signal received!" - when supportedPlatform: + when ioselSupportedPlatform: timerTest() eventTest() processTest() diff --git a/tests/cpp/temitlist.nim b/tests/cpp/temitlist.nim new file mode 100644 index 000000000..cef0fc52d --- /dev/null +++ b/tests/cpp/temitlist.nim @@ -0,0 +1,22 @@ +discard """ + cmd: "nim cpp $file" + output: '''6.0''' +""" + +# bug #4730 + +type Vector* {.importcpp: "std::vector", header: "<vector>".}[T] = object + +template `[]=`*[T](v: var Vector[T], key: int, val: T) = + {.emit: [v, "[", key, "] = ", val, ";"].} + +proc setLen*[T](v: var Vector[T]; size: int) {.importcpp: "resize", nodecl.} +proc `[]`*[T](v: var Vector[T], key: int): T {.importcpp: "(#[#])", nodecl.} + +proc main = + var v: Vector[float] + v.setLen 1 + v[0] = 6.0 + echo v[0] + +main() |