logos-storage-nim/tests/imports.nim
2026-06-17 22:35:25 +04:00

30 lines
770 B
Nim

import std/macros
import std/os
import std/strutils
macro importTests*(dir: static string, exclude: static string): untyped =
## imports every test*.nim file under `dir` (recursively).
## `exclude`, when non-empty, skips files whose path contains it.
let imports = newStmtList()
for file in walkDirRec(dir):
let (_, name, ext) = splitFile(file)
if not (name.startsWith("test") and ext == ".nim"):
continue
if exclude.len > 0 and exclude in file:
continue
imports.add(
quote do:
import `file`
)
imports
macro importAll*(paths: static seq[string]): untyped =
## imports all specified paths
let imports = newStmtList()
for path in paths:
imports.add(
quote do:
import `path`
)
imports