nimbus-eth1/hive_integration/nodocker/sim_utils.nim

52 lines
1.2 KiB
Nim
Raw Normal View History

# Nimbus
# Copyright (c) 2021 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
# at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
import
2022-04-20 07:57:50 +00:00
std/[tables, strutils, times],
../../nimbus/utils/utils,
2022-04-20 07:57:50 +00:00
unittest2
export
2022-04-20 07:57:50 +00:00
tables, strutils, unittest2
2022-04-20 07:57:50 +00:00
type
SimStat* = object
ok*: int
skipped*: int
failed*: int
2022-06-17 00:53:33 +00:00
failingCases*: seq[string]
2022-04-20 07:57:50 +00:00
proc inc*(stat: var SimStat, name: string, status: TestStatus) =
echo name, ", ", status
if status == OK:
inc stat.ok
elif status == SKIPPED:
inc stat.skipped
else:
inc stat.failed
2022-06-17 00:53:33 +00:00
stat.failingCases.add name
2022-04-20 07:57:50 +00:00
proc `$`*(stat: SimStat): string =
2022-07-04 05:35:03 +00:00
if stat.failingCases.len > 0:
result.add " - Failing Cases:\n"
for c in stat.failingCases:
result.add " - $1 \n" % [c]
2022-06-17 00:53:33 +00:00
result.add "ok: $1, skipped: $2, failed: $3" % [$stat.ok, $stat.skipped, $stat.failed]
2022-04-20 07:57:50 +00:00
proc print*(stat: SimStat, dur: Duration, name: string) =
var f = open(name & ".md", fmWrite)
f.write("* " & name)
f.write("\n")
f.write(" - " & $stat)
f.write("\n")
f.write(" - " & dur.short)
2022-04-20 07:57:50 +00:00
f.write("\n")
f.close()