mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
made some tests green
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
===========================
|
||||
========================
|
||||
Tools available with Nim
|
||||
===========================
|
||||
========================
|
||||
|
||||
The standard distribution ships with the following tools:
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ type
|
||||
disp: Dispatcher
|
||||
AsyncScgiState* = ref AsyncScgiStateObj
|
||||
|
||||
{.deprected: [EScgi: ScgiError, TScgiState: ScgiState,
|
||||
{.deprecated: [EScgi: ScgiError, TScgiState: ScgiState,
|
||||
PAsyncScgiState: AsyncScgiState, scgiError: raiseScgiError].}
|
||||
|
||||
proc recvBuffer(s: var ScgiState, L: int) =
|
||||
@@ -108,12 +108,12 @@ proc open*(s: var ScgiState, port = Port(4000), address = "127.0.0.1",
|
||||
s.input = newString(s.buflen) # will be reused
|
||||
|
||||
s.server = socket()
|
||||
if s.server == InvalidSocket: raiseOSError(osLastError())
|
||||
if s.server == invalidSocket: raiseOSError(osLastError())
|
||||
new(s.client) # Initialise s.client for `next`
|
||||
if s.server == InvalidSocket: raiseScgiError("could not open socket")
|
||||
if s.server == invalidSocket: raiseScgiError("could not open socket")
|
||||
#s.server.connect(connectionName, port)
|
||||
if reuseAddr:
|
||||
s.server.setSockOpt(OptReuseAddr, True)
|
||||
s.server.setSockOpt(OptReuseAddr, true)
|
||||
bindAddr(s.server, port, address)
|
||||
listen(s.server)
|
||||
|
||||
@@ -135,7 +135,7 @@ proc next*(s: var ScgiState, timeout: int = -1): bool =
|
||||
if d == '\0':
|
||||
s.client.close()
|
||||
return false
|
||||
if d notin strutils.digits:
|
||||
if d notin strutils.Digits:
|
||||
if d != ':': raiseScgiError("':' after length expected")
|
||||
break
|
||||
L = L * 10 + ord(d) - ord('0')
|
||||
@@ -144,7 +144,7 @@ proc next*(s: var ScgiState, timeout: int = -1): bool =
|
||||
if s.headers["SCGI"] != "1": raiseScgiError("SCGI Version 1 expected")
|
||||
L = parseInt(s.headers["CONTENT_LENGTH"])
|
||||
recvBuffer(s, L)
|
||||
return True
|
||||
return true
|
||||
|
||||
proc writeStatusOkTextContent*(c: Socket, contentType = "text/html") =
|
||||
## sends the following string to the socket `c`::
|
||||
@@ -206,7 +206,7 @@ proc handleClientRead(client: AsyncClient, s: AsyncScgiState) =
|
||||
return
|
||||
if ret == -1:
|
||||
return # No more data available
|
||||
if d[0] notin strutils.digits:
|
||||
if d[0] notin strutils.Digits:
|
||||
if d[0] != ':': raiseScgiError("':' after length expected")
|
||||
break
|
||||
client.dataLen = client.dataLen * 10 + ord(d[0]) - ord('0')
|
||||
|
||||
@@ -40,8 +40,8 @@ var
|
||||
|
||||
checkpoints = @[]
|
||||
|
||||
template TestSetupIMPL*: stmt {.immediate, dirty.} = discard
|
||||
template TestTeardownIMPL*: stmt {.immediate, dirty.} = discard
|
||||
template testSetupIMPL*: stmt {.immediate, dirty.} = discard
|
||||
template testTeardownIMPL*: stmt {.immediate, dirty.} = discard
|
||||
|
||||
proc shouldRun(testName: string): bool =
|
||||
result = true
|
||||
@@ -49,10 +49,10 @@ proc shouldRun(testName: string): bool =
|
||||
template suite*(name: expr, body: stmt): stmt {.immediate, dirty.} =
|
||||
block:
|
||||
template setup*(setupBody: stmt): stmt {.immediate, dirty.} =
|
||||
template TestSetupIMPL: stmt {.immediate, dirty.} = setupBody
|
||||
template testSetupIMPL: stmt {.immediate, dirty.} = setupBody
|
||||
|
||||
template teardown*(teardownBody: stmt): stmt {.immediate, dirty.} =
|
||||
template TestTeardownIMPL: stmt {.immediate, dirty.} = teardownBody
|
||||
template testTeardownIMPL: stmt {.immediate, dirty.} = teardownBody
|
||||
|
||||
body
|
||||
|
||||
@@ -60,10 +60,10 @@ proc testDone(name: string, s: TestStatus) =
|
||||
if s == FAILED:
|
||||
programResult += 1
|
||||
|
||||
if OutputLevel != PRINT_NONE and (OutputLevel == PRINT_ALL or s == FAILED):
|
||||
if outputLevel != PRINT_NONE and (outputLevel == PRINT_ALL or s == FAILED):
|
||||
template rawPrint() = echo("[", $s, "] ", name, "\n")
|
||||
when not defined(ECMAScript):
|
||||
if ColorOutput and not defined(ECMAScript):
|
||||
if colorOutput and not defined(ECMAScript):
|
||||
var color = (if s == OK: fgGreen else: fgRed)
|
||||
styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n"
|
||||
else:
|
||||
@@ -76,10 +76,10 @@ template test*(name: expr, body: stmt): stmt {.immediate, dirty.} =
|
||||
|
||||
if shouldRun(name):
|
||||
checkpoints = @[]
|
||||
var TestStatusIMPL {.inject.} = OK
|
||||
var testStatusIMPL {.inject.} = OK
|
||||
|
||||
try:
|
||||
TestSetupIMPL()
|
||||
testSetupIMPL()
|
||||
body
|
||||
|
||||
except:
|
||||
@@ -87,8 +87,8 @@ template test*(name: expr, body: stmt): stmt {.immediate, dirty.} =
|
||||
fail()
|
||||
|
||||
finally:
|
||||
TestTeardownIMPL()
|
||||
testDone name, TestStatusIMPL
|
||||
testTeardownIMPL()
|
||||
testDone name, testStatusIMPL
|
||||
|
||||
proc checkpoint*(msg: string) =
|
||||
checkpoints.add(msg)
|
||||
@@ -100,10 +100,10 @@ template fail* =
|
||||
echo msg
|
||||
|
||||
when not defined(ECMAScript):
|
||||
if AbortOnError: quit(1)
|
||||
if abortOnError: quit(1)
|
||||
|
||||
when declared(TestStatusIMPL):
|
||||
TestStatusIMPL = FAILED
|
||||
when declared(testStatusIMPL):
|
||||
testStatusIMPL = FAILED
|
||||
else:
|
||||
programResult += 1
|
||||
|
||||
|
||||
@@ -18,4 +18,4 @@ proc `++`(x, y: DF): DF {.borrow.}
|
||||
proc `$`(x: DI): string {.borrow.}
|
||||
proc `$`(x: DF): string {.borrow.}
|
||||
|
||||
echo 4544.DI ++ 343.di, " ", (4.5.df ++ 0.5.df).float == 5.0
|
||||
echo 4544.DI ++ 343.DI, " ", (4.5.DF ++ 0.5.DF).float == 5.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
discard """
|
||||
file: "tsubrange2.nim"
|
||||
outputsub: "value out of range: 50 [EOutOfRange]"
|
||||
outputsub: "value out of range: 50 [RangeError]"
|
||||
exitcode: "1"
|
||||
"""
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
discard """
|
||||
file: "tsubrange.nim"
|
||||
outputsub: "value out of range: 50 [EOutOfRange]"
|
||||
outputsub: "value out of range: 50 [RangeError]"
|
||||
exitcode: "1"
|
||||
"""
|
||||
|
||||
@@ -16,4 +16,3 @@ var
|
||||
r = y
|
||||
|
||||
#p y
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ block orderedTableTest1:
|
||||
block countTableTest1:
|
||||
var s = data.toTable
|
||||
var t = initCountTable[string]()
|
||||
for k in s.Keys: t.inc(k)
|
||||
for k in s.keys: t.inc(k)
|
||||
for k in t.keys: assert t[k] == 1
|
||||
t.inc("90", 3)
|
||||
t.inc("12", 2)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
type pnode* = ref object of tobject
|
||||
type PNode* = ref object of RootObj
|
||||
|
||||
template litNode (name, ty): stmt =
|
||||
type name* = ref object of PNode
|
||||
@@ -8,7 +8,7 @@ litNode PIntNode, int
|
||||
|
||||
import json
|
||||
|
||||
template withKey*(j: PJsonNode; key: string; varname: expr;
|
||||
template withKey*(j: JsonNode; key: string; varname: expr;
|
||||
body:stmt): stmt {.immediate.} =
|
||||
if j.hasKey(key):
|
||||
let varname{.inject.}= j[key]
|
||||
|
||||
Reference in New Issue
Block a user