Skip to content

Commit

Permalink
Fix getNimibVersion() (#196)
Browse files Browse the repository at this point in the history
* Fix `getNimibVersion()`

* add test

---------

Co-authored-by: t-h-rk-turner <[email protected]>
  • Loading branch information
neroist and neroist authored Mar 27, 2023
1 parent ced9e4c commit d8c1010
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/nimib/config.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import types, parsetoml, jsony, std / [json, os, osproc, math, sequtils]

proc getNimibVersion*(): string =
let
# nimib/src/nimib/config.nim -> nimib/src/nimib/ -> nimib/src/ -> nimib/
var dir = currentSourcePath().parentDir().parentDir()

# please, an easier way to do this...
dumpedJson = execProcess("nimble dump --json", currentSourcePath().parentDir().parentDir().parentDir())
if dir.splitPath().tail == "src":
dir = dir.parentDir()

let dumpedJson = execProcess("nimble dump --json", dir)

result = parseJson(dumpedJson)["version"].getStr()

Expand Down Expand Up @@ -111,4 +112,4 @@ when isMainModule:
dump doc.rawCfg
dump doc.cfg
dump doc.srcDir
dump doc.homeDir
dump doc.homeDir
6 changes: 6 additions & 0 deletions tests/tnimib.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import std / [unittest, strformat, strutils]
import nimib/config
import nimib

nbInit # todo: add a test suite for nbInit
Expand Down Expand Up @@ -266,3 +267,8 @@ when moduleAvailable(karax/kbase):
check "you = \"me\"" in nb.blocks[^1].context["transformedCode"].vString
check nb.blocks[^2].code.startsWith("let you =")
check nb.blocks[^2].output == "hi me\n"

test "getNimibVersion()":
let version = getNimibVersion()

check version.count('.') == 2

0 comments on commit d8c1010

Please sign in to comment.