Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
commit
3b6d831549
7 changed files with 78 additions and 14 deletions
|
|
@ -707,13 +707,13 @@ proc genMainProc(m: BModule) =
|
||||||
CommonMainBody & "}$n"
|
CommonMainBody & "}$n"
|
||||||
PosixCMain = "int main(int argc, char** args, char** env) {$n" &
|
PosixCMain = "int main(int argc, char** args, char** env) {$n" &
|
||||||
" cmdLine = args;$n" & " cmdCount = argc;$n" & " gEnv = env;$n" &
|
" cmdLine = args;$n" & " cmdCount = argc;$n" & " gEnv = env;$n" &
|
||||||
" NimMain();$n" & " return 0;$n" & "}$n"
|
" NimMain();$n" & " return nim_program_result;$n" & "}$n"
|
||||||
WinNimMain = "N_CDECL(void, NimMain)(void) {$n" &
|
WinNimMain = "N_CDECL(void, NimMain)(void) {$n" &
|
||||||
CommonMainBody & "}$n"
|
CommonMainBody & "}$n"
|
||||||
WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $n" &
|
WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $n" &
|
||||||
" HINSTANCE hPrevInstance, $n" &
|
" HINSTANCE hPrevInstance, $n" &
|
||||||
" LPSTR lpCmdLine, int nCmdShow) {$n" &
|
" LPSTR lpCmdLine, int nCmdShow) {$n" &
|
||||||
" NimMain();$n" & " return 0;$n" & "}$n"
|
" NimMain();$n" & " return nim_program_result;$n" & "}$n"
|
||||||
WinNimDllMain = "N_LIB_EXPORT N_CDECL(void, NimMain)(void) {$n" &
|
WinNimDllMain = "N_LIB_EXPORT N_CDECL(void, NimMain)(void) {$n" &
|
||||||
CommonMainBody & "}$n"
|
CommonMainBody & "}$n"
|
||||||
WinCDllMain =
|
WinCDllMain =
|
||||||
|
|
|
||||||
|
|
@ -331,6 +331,8 @@ typedef long long int NI64;
|
||||||
typedef unsigned int NU32;
|
typedef unsigned int NU32;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern NI nim_program_result;
|
||||||
|
|
||||||
typedef float NF32;
|
typedef float NF32;
|
||||||
typedef double NF64;
|
typedef double NF64;
|
||||||
typedef double NF;
|
typedef double NF;
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,18 @@
|
||||||
## It is loosely based on C++'s boost.test and Haskell's QuickTest
|
## It is loosely based on C++'s boost.test and Haskell's QuickTest
|
||||||
|
|
||||||
import
|
import
|
||||||
macros, terminal
|
macros, terminal, os
|
||||||
|
|
||||||
type
|
type
|
||||||
TestStatus* = enum OK, FAILED
|
TTestStatus* = enum OK, FAILED
|
||||||
# ETestFailed* = object of ESynch
|
TOutputLevel* = enum PRINT_ALL, PRINT_FAILURES, PRINT_NONE
|
||||||
|
|
||||||
var
|
var
|
||||||
# XXX: These better be thread-local
|
# XXX: These better be thread-local
|
||||||
AbortOnError* = false
|
AbortOnError*: bool
|
||||||
|
OutputLevel*: TOutputLevel
|
||||||
|
ColorOutput*: bool
|
||||||
|
|
||||||
checkpoints: seq[string] = @[]
|
checkpoints: seq[string] = @[]
|
||||||
|
|
||||||
template TestSetupIMPL*: stmt = nil
|
template TestSetupIMPL*: stmt = nil
|
||||||
|
|
@ -36,20 +39,29 @@ proc shouldRun(testName: string): bool =
|
||||||
|
|
||||||
template suite*(name: expr, body: stmt): stmt =
|
template suite*(name: expr, body: stmt): stmt =
|
||||||
block:
|
block:
|
||||||
template setup(setupBody: stmt): stmt =
|
template setup*(setupBody: stmt): stmt =
|
||||||
template TestSetupIMPL: stmt = setupBody
|
template TestSetupIMPL: stmt = setupBody
|
||||||
|
|
||||||
template teardown(teardownBody: stmt): stmt =
|
template teardown*(teardownBody: stmt): stmt =
|
||||||
template TestTeardownIMPL: stmt = teardownBody
|
template TestTeardownIMPL: stmt = teardownBody
|
||||||
|
|
||||||
body
|
body
|
||||||
|
|
||||||
proc printStatus*(s: TestStatus, name: string) =
|
proc testDone(name: string, s: TTestStatus) =
|
||||||
var color = (if s == OK: fgGreen else: fgRed)
|
if s == FAILED:
|
||||||
styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n"
|
program_result += 1
|
||||||
|
|
||||||
|
if OutputLevel != PRINT_NONE and (OutputLevel == PRINT_ALL or s == FAILED):
|
||||||
|
var color = (if s == OK: fgGreen else: fgRed)
|
||||||
|
|
||||||
|
if ColorOutput:
|
||||||
|
styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n"
|
||||||
|
else:
|
||||||
|
echo "[", $s, "] ", name, "\n"
|
||||||
|
|
||||||
template test*(name: expr, body: stmt): stmt =
|
template test*(name: expr, body: stmt): stmt =
|
||||||
bind shouldRun, checkPoints
|
bind shouldRun, checkpoints, testDone
|
||||||
|
|
||||||
if shouldRun(name):
|
if shouldRun(name):
|
||||||
checkpoints = @[]
|
checkpoints = @[]
|
||||||
var TestStatusIMPL = OK
|
var TestStatusIMPL = OK
|
||||||
|
|
@ -60,7 +72,7 @@ template test*(name: expr, body: stmt): stmt =
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
TestTeardownIMPL()
|
TestTeardownIMPL()
|
||||||
printStatus(TestStatusIMPL, name)
|
testDone name, TestStatusIMPL
|
||||||
|
|
||||||
proc checkpoint*(msg: string) =
|
proc checkpoint*(msg: string) =
|
||||||
checkpoints.add(msg)
|
checkpoints.add(msg)
|
||||||
|
|
@ -124,7 +136,8 @@ macro check*(conditions: stmt): stmt =
|
||||||
result = standardRewrite(conditions[1])
|
result = standardRewrite(conditions[1])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
error conditions.lineinfo & ": Malformed check statement"
|
var ast = conditions.treeRepr
|
||||||
|
error conditions.lineinfo & ": Malformed check statement:\n" & ast
|
||||||
|
|
||||||
template require*(conditions: stmt): stmt =
|
template require*(conditions: stmt): stmt =
|
||||||
block:
|
block:
|
||||||
|
|
@ -149,3 +162,15 @@ macro expect*(exp: stmt): stmt =
|
||||||
|
|
||||||
result = getAst(expectBody(errorTypes, exp.lineinfo, body))
|
result = getAst(expectBody(errorTypes, exp.lineinfo, body))
|
||||||
|
|
||||||
|
|
||||||
|
## Reading settings
|
||||||
|
var envOutLvl = os.getEnv("NIMTEST_OUTPUT_LVL").string
|
||||||
|
|
||||||
|
if envOutLvl.len > 0:
|
||||||
|
for opt in countup(low(TOutputLevel), high(TOutputLevel)):
|
||||||
|
if $opt == envOutLvl:
|
||||||
|
OutputLevel = opt
|
||||||
|
break
|
||||||
|
|
||||||
|
AbortOnError = existsEnv("NIMTEST_ABORT_ON_ERROR")
|
||||||
|
ColorOutput = not existsEnv("NIMTEST_NO_COLOR")
|
||||||
|
|
|
||||||
|
|
@ -1541,6 +1541,11 @@ const
|
||||||
## is the value that should be passed to ``quit`` to indicate
|
## is the value that should be passed to ``quit`` to indicate
|
||||||
## failure.
|
## failure.
|
||||||
|
|
||||||
|
var program_result* {.exportc: "nim_$1".} = QuitSuccess
|
||||||
|
## modify this varialbe to specify the exit code of the program
|
||||||
|
## under normal circumstances. when the program is terminated
|
||||||
|
## prematurelly using ``quit``, this value is ignored.
|
||||||
|
|
||||||
proc quit*(errorcode: int = QuitSuccess) {.
|
proc quit*(errorcode: int = QuitSuccess) {.
|
||||||
magic: "Exit", importc: "exit", noDecl, noReturn.}
|
magic: "Exit", importc: "exit", noDecl, noReturn.}
|
||||||
## stops the program immediately; before stopping the program the
|
## stops the program immediately; before stopping the program the
|
||||||
|
|
@ -2029,3 +2034,31 @@ proc slurp*(filename: string): string {.magic: "Slurp".}
|
||||||
## const myResource = slurp"mydatafile.bin"
|
## const myResource = slurp"mydatafile.bin"
|
||||||
##
|
##
|
||||||
|
|
||||||
|
proc `+=`*[T](x, y: ordinal[T]) {.magic: "Inc", noSideEffect.}
|
||||||
|
## Increments an ordinal
|
||||||
|
|
||||||
|
proc `-=`*[T](x, y: ordinal[T]) {.magic: "Dec", noSideEffect.}
|
||||||
|
## Decrements an ordinal
|
||||||
|
|
||||||
|
proc `*=`*[T](x: var ordinal[T], y: ordinal[T]) {.inline noSideEffect.} =
|
||||||
|
## Binary `*=` operator for oridinals
|
||||||
|
x = x * y
|
||||||
|
|
||||||
|
proc `+=` *(x: var float, y:float) {.inline noSideEffect.} =
|
||||||
|
## Increments in placee a floating point number
|
||||||
|
x = x + y
|
||||||
|
|
||||||
|
proc `-=` *(x: var float, y:float) {.inline noSideEffect.} =
|
||||||
|
## Decrements in place a floating point number
|
||||||
|
x = x - y
|
||||||
|
|
||||||
|
proc `*=` *(x: var float, y:float) {.inline noSideEffect.} =
|
||||||
|
## Multiplies in place a floating point number
|
||||||
|
x = x * y
|
||||||
|
|
||||||
|
proc `/=` *(x: var float, y:float) {.inline noSideEffect.} =
|
||||||
|
## Divides in place a floating point number
|
||||||
|
x = x / y
|
||||||
|
|
||||||
|
proc `&=`* (x: var string, y: string) {.magic: "AppendStrStr", noSideEffect.}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -391,6 +391,9 @@ proc outputJSON(reject, compile, run: TResults) =
|
||||||
writeFile(jsonFile, s)
|
writeFile(jsonFile, s)
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
|
os.putenv "NIMTEST_NO_COLOR", "1"
|
||||||
|
os.putenv "NIMTEST_OUTPUT_LVL", "PRINT_FAILURES"
|
||||||
|
|
||||||
const
|
const
|
||||||
compileJson = "compile.json"
|
compileJson = "compile.json"
|
||||||
runJson = "run.json"
|
runJson = "run.json"
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ Library Additions
|
||||||
- Added ``strutils.unindent``, ``strutils.countLines``.
|
- Added ``strutils.unindent``, ``strutils.countLines``.
|
||||||
- Added ``system.slurp`` for easy resource embedding.
|
- Added ``system.slurp`` for easy resource embedding.
|
||||||
- Added ``system.running`` for threads.
|
- Added ``system.running`` for threads.
|
||||||
|
- Added ``system.program_result``.
|
||||||
- Added ``xmltree.innerText``.
|
- Added ``xmltree.innerText``.
|
||||||
- Added ``os.isAbsolute``, ``os.dynLibFormat``.
|
- Added ``os.isAbsolute``, ``os.dynLibFormat``.
|
||||||
- Added ``parseutils.interpolatedFragments``.
|
- Added ``parseutils.interpolatedFragments``.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue