Clean up tests/stdlib
2 tests still fail: - tircbot would need a benign pragma because of the locks - tgetfileinfo uses os.getFileInfo() on nil, which segfaults instead of throwing an exception as the tester expects
This commit is contained in:
parent
1b91b3a2a5
commit
e0ae9f5248
3 changed files with 37 additions and 33 deletions
|
|
@ -4,7 +4,7 @@ import dialogs, gtk2
|
||||||
|
|
||||||
gtk2.nimrod_init()
|
gtk2.nimrod_init()
|
||||||
|
|
||||||
var x = ChooseFilesToOpen(nil)
|
var x = chooseFilesToOpen(nil)
|
||||||
for a in items(x):
|
for a in items(x):
|
||||||
writeln(stdout, a)
|
writeln(stdout, a)
|
||||||
|
|
||||||
|
|
@ -12,6 +12,6 @@ info(nil, "start with an info box")
|
||||||
warning(nil, "now a warning ...")
|
warning(nil, "now a warning ...")
|
||||||
error(nil, "... and an error!")
|
error(nil, "... and an error!")
|
||||||
|
|
||||||
writeln(stdout, ChooseFileToOpen(nil))
|
writeln(stdout, chooseFileToOpen(nil))
|
||||||
writeln(stdout, ChooseFileToSave(nil))
|
writeln(stdout, chooseFileToSave(nil))
|
||||||
writeln(stdout, ChooseDir(nil))
|
writeln(stdout, chooseDir(nil))
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ proc caseOneAndTwo(followLink: bool) =
|
||||||
try:
|
try:
|
||||||
discard getFileInfo(getAppFilename(), followLink)
|
discard getFileInfo(getAppFilename(), followLink)
|
||||||
#echo("String : Existing File : Symlink $# : Success" % $followLink)
|
#echo("String : Existing File : Symlink $# : Success" % $followLink)
|
||||||
except EOS:
|
except OSError:
|
||||||
echo("String : Existing File : Symlink $# : Failure" % $followLink)
|
echo("String : Existing File : Symlink $# : Failure" % $followLink)
|
||||||
|
|
||||||
proc caseThreeAndFour(followLink: bool) =
|
proc caseThreeAndFour(followLink: bool) =
|
||||||
|
|
@ -40,7 +40,8 @@ proc caseThreeAndFour(followLink: bool) =
|
||||||
try:
|
try:
|
||||||
discard getFileInfo(invalidName, true)
|
discard getFileInfo(invalidName, true)
|
||||||
echo("String : Non-existing File : Symlink $# : Failure" % $followLink)
|
echo("String : Non-existing File : Symlink $# : Failure" % $followLink)
|
||||||
except EOS:
|
except OSError:
|
||||||
|
discard
|
||||||
#echo("String : Non-existing File : Symlink $# : Success" % $followLink)
|
#echo("String : Non-existing File : Symlink $# : Success" % $followLink)
|
||||||
|
|
||||||
proc testGetFileInfo =
|
proc testGetFileInfo =
|
||||||
|
|
@ -82,12 +83,14 @@ proc testGetFileInfo =
|
||||||
discard getFileInfo(testFile)
|
discard getFileInfo(testFile)
|
||||||
echo("Handle : Invalid File : Failure")
|
echo("Handle : Invalid File : Failure")
|
||||||
except EIO, EOS:
|
except EIO, EOS:
|
||||||
|
discard
|
||||||
#echo("Handle : Invalid File : Success")
|
#echo("Handle : Invalid File : Success")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
discard getFileInfo(testHandle)
|
discard getFileInfo(testHandle)
|
||||||
echo("Handle : Invalid File : Failure")
|
echo("Handle : Invalid File : Failure")
|
||||||
except EIO, EOS:
|
except EIO, EOS:
|
||||||
|
discard
|
||||||
#echo("Handle : Invalid File : Success")
|
#echo("Handle : Invalid File : Success")
|
||||||
|
|
||||||
testGetFileInfo()
|
testGetFileInfo()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import irc, sockets, asyncio, json, os, strutils, times, redis
|
||||||
|
|
||||||
type
|
type
|
||||||
TDb* = object
|
TDb* = object
|
||||||
r*: TRedis
|
r*: Redis
|
||||||
lastPing: float
|
lastPing: float
|
||||||
|
|
||||||
TBuildResult* = enum
|
TBuildResult* = enum
|
||||||
|
|
@ -15,20 +15,20 @@ type
|
||||||
|
|
||||||
TCommit* = object
|
TCommit* = object
|
||||||
commitMsg*, username*, hash*: string
|
commitMsg*, username*, hash*: string
|
||||||
date*: TTime
|
date*: Time
|
||||||
|
|
||||||
TPlatform* = object
|
TPlatform* = object
|
||||||
buildResult*: TBuildResult
|
buildResult*: TBuildResult
|
||||||
testResult*: TTestResult
|
testResult*: TTestResult
|
||||||
failReason*, platform*: string
|
failReason*, platform*: string
|
||||||
total*, passed*, skipped*, failed*: biggestInt
|
total*, passed*, skipped*, failed*: BiggestInt
|
||||||
csources*: bool
|
csources*: bool
|
||||||
|
|
||||||
const
|
const
|
||||||
listName = "commits"
|
listName = "commits"
|
||||||
failOnExisting = False
|
failOnExisting = false
|
||||||
|
|
||||||
proc open*(host = "localhost", port: TPort): TDb =
|
proc open*(host = "localhost", port: Port): TDb =
|
||||||
result.r = redis.open(host, port)
|
result.r = redis.open(host, port)
|
||||||
result.lastPing = epochTime()
|
result.lastPing = epochTime()
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ proc getCommits*(database: TDb,
|
||||||
for key, value in database.r.hPairs(c):
|
for key, value in database.r.hPairs(c):
|
||||||
case normalize(key)
|
case normalize(key)
|
||||||
of "commitmsg": commit.commitMsg = value
|
of "commitmsg": commit.commitMsg = value
|
||||||
of "date": commit.date = TTime(parseInt(value))
|
of "date": commit.date = Time(parseInt(value))
|
||||||
of "username": commit.username = value
|
of "username": commit.username = value
|
||||||
else:
|
else:
|
||||||
echo(key)
|
echo(key)
|
||||||
|
|
@ -157,21 +157,21 @@ proc `[]`*(p: seq[TPlatform], name: string): TPlatform =
|
||||||
for platform in items(p):
|
for platform in items(p):
|
||||||
if platform.platform == name:
|
if platform.platform == name:
|
||||||
return platform
|
return platform
|
||||||
raise newException(EInvalidValue, name & " platforms not found in commits.")
|
raise newException(ValueError, name & " platforms not found in commits.")
|
||||||
|
|
||||||
proc contains*(p: seq[TPlatform], s: string): bool =
|
proc contains*(p: seq[TPlatform], s: string): bool =
|
||||||
for i in items(p):
|
for i in items(p):
|
||||||
if i.platform == s:
|
if i.platform == s:
|
||||||
return True
|
return true
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
PState = ref TState
|
PState = ref TState
|
||||||
TState = object of TObject
|
TState = object of RootObj
|
||||||
dispatcher: PDispatcher
|
dispatcher: Dispatcher
|
||||||
sock: PAsyncSocket
|
sock: AsyncSocket
|
||||||
ircClient: PAsyncIRC
|
ircClient: PAsyncIRC
|
||||||
hubPort: TPort
|
hubPort: Port
|
||||||
database: TDb
|
database: TDb
|
||||||
dbConnected: bool
|
dbConnected: bool
|
||||||
|
|
||||||
|
|
@ -181,7 +181,7 @@ type
|
||||||
TSeen = object
|
TSeen = object
|
||||||
nick: string
|
nick: string
|
||||||
channel: string
|
channel: string
|
||||||
timestamp: TTime
|
timestamp: Time
|
||||||
case kind*: TSeenType
|
case kind*: TSeenType
|
||||||
of PSeenJoin: nil
|
of PSeenJoin: nil
|
||||||
of PSeenPart, PSeenQuit, PSeenMsg:
|
of PSeenPart, PSeenQuit, PSeenMsg:
|
||||||
|
|
@ -218,11 +218,12 @@ proc getSeen(d: TDb, nick: string, s: var TSeen): bool =
|
||||||
for key, value in d.r.hPairs("seen:" & nick):
|
for key, value in d.r.hPairs("seen:" & nick):
|
||||||
case normalize(key)
|
case normalize(key)
|
||||||
of "type":
|
of "type":
|
||||||
|
discard
|
||||||
#s.kind = value.parseInt.TSeenType
|
#s.kind = value.parseInt.TSeenType
|
||||||
of "channel":
|
of "channel":
|
||||||
s.channel = value
|
s.channel = value
|
||||||
of "timestamp":
|
of "timestamp":
|
||||||
s.timestamp = TTime(value.parseInt)
|
s.timestamp = Time(value.parseInt)
|
||||||
of "msg":
|
of "msg":
|
||||||
s.msg = value
|
s.msg = value
|
||||||
of "newnick":
|
of "newnick":
|
||||||
|
|
@ -235,7 +236,7 @@ template createSeen(typ: TSeenType, n, c: string): stmt {.immediate, dirty.} =
|
||||||
seenNick.channel = c
|
seenNick.channel = c
|
||||||
seenNick.timestamp = getTime()
|
seenNick.timestamp = getTime()
|
||||||
|
|
||||||
proc parseReply(line: string, expect: string): Bool =
|
proc parseReply(line: string, expect: string): bool =
|
||||||
var jsonDoc = parseJson(line)
|
var jsonDoc = parseJson(line)
|
||||||
return jsonDoc["reply"].str == expect
|
return jsonDoc["reply"].str == expect
|
||||||
|
|
||||||
|
|
@ -272,14 +273,14 @@ proc handleWebMessage(state: PState, line: string) =
|
||||||
message.add(limitCommitMsg(commit["message"].str))
|
message.add(limitCommitMsg(commit["message"].str))
|
||||||
|
|
||||||
# Send message to #nim.
|
# Send message to #nim.
|
||||||
state.ircClient.privmsg(joinChans[0], message)
|
discard state.ircClient.privmsg(joinChans[0], message)
|
||||||
elif json.hasKey("redisinfo"):
|
elif json.hasKey("redisinfo"):
|
||||||
assert json["redisinfo"].hasKey("port")
|
assert json["redisinfo"].hasKey("port")
|
||||||
#let redisPort = json["redisinfo"]["port"].num
|
#let redisPort = json["redisinfo"]["port"].num
|
||||||
state.dbConnected = true
|
state.dbConnected = true
|
||||||
|
|
||||||
proc hubConnect(state: PState)
|
proc hubConnect(state: PState)
|
||||||
proc handleConnect(s: PAsyncSocket, state: PState) =
|
proc handleConnect(s: AsyncSocket, state: PState) =
|
||||||
try:
|
try:
|
||||||
# Send greeting
|
# Send greeting
|
||||||
var obj = newJObject()
|
var obj = newJObject()
|
||||||
|
|
@ -295,7 +296,7 @@ proc handleConnect(s: PAsyncSocket, state: PState) =
|
||||||
doAssert parseReply(line, "OK")
|
doAssert parseReply(line, "OK")
|
||||||
echo("The hub accepted me!")
|
echo("The hub accepted me!")
|
||||||
else:
|
else:
|
||||||
raise newException(EInvalidValue,
|
raise newException(ValueError,
|
||||||
"Hub didn't accept me. Waited 1.5 seconds.")
|
"Hub didn't accept me. Waited 1.5 seconds.")
|
||||||
|
|
||||||
# ask for the redis info
|
# ask for the redis info
|
||||||
|
|
@ -303,35 +304,35 @@ proc handleConnect(s: PAsyncSocket, state: PState) =
|
||||||
riobj["do"] = newJString("redisinfo")
|
riobj["do"] = newJString("redisinfo")
|
||||||
state.sock.send($riobj & "\c\L")
|
state.sock.send($riobj & "\c\L")
|
||||||
|
|
||||||
except EOS:
|
except OsError:
|
||||||
echo(getCurrentExceptionMsg())
|
echo(getCurrentExceptionMsg())
|
||||||
s.close()
|
s.close()
|
||||||
echo("Waiting 5 seconds...")
|
echo("Waiting 5 seconds...")
|
||||||
sleep(5000)
|
sleep(5000)
|
||||||
state.hubConnect()
|
state.hubConnect()
|
||||||
|
|
||||||
proc handleRead(s: PAsyncSocket, state: PState) =
|
proc handleRead(s: AsyncSocket, state: PState) =
|
||||||
var line = ""
|
var line = ""
|
||||||
if state.sock.recvLine(line):
|
if state.sock.recvLine(line):
|
||||||
if line != "":
|
if line != "":
|
||||||
# Handle the message
|
# Handle the message
|
||||||
state.handleWebMessage(line)
|
state.handleWebMessage(line)
|
||||||
else:
|
else:
|
||||||
echo("Disconnected from hub: ", OSErrorMsg())
|
echo("Disconnected from hub: ", osErrorMsg())
|
||||||
s.close()
|
s.close()
|
||||||
echo("Reconnecting...")
|
echo("Reconnecting...")
|
||||||
state.hubConnect()
|
state.hubConnect()
|
||||||
else:
|
else:
|
||||||
echo(OSErrorMsg())
|
echo(osErrorMsg())
|
||||||
|
|
||||||
proc hubConnect(state: PState) =
|
proc hubConnect(state: PState) =
|
||||||
state.sock = AsyncSocket()
|
state.sock = asyncSocket()
|
||||||
state.sock.connect("127.0.0.1", state.hubPort)
|
state.sock.connect("127.0.0.1", state.hubPort)
|
||||||
state.sock.handleConnect =
|
state.sock.handleConnect =
|
||||||
proc (s: PAsyncSocket) =
|
proc (s: AsyncSocket) =
|
||||||
handleConnect(s, state)
|
handleConnect(s, state)
|
||||||
state.sock.handleRead =
|
state.sock.handleRead =
|
||||||
proc (s: PAsyncSocket) =
|
proc (s: AsyncSocket) =
|
||||||
handleRead(s, state)
|
handleRead(s, state)
|
||||||
|
|
||||||
state.dispatcher.register(state.sock)
|
state.dispatcher.register(state.sock)
|
||||||
|
|
@ -426,7 +427,7 @@ proc handleIrc(irc: PAsyncIRC, event: TIRCEvent, state: PState) =
|
||||||
else:
|
else:
|
||||||
discard # TODO: ?
|
discard # TODO: ?
|
||||||
|
|
||||||
proc open(port: TPort = TPort(5123)): PState =
|
proc open(port: Port = Port(5123)): PState =
|
||||||
var res: PState
|
var res: PState
|
||||||
new(res)
|
new(res)
|
||||||
res.dispatcher = newDispatcher()
|
res.dispatcher = newDispatcher()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue