made some tests green

This commit is contained in:
Araq 2014-08-31 12:34:35 +02:00
commit ae548a696f
8 changed files with 28 additions and 29 deletions

View file

@ -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')

View file

@ -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