diff --git a/bdd.nim b/bdd.nim index 8dcd441..421aae7 100644 --- a/bdd.nim +++ b/bdd.nim @@ -51,20 +51,21 @@ proc bdd*(caseName: string): (What, string, () -> bool) -> void = of should: itShould msg, caseName, condition() of shouldNot: itShouldNot msg, caseName, condition() of shouldRaise, shouldNotRaise: - var didError = false + var didRaise = false try: discard condition() - except CatchableError, OSError: didError = true + except CatchableError, OSError: didRaise = true finally: - if what.ord == shouldRaise.ord: itShould msg, caseName, didError - else: itShouldNot msg, caseName, didError + if what.ord == shouldRaise.ord: itShould msg, caseName, didRaise + else: itShouldNot msg, caseName, didRaise ) when isMainModule: - proc catchme: bool = raise newException(CatchableError, "if you can") - let it = bdd "bdd tests" + proc catchme: bool = raise TddError(msg: "if you can") + let it = bdd "bdd tests" it should, "be true", () => true it shouldNot, "be true", () => false it shouldRaise, "error", () => catchme() it shouldNotRaise, "error", () => true + it shouldNotRaise, "or care about result", () => false diff --git a/src/boat.dot b/src/boat.dot index a80bcf2..fc867dd 100644 --- a/src/boat.dot +++ b/src/boat.dot @@ -26,66 +26,4 @@ digraph boat { "system/io" -> "std/private/since"; "system/io" -> "system/formatfloat"; "system" -> "system/io"; -"std/os" -> "std/private/since"; -"std/strutils" -> "std/parseutils"; -"std/math" -> "std/private/since"; -"std/macros" -> "std/private/since"; -"std/bitops" -> "std/macros"; -"std/bitops" -> "std/private/since"; -"std/bitops" -> "std/private/bitops_utils"; -"std/bitops" -> "system/countbits_impl"; -"std/math" -> "std/bitops"; -"std/math" -> "std/fenv"; -"std/strutils" -> "std/math"; -"std/algorithm" -> "std/private/since"; -"std/strutils" -> "std/algorithm"; -"std/enumutils" -> "std/macros"; -"std/typetraits" -> "std/private/since"; -"std/typetraits" -> "std/macros"; -"std/enumutils" -> "std/typetraits"; -"std/strutils" -> "std/enumutils"; -"std/strutils" -> "std/unicode"; -"std/strutils" -> "std/private/since"; -"std/strutils" -> "std/private/strimpl"; -"std/pathnorm" -> "std/osseps"; -"std/os" -> "std/strutils"; -"std/os" -> "std/pathnorm"; -"std/options" -> "std/typetraits"; -"std/times" -> "std/strutils"; -"std/times" -> "std/math"; -"std/times" -> "std/options"; -"std/times" -> "std/private/since"; -"std/times" -> "std/posix"; -"std/os" -> "std/posix"; -"std/os" -> "std/times"; -"boat/private/BoatConstants" -> "std/os"; -"boat/private/BoatConstants" -> "boat/private/BoatErrors"; -"std/sugar" -> "std/private/since"; -"std/sugar" -> "std/macros"; -"std/private/underscored_calls" -> "std/macros"; -"std/sugar" -> "std/private/underscored_calls"; -"../bdd" -> "std/sugar"; -"boat/private/Config" -> "../bdd"; -"std/streams" -> "std/private/since"; -"std/lexbase" -> "std/strutils"; -"std/lexbase" -> "std/streams"; -"std/tables" -> "std/private/since"; -"std/hashes" -> "std/private/since"; -"std/tables" -> "std/hashes"; -"std/tables" -> "std/math"; -"std/tables" -> "std/algorithm"; -"std/parsecfg" -> "std/strutils"; -"std/parsecfg" -> "std/lexbase"; -"std/parsecfg" -> "std/streams"; -"std/parsecfg" -> "std/tables"; -"std/parsecfg" -> "std/private/decode_helpers"; -"std/parsecfg" -> "std/private/since"; -"boat/private/Config" -> "std/os"; -"boat/private/Config" -> "std/parsecfg"; -"boat/private/Config" -> "std/strutils"; -"boat/private/Config" -> "boat/private/BoatErrors"; -"boat/private/Config" -> "boat/private/BoatConstants"; -"boat" -> "boat/private/BoatConstants"; -"boat" -> "boat/private/BoatErrors"; -"boat" -> "boat/private/Config"; } diff --git a/src/boat.nim b/src/boat.nim index 82f084b..6e2c435 100644 --- a/src/boat.nim +++ b/src/boat.nim @@ -1,11 +1,5 @@ ## .. include:: ./readme.rst -import boat/private/[ - boatConfig, - boatConstants, - boatErrors, -] - proc boat*: void = echo "All HANDS! cat o'nine tails! blue peter! OMG... landlubber" when isMainModule: diff --git a/src/boat.png b/src/boat.png index b480e56..78468bf 100644 Binary files a/src/boat.png and b/src/boat.png differ diff --git a/src/boat/private/boatConfig.nim b/src/boat/private/boatConfig.nim index 5b1873a..6e5bcc9 100644 --- a/src/boat/private/boatConfig.nim +++ b/src/boat/private/boatConfig.nim @@ -7,10 +7,6 @@ ## TLDR - come back later -todos ------ -- cmd to parse arbitrarily, e.g. boat conf load ./some/dir -- cmd to see current captains: e.g. boat conf list -> X, Y, Z ]## from ../../../bdd import tddError @@ -31,15 +27,12 @@ import var captainsLog* {.global.} = %* {} ## \ ## captains log is the world -proc parseLocalManifest*(self: BoatConfig, path: string = ""): bool = - ## parse self.use to self.parsed - ## prefer calling self.load or self.reload for validation - let usePath = self.usePath path - - # self.parsed = self.parsed.retrieve usePath +proc parseManifest*(self: BoatConfig, path: string = "", ft: FileType): bool = + ## sets self.parsed to the parsed manifest + self.parsed = ft.retrieve self.usePath path result = true -proc localManifestIsValid*(self: BoatConfig, path: string = ""): bool = +proc manifestIsValid*(self: BoatConfig, path: string = ""): bool = ## throws if manifest not found, cant be read, or errors during parsing let usePath = self.usePath path let pathInfo = usePath.getFileInfo @@ -48,12 +41,12 @@ proc localManifestIsValid*(self: BoatConfig, path: string = ""): bool = of pcFile, pcLinkToFile: if fpUserRead notin pathInfo.permissions: raise filePermissionError elif not usePath.endsWith manifestName: raise manifestNameError - elif not self.parseLocalManifest usePath: raise configParseError + elif not self.parseManifest(usePath, localManifest): raise configParseError else: true of pcDir, pcLinkToDir: # force directories to use their manifest self.use = self.use / manifestName - self.localManifestIsValid() + self.manifestIsValid proc save*(self: BoatConfig, path: string = ""): bool = ## serialize Self.parsed to disk @ boatConstants.cacheDir / .{manifestName} @@ -61,49 +54,40 @@ proc save*(self: BoatConfig, path: string = ""): bool = # should call fileManager.toDisk result = true -proc init*(self: BoatConfig, path: string = ""): bool = - let usePath = self.usePath path +proc init*(self: BoatConfig): bool = # starts with https? # ends with manifestName? - # save to boatConstants.tempDir / self.use - # recurse self.reload path = temp location + # check FileManagerUtils.retrieve + # it should contain logic for loading remote manifests # throw: urls must point to a manifest.nim.ini - case usePath.startsWith "https" + case self.use.startsWith "https" of true: raise tddError else: - try: doAssert self.localManifestIsValid(path) == true + try: doAssert self.manifestIsValid == true except CatchableError: debugEcho repr getCurrentException() raise fileLoadError - if not self.save usePath: raise fileSaveDefect + if not self.save: raise fileSaveDefect else: result = true proc reload*(self: BoatConfig): bool = - ## reloads a configuration from disk - # (fpath, T) = FileMananger.fromDisk(...) - # self.parsedPath = fpath, self.parsed = T + ## reloads a configuration from captainsLog raise tddError proc load*(self: BoatConfig): bool = - ## (re)load a Configuration; safer than calling reload specifically + ## (re)load a Configuration result = - if captainsLogLoaded and self.parsedPath.len is Positive: self.reload() - else: self.init() + # if self.use in captainsLog ? reload from captainslog + if 1 > 2: raise tddError + else: self.init proc loadCaptainsLog(): void = ## loads the previous or initializes a new captains log - if not captainsLogLoaded: echo "loading captains log" - # captainsLogLoaded = true - # let (fpath, prevCaptainsLog) = captainsLog.fromDisk(cacheDir / manifestName, JsonNode, false) - # captainsLog = prevCaptainsLog + captainsLogLoaded = true + # try to retrieve the prev captainslog from cachDir + # else initialize an empty captainslog # always load the captainsLog into ram if not captainsLogLoaded: loadCaptainsLog() - -# consumers can retrieve the parsed Config and path on disk -# but only internal functions should be able to set it -export - boatConfigType.BoatConfig, - parsed, - parsedPath +export boatConfigType diff --git a/src/boat/private/boatConfigType.nim b/src/boat/private/boatConfigType.nim index 5257010..e9337b2 100644 --- a/src/boat/private/boatConfigType.nim +++ b/src/boat/private/boatConfigType.nim @@ -6,21 +6,10 @@ type BoatConfig*[T: BoatConfigKind = Config] = ref object of RootObj ## base type for all boat configs use*: string ## \ ## filepath, dir containing a file or remote uri - - parsed: T ## \ - ## the parsed config after loading - parsedPath: string ## \ + parsed*: T ## \ + ## the parsed config if the config has been parsed + parsedPath*: string ## \ ## path on disk the parsed config was saved to -proc `parsed=`*(self: BoatConfig, path: string): void = - self.parsed = self.parsed.retrieve path - -proc `parsed`*(self: BoatConfig): BoatConfigKind = self.parsed - -proc `parsedPath=`*(self: BoatConfig, path: string): void = - self.parsedPath = path - -proc `parsedPath`*(self: BoatConfig): string = self.parsedPath - -proc usePath*(self: BoatConfig, path: string): string = +proc usePath*(self: BoatConfig, path: string = ""): string = if path.len is Positive: path else: self.use diff --git a/src/boat/private/boatConstants.nim b/src/boat/private/boatConstants.nim index f4e8b4c..7df30b2 100644 --- a/src/boat/private/boatConstants.nim +++ b/src/boat/private/boatConstants.nim @@ -10,7 +10,9 @@ from parsecfg import Config import boatErrors -type BoatConfigKind* = Config | JsonNode +type BoatConfigKind* = Config | JsonNode ## \ + ## a Config generally means a manifest + ## while JsonNode indicates a captainslog var captainsLogLoaded* {.global.} = false ## \ ## true if we've loaded the captains log from disk into ram diff --git a/src/boat/private/boatErrors.nim b/src/boat/private/boatErrors.nim index df2e477..7c71d4b 100644 --- a/src/boat/private/boatErrors.nim +++ b/src/boat/private/boatErrors.nim @@ -20,4 +20,4 @@ type BoatDefect = ref object of Defect ## \ var dirCreateDefect* = BoatDefect(msg: "Dir Create Failed") var fileLoadDefect* = BoatDefect(msg: "Cant Load File") var fileSaveDefect* = BoatDefect(msg: "Cant Save File") -var boatConfigKindError* = BoatDefect(msg: fmt"Expected BoatConfigKind") +var boatConfigKindError* = BoatDefect(msg: fmt"Expected typeof BoatConfigKind") diff --git a/src/boat/private/fileManager.nim b/src/boat/private/fileManager.nim index 57f2762..e76b30d 100644 --- a/src/boat/private/fileManager.nim +++ b/src/boat/private/fileManager.nim @@ -5,29 +5,25 @@ from ../../../bdd import tddError -import std/[ - locks, - threadpool, -] +# import std/[ +# locks, +# threadpool, +# ] import boatConstants, boatErrors, fileManagerUtils -type SaveType* = enum - parsedConfig, - captainsLog, - remoteManifest, -proc dir*(self: SaveType): string = - ## returns the directory where different SaveTypes are persisted +proc dir*(self: FileType): string = + ## returns the directory where different FileTypes are persisted result = case self - of parsedConfig, captainsLog: cacheDir + of localManifest, captainsLog: cacheDir else: tempDir -proc path*(self: SaveType, fname: string): string = - ## computes the filpath for a SaveType +proc path*(self: FileType, fname: string): string = + ## computes the filpath for a FileType raise tddError # result = self.dir / hash(fname) @@ -39,7 +35,7 @@ proc encode*[T: JsonNode | string](self: T): string = proc toDisk*[T: JsonNode | string | Config]( - self: SaveType, + self: FileType, fname: string, data: T, captainsLog: JsonNode @@ -63,7 +59,7 @@ proc toDisk*[T: JsonNode | string | Config]( proc fromDisk*[T]( - self: SaveType, + self: FileType, fname: string, to: T, errorNotFound = false diff --git a/src/boat/private/fileManagerUtils.nim b/src/boat/private/fileManagerUtils.nim index 64b9e7a..c384da7 100644 --- a/src/boat/private/fileManagerUtils.nim +++ b/src/boat/private/fileManagerUtils.nim @@ -8,10 +8,13 @@ import std/[ import boatErrors, boatConstants +type FileType* = enum + captainsLog, + localManifest, + remoteManifest, -proc persist*[T: string | Config](self: T, path: string): Future[void] {.async.} = - ## writes strings to path - ## calls parsecfg.writeConfig for configs +proc persist*[T: FileType](self: T, path: string): Future[void] {.async.} = + ## persists a FileType to path raise tddError # lock # of string -> data.write path @@ -19,12 +22,13 @@ proc persist*[T: string | Config](self: T, path: string): Future[void] {.async.} # unlock # throw if any errors occur -proc retrieve*[T: BoatConfigKind](self: T, path: string): T = - # retrieves a Config or Json from a path +proc retrieve*[T: FileType](self: T, path: string): BoatConfigKind = + ## retrieves a FileType from path and parses to BoatConfigKind try: - if self is Config: result = loadConfig path - elif self is JsonNode: raise tddError # should load json from path - else: raise boatConfigKindError + result = case self + of captainsLog: raise tddError # parse to json + of localManifest: loadConfig path + of remoteManifest: raise tddError # download, then loadConfig path except CatchableError: debugEcho repr getCurrentException() raise fileLoadDefect diff --git a/src/htmldocs/_._/bdd.html b/src/htmldocs/_._/bdd.html deleted file mode 100644 index 0b5facd..0000000 --- a/src/htmldocs/_._/bdd.html +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - - - - - - - - - - - - -bdd - - - - - - - - -
-
-

bdd

-
-
-
- -     Dark Mode -
- -
- Search: -
-
- Group by: - -
- - -
-   Source -  Edit - -
-
- -

-

Bdd

simple assertions for use with testament

-

-
-

Types

-
-
-
TddError = ref object of CatchableError
-  
-
- -generic error for test driven development -  Source -  Edit - -
-
-
-
What = enum
-  should,                   ## be true
-  shouldError,              ## when called
-  shouldNot,                ## be true
-  shouldNotError             ## when called
-
- -expected result of some condition -  Source -  Edit - -
-
- -
-
-

Vars

-
-
-
tddError = TddError(msg: "TODO: this feature isnt ready yet")
-
- - -ready to be raised tddError -  Source -  Edit - -
-
- -
-
-

Procs

-
-
-
proc bdd(caseName: string): (What, string, () -> bool) -> void {....raises: [],
-    tags: [].}
-
- -simple assertions for use with testament provide a test name and receive a fn that validates condition matches expectation -  Source -  Edit - -
-
-
-
proc itShould(msg: string; name = "test name: "; condition: bool; istrue = true): void {.
-    ...raises: [], tags: [].}
-
- -asserts condition matches expectation prefer creating a test case with bdd -  Source -  Edit - -
-
-
-
proc itShouldNot(msg: string; name = "test name: "; condition: bool): void {.
-    ...raises: [], tags: [].}
-
- -asserts condition matches expectation prefer creating a test case with bdd -  Source -  Edit - -
-
- -
- -
-
- -
- -
-
-
- - - diff --git a/src/htmldocs/_._/bdd.idx b/src/htmldocs/_._/bdd.idx deleted file mode 100644 index c519c89..0000000 --- a/src/htmldocs/_._/bdd.idx +++ /dev/null @@ -1,11 +0,0 @@ -TddError _._/bdd.html#TddError bdd: TddError -tddError _._/bdd.html#tddError_2 bdd: tddError -itShould _._/bdd.html#itShould,string,string,bool bdd: itShould(msg: string; name = "test name: "; condition: bool; istrue = true): void -itShouldNot _._/bdd.html#itShouldNot,string,string,bool bdd: itShouldNot(msg: string; name = "test name: "; condition: bool): void -should _._/bdd.html#should What.should -shouldError _._/bdd.html#shouldError What.shouldError -shouldNot _._/bdd.html#shouldNot What.shouldNot -shouldNotError _._/bdd.html#shouldNotError What.shouldNotError -What _._/bdd.html#What bdd: What -bdd _._/bdd.html#bdd,string bdd: bdd(caseName: string): (What, string, () -> bool) -> void -Bdd _._/bdd.html#bdd Bdd diff --git a/src/htmldocs/boat.html b/src/htmldocs/boat.html index 879e5b7..3f53c9d 100644 --- a/src/htmldocs/boat.html +++ b/src/htmldocs/boat.html @@ -102,12 +102,6 @@

src/boat

  • - Imports - -
  • -
  • Procs