Skip to content
Open
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
24 changes: 18 additions & 6 deletions bdd.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
# todo: extract this to a separate package
# todo: think through how to auto-clean up stuff created during tests
# ^ think testament auto sets d:testing which can help with this
# ^^ use a pragma to change the appname: https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-compileminustime-define-pragmas
# ^ also make note about native nimlang procs, e.g. tryRemoveFile returns bool
# see if we can integrate with https://github.com/binhonglee/coco


import std/sugar

Expand All @@ -20,6 +23,13 @@ type BddDefect = ref object of Defect
var failure = BddDefect(msg: "Invalid Test Parameters") ## \
## escape hatch to fail a test early

# TODO: i think pushing these pragmas reduces test speed signficantly
{.hints: off,
optimization: speed,
push checks: off,
stackTrace: on,
warnings: off.}

proc assertCondition(
condition: bool,
matches: bool,
Expand Down Expand Up @@ -48,21 +58,21 @@ proc itShouldNot*(
## prefer creating a test case with bdd
assertCondition condition, false, name, msg

type What* = enum
type ShouldWhat* = enum
## expected result of some condition
should, ## be true
shouldNot, ## be true
shouldNotRaise, ## error when called
shouldNotRaiseMsg, ## but should raise a different msg when called
shouldRaise, ## error when called
shouldRaiseMsg, ## when called
shouldNotRaiseMsg, ## but should raise a different msg when called

proc bdd*(caseName: string): (What, string, () -> bool) -> void =
proc bdd*(caseName: string): (ShouldWhat, string, () -> bool) -> void =
## simple assertions for use with testament
## provide a test name and receive a fn that
## validates condition matches expectation
(what: What, msg: string, condition: () -> bool) => (
case what
(ShouldWhat: ShouldWhat, msg: string, condition: () -> bool) => (
case ShouldWhat
of should: itShould msg, condition(), caseName
of shouldNot: itShouldNot msg, condition(), caseName
of
Expand All @@ -77,14 +87,16 @@ proc bdd*(caseName: string): (What, string, () -> bool) -> void =
didRaise = true
msgRaised = getCurrentExceptionMsg()
finally:
case what:
case ShouldWhat:
of shouldNotRaise: itShouldNot msg, didRaise, caseName
of shouldNotRaiseMsg: itShould msg, didRaise and msgRaised != msg, caseName
of shouldRaise: itShould msg, didRaise, caseName
of shouldRaiseMsg: itShould msg, didRaise and msgRaised == msg, caseName
else: raise failure
)

{.pop.}

export sugar

when isMainModule:
Expand Down
4 changes: 3 additions & 1 deletion config.nims
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
--debugger:native
--deepcopy:on
--deepcopy:on # required for mm:orc/arc
--define:nimPreviewHashRef
--define:nimStrictDelete
--define:ssl
--define:threadsafe
--experimental:strictEffects
--hints:on
--mm:orc
--multimethods:on
Expand All @@ -13,6 +14,7 @@
--threads:on
--tlsEmulation:on
--warnings:on
# --panics:on # we need to rework logic to guard against defects

case getCommand():
of "c", "cc", "cpp", "objc":
Expand Down
1 change: 1 addition & 0 deletions src/boat/private/boatConfig.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type BoatConfig* = ref object of RootObj
## base type for all boat configs
use*: string ## \
## file / dir / remote uri pointing to a manifest.nim.ini
## try parsed* with the type alias again: https://forum.nim-lang.org/t/10023

proc usePath*(self: BoatConfig, path: string = ""): string =
## returns path if not empty, else self.use
Expand Down
5 changes: 4 additions & 1 deletion src/boat/private/fileManagerUtils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import std/[

import boatErrors, boatConstants

type FileTypes* = Config | JsonNode | string
type Encodable* = JsonNode | string
type FileTypes* = Config | JsonNode | string

proc persist*[T: FileTypes](self: T, path: string): Future[void] {.async.} =
## persists a FileType to path
Expand Down Expand Up @@ -73,6 +73,9 @@ proc encode*[T: Encodable](self: T): string =
# of string -> base64

proc decode*[T: Encodable](self: T): T = raise tddError
# parse to string ->
# if json parse to and return json
# else return string

export
asyncdispatch,
Expand Down
82 changes: 41 additions & 41 deletions src/htmldocs/_._/bdd.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/htmldocs/_._/bdd.idx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/htmldocs/boat.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading