Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
425f221440
19 changed files with 302 additions and 113 deletions
15
tests/async/t6100.nim
Normal file
15
tests/async/t6100.nim
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
discard """
|
||||
file: "t6100.nim"
|
||||
exitcode: 0
|
||||
output: "10000000"
|
||||
"""
|
||||
import asyncdispatch
|
||||
|
||||
let done = newFuture[int]()
|
||||
done.complete(1)
|
||||
|
||||
proc asyncSum: Future[int] {.async.} =
|
||||
for _ in 1..10_000_000:
|
||||
result += await done
|
||||
|
||||
echo waitFor asyncSum()
|
||||
|
|
@ -1,61 +1,7 @@
|
|||
discard """
|
||||
exitcode: 0
|
||||
disabled: "windows"
|
||||
output: '''
|
||||
b failure
|
||||
Async traceback:
|
||||
tasync_traceback.nim(97) tasync_traceback
|
||||
asyncmacro.nim(395) a
|
||||
asyncmacro.nim(34) a_continue
|
||||
## Resumes an async procedure
|
||||
tasync_traceback.nim(95) aIter
|
||||
asyncmacro.nim(395) b
|
||||
asyncmacro.nim(34) b_continue
|
||||
## Resumes an async procedure
|
||||
tasync_traceback.nim(92) bIter
|
||||
#[
|
||||
tasync_traceback.nim(97) tasync_traceback
|
||||
asyncmacro.nim(395) a
|
||||
asyncmacro.nim(43) a_continue
|
||||
## Resumes an async procedure
|
||||
asyncfutures.nim(211) callback=
|
||||
asyncfutures.nim(190) addCallback
|
||||
asyncfutures.nim(53) callSoon
|
||||
asyncmacro.nim(34) a_continue
|
||||
## Resumes an async procedure
|
||||
asyncmacro.nim(0) aIter
|
||||
asyncfutures.nim(304) read
|
||||
]#
|
||||
Exception message: b failure
|
||||
Exception type:
|
||||
|
||||
bar failure
|
||||
Async traceback:
|
||||
tasync_traceback.nim(113) tasync_traceback
|
||||
asyncdispatch.nim(1492) waitFor
|
||||
asyncdispatch.nim(1496) poll
|
||||
## Processes asynchronous completion events
|
||||
asyncdispatch.nim(1262) runOnce
|
||||
asyncdispatch.nim(183) processPendingCallbacks
|
||||
## Executes pending callbacks
|
||||
asyncmacro.nim(34) bar_continue
|
||||
## Resumes an async procedure
|
||||
tasync_traceback.nim(108) barIter
|
||||
#[
|
||||
tasync_traceback.nim(113) tasync_traceback
|
||||
asyncdispatch.nim(1492) waitFor
|
||||
asyncdispatch.nim(1496) poll
|
||||
## Processes asynchronous completion events
|
||||
asyncdispatch.nim(1262) runOnce
|
||||
asyncdispatch.nim(183) processPendingCallbacks
|
||||
## Executes pending callbacks
|
||||
asyncmacro.nim(34) foo_continue
|
||||
## Resumes an async procedure
|
||||
asyncmacro.nim(0) fooIter
|
||||
asyncfutures.nim(304) read
|
||||
]#
|
||||
Exception message: bar failure
|
||||
Exception type:'''
|
||||
output: "Matched"
|
||||
"""
|
||||
import asyncdispatch
|
||||
|
||||
|
|
@ -87,6 +33,8 @@ import asyncdispatch
|
|||
# tasync_traceback.nim(21) a
|
||||
# tasync_traceback.nim(18) b
|
||||
|
||||
var result = ""
|
||||
|
||||
proc b(): Future[int] {.async.} =
|
||||
if true:
|
||||
raise newException(OSError, "b failure")
|
||||
|
|
@ -98,8 +46,8 @@ let aFut = a()
|
|||
try:
|
||||
discard waitFor aFut
|
||||
except Exception as exc:
|
||||
echo exc.msg
|
||||
echo()
|
||||
result.add(exc.msg & "\n")
|
||||
result.add("\n")
|
||||
|
||||
# From #6803
|
||||
proc bar(): Future[string] {.async.} =
|
||||
|
|
@ -110,7 +58,69 @@ proc bar(): Future[string] {.async.} =
|
|||
proc foo(): Future[string] {.async.} = return await bar()
|
||||
|
||||
try:
|
||||
echo waitFor(foo())
|
||||
result.add(waitFor(foo()) & "\n")
|
||||
except Exception as exc:
|
||||
echo exc.msg
|
||||
echo()
|
||||
result.add(exc.msg & "\n")
|
||||
result.add("\n")
|
||||
|
||||
# Use re to parse the result
|
||||
import re
|
||||
const expected = """
|
||||
b failure
|
||||
Async traceback:
|
||||
tasync_traceback\.nim\(\d+?\)\s+?tasync_traceback
|
||||
asyncmacro\.nim\(\d+?\)\s+?a
|
||||
asyncmacro\.nim\(\d+?\)\s+?a_continue
|
||||
## Resumes an async procedure
|
||||
tasync_traceback\.nim\(\d+?\)\s+?aIter
|
||||
asyncmacro\.nim\(\d+?\)\s+?b
|
||||
asyncmacro\.nim\(\d+?\)\s+?b_continue
|
||||
## Resumes an async procedure
|
||||
tasync_traceback\.nim\(\d+?\)\s+?bIter
|
||||
#\[
|
||||
tasync_traceback\.nim\(\d+?\)\s+?tasync_traceback
|
||||
asyncmacro\.nim\(\d+?\)\s+?a
|
||||
asyncmacro\.nim\(\d+?\)\s+?a_continue
|
||||
## Resumes an async procedure
|
||||
asyncmacro\.nim\(\d+?\)\s+?aIter
|
||||
asyncfutures\.nim\(\d+?\)\s+?read
|
||||
\]#
|
||||
Exception message: b failure
|
||||
Exception type:
|
||||
|
||||
bar failure
|
||||
Async traceback:
|
||||
tasync_traceback\.nim\(\d+?\)\s+?tasync_traceback
|
||||
asyncdispatch\.nim\(\d+?\)\s+?waitFor
|
||||
asyncdispatch\.nim\(\d+?\)\s+?poll
|
||||
## Processes asynchronous completion events
|
||||
asyncdispatch\.nim\(\d+?\)\s+?runOnce
|
||||
asyncdispatch\.nim\(\d+?\)\s+?processPendingCallbacks
|
||||
## Executes pending callbacks
|
||||
asyncmacro\.nim\(\d+?\)\s+?bar_continue
|
||||
## Resumes an async procedure
|
||||
tasync_traceback\.nim\(\d+?\)\s+?barIter
|
||||
#\[
|
||||
tasync_traceback\.nim\(\d+?\)\s+?tasync_traceback
|
||||
asyncdispatch\.nim\(\d+?\)\s+?waitFor
|
||||
asyncdispatch\.nim\(\d+?\)\s+?poll
|
||||
## Processes asynchronous completion events
|
||||
asyncdispatch\.nim\(\d+?\)\s+?runOnce
|
||||
asyncdispatch\.nim\(\d+?\)\s+?processPendingCallbacks
|
||||
## Executes pending callbacks
|
||||
asyncmacro\.nim\(\d+?\)\s+?foo_continue
|
||||
## Resumes an async procedure
|
||||
asyncmacro\.nim\(\d+?\)\s+?fooIter
|
||||
asyncfutures\.nim\(\d+?\)\s+?read
|
||||
\]#
|
||||
Exception message: bar failure
|
||||
Exception type:
|
||||
"""
|
||||
|
||||
if result.match(re(expected)):
|
||||
echo("Matched")
|
||||
else:
|
||||
echo("Not matched!")
|
||||
echo()
|
||||
echo(result)
|
||||
quit(QuitFailure)
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ var fs = newFutureStream[int]()
|
|||
|
||||
proc alpha() {.async.} =
|
||||
for i in 0 .. 5:
|
||||
await sleepAsync(1000)
|
||||
await fs.write(i)
|
||||
await sleepAsync(1000)
|
||||
|
||||
echo("Done")
|
||||
fs.complete()
|
||||
|
|
|
|||
|
|
@ -48,5 +48,11 @@ doAssert "2.71828182845904523536028747".parseFloat ==
|
|||
2.71828182845904523536028747
|
||||
doAssert 0.00097656250000000021684043449710088680149056017398834228515625 ==
|
||||
"0.00097656250000000021684043449710088680149056017398834228515625".parseFloat
|
||||
doAssert 0.00998333 == ".00998333".parseFloat
|
||||
doAssert 0.00128333 == ".00128333".parseFloat
|
||||
doAssert 999999999999999.0 == "999999999999999.0".parseFloat
|
||||
doAssert 9999999999999999.0 == "9999999999999999.0".parseFloat
|
||||
doAssert 0.999999999999999 == ".999999999999999".parseFloat
|
||||
doAssert 0.9999999999999999 == ".9999999999999999".parseFloat
|
||||
|
||||
echo("passed all tests.")
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ discard """
|
|||
(y: 678, x: 123)
|
||||
(y: 678, x: 123)
|
||||
(y: 0, x: 123)
|
||||
(y: 678, x: 123)'''
|
||||
(y: 678, x: 123)
|
||||
(y: 123, x: 678)'''
|
||||
"""
|
||||
|
||||
type
|
||||
|
|
@ -75,3 +76,7 @@ when true:
|
|||
echo b # (y: 0, x: 123)
|
||||
b=B(y: 678, x: 123)
|
||||
echo b # (y: 678, x: 123)
|
||||
b=B(y: b.x, x: b.y)
|
||||
echo b # (y: 123, x: 678)
|
||||
|
||||
GC_fullCollect()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
discard """
|
||||
output: '''42
|
||||
Foo'''
|
||||
"""
|
||||
|
||||
type TFoo{.exportc.} = object
|
||||
x:int
|
||||
|
||||
|
|
@ -48,3 +53,5 @@ type NamedGraphic = object of Graphic2
|
|||
|
||||
var ngr = NamedGraphic(kind: Koo, radius: 6.9, name: "Foo")
|
||||
echo ngr.name
|
||||
|
||||
GC_fullCollect()
|
||||
|
|
|
|||
|
|
@ -281,6 +281,30 @@ suite "ttimes":
|
|||
test "parseTest":
|
||||
runTimezoneTests()
|
||||
|
||||
test "dynamic timezone":
|
||||
proc staticOffset(offset: int): Timezone =
|
||||
proc zoneInfoFromTz(adjTime: Time): ZonedTime =
|
||||
result.isDst = false
|
||||
result.utcOffset = offset
|
||||
result.adjTime = adjTime
|
||||
|
||||
proc zoneInfoFromUtc(time: Time): ZonedTime =
|
||||
result.isDst = false
|
||||
result.utcOffset = offset
|
||||
result.adjTime = fromUnix(time.toUnix - offset)
|
||||
|
||||
result.name = ""
|
||||
result.zoneInfoFromTz = zoneInfoFromTz
|
||||
result.zoneInfoFromUtc = zoneInfoFromUtc
|
||||
|
||||
let tz = staticOffset(-9000)
|
||||
let dt = initDateTime(1, mJan, 2000, 12, 00, 00, tz)
|
||||
check dt.utcOffset == -9000
|
||||
check dt.isDst == false
|
||||
check $dt == "2000-01-01T12:00:00+02:30"
|
||||
check $dt.utc == "2000-01-01T09:30:00+00:00"
|
||||
check $dt.utc.inZone(tz) == $dt
|
||||
|
||||
test "isLeapYear":
|
||||
check isLeapYear(2016)
|
||||
check (not isLeapYear(2015))
|
||||
|
|
|
|||
36
tests/untestable/tssl.nim
Normal file
36
tests/untestable/tssl.nim
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#
|
||||
# Nim - SSL integration tests
|
||||
# (c) Copyright 2017 Nim contributors
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
## Warning: this test performs external networking.
|
||||
##
|
||||
## Test with:
|
||||
## ./bin/nim c -d:ssl -p:. -r tests/untestable/tssl.nim
|
||||
## ./bin/nim c -d:ssl -p:. --dynlibOverride:ssl --passL:-lcrypto --passL:-lssl -r tests/untestable/tssl.nim
|
||||
## The compilation is expected to succeed with any new/old version of OpenSSL,
|
||||
## both with dynamic and static linking.
|
||||
## The "howsmyssl" test is known to fail with OpenSSL < 1.1 due to insecure
|
||||
## cypher suites being used.
|
||||
|
||||
import httpclient, os
|
||||
from strutils import contains, toHex
|
||||
|
||||
from openssl import getOpenSSLVersion
|
||||
|
||||
when isMainModule:
|
||||
echo "version: 0x" & $getOpenSSLVersion().toHex()
|
||||
|
||||
let client = newHttpClient()
|
||||
# hacky SSL check
|
||||
const url = "https://www.howsmyssl.com"
|
||||
let report = client.getContent(url)
|
||||
if not report.contains(">Probably Okay</span>"):
|
||||
let fn = getTempDir() / "sslreport.html"
|
||||
echo "SSL CHECK ERROR, see " & fn
|
||||
writeFile(fn, report)
|
||||
quit(1)
|
||||
|
||||
echo "done"
|
||||
Loading…
Add table
Add a link
Reference in a new issue