Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions nimble.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ when defined(nimdistros):
before install:
exec "git submodule update --init"

task test, "Run the Nimble tester!":
#Find params that are a test name
proc runTester(extraFlags = "") =
var extraParams = ""
for i in 0 .. paramCount():
if "::" in paramStr(i):
extraParams = "test "
extraParams = "test "
extraParams.addQuoted paramStr(i)

withDir "tests":
exec "nim c -r tester " & extraParams
withDir "tests":
exec "nim c " & extraFlags & " -r tester " & extraParams

task test, "Run the Nimble tester!":
runTester()

task cibenchmark, "Run tests with timing instrumentation":
runTester("-d:timedTests")
53 changes: 53 additions & 0 deletions tests/testscommon.nim
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,56 @@ block:
# Verbose name is used for exit code so assert is clearer
let (output, nimbleCompileExitCode) = execCmdEx("nim c " & nimbleCompilePath)
doAssert nimbleCompileExitCode == QuitSuccess, output

# Test timing instrumentation — compile with -d:timedTests to enable
when defined(timedTests):
import std/times, std/algorithm, std/exitprocs

type
TestTiming = object
suite: string
test: string
duration: Duration

TimingFormatter = ref object of OutputFormatter
currentSuite: string
suiteStart: DateTime
testStart: DateTime
timings: seq[TestTiming]

method suiteStarted(f: TimingFormatter, suiteName: string) =
f.currentSuite = suiteName
f.suiteStart = times.now()

method testStarted(f: TimingFormatter, testName: string) =
f.testStart = times.now()

method testEnded(f: TimingFormatter, testResult: TestResult) =
f.timings.add(TestTiming(
suite: f.currentSuite,
test: testResult.testName,
duration: times.now() - f.testStart))

method suiteEnded(f: TimingFormatter) =
f.timings.add(TestTiming(
suite: f.currentSuite,
test: "[total]",
duration: times.now() - f.suiteStart))

var timingFmt = TimingFormatter()
addOutputFormatter(timingFmt)

proc printTimingReport() =
var sorted = timingFmt.timings.filterIt(it.duration.inMilliseconds > 0)
sorted.sort proc(a, b: TestTiming): int = cmp(b.duration, a.duration)
echo ""
echo "=== Test Timing Report (slowest first) ==="
for t in sorted:
let ms = t.duration.inMilliseconds
if t.test == "[total]":
echo &" [{ms:>8}ms] SUITE: {t.suite}"
else:
echo &" [{ms:>8}ms] {t.suite} > {t.test}"
echo "==========================================="

addExitProc printTimingReport