mirror of
https://github.com/codex-storage/nim-leveldb.git
synced 2025-02-19 19:08:34 +00:00
test package
This commit is contained in:
parent
6dceb3e080
commit
ba45990676
15
tests/packagetest/packagetest.nimble
Normal file
15
tests/packagetest/packagetest.nimble
Normal file
@ -0,0 +1,15 @@
|
||||
# Package
|
||||
|
||||
version = "0.1.0"
|
||||
author = "Xie Yanbo"
|
||||
description = "A new awesome nimble package"
|
||||
license = "MIT"
|
||||
srcDir = "src"
|
||||
bin = @["packagetest"]
|
||||
|
||||
|
||||
|
||||
# Dependencies
|
||||
|
||||
requires "nim >= 0.18.0"
|
||||
requires "leveldb"
|
10
tests/packagetest/src/packagetest.nim
Normal file
10
tests/packagetest/src/packagetest.nim
Normal file
@ -0,0 +1,10 @@
|
||||
import options
|
||||
import leveldb
|
||||
|
||||
when isMainModule:
|
||||
let db = leveldb.open("/tmp/testleveldb/tooldb")
|
||||
db.put("hello", "world")
|
||||
let val = db.get("hello")
|
||||
if val.isSome() and val.get() == "world":
|
||||
echo "leveldb works."
|
||||
db.close()
|
@ -1,6 +1,28 @@
|
||||
import unittest, options, sequtils
|
||||
import unittest, options, os, osproc, sequtils, strutils, sugar
|
||||
import leveldb, leveldbpkg/raw
|
||||
|
||||
template cd*(dir: string, body: untyped) =
|
||||
## Sets the current dir to ``dir``, executes ``body`` and restores the
|
||||
## previous working dir.
|
||||
block:
|
||||
let lastDir = getCurrentDir()
|
||||
setCurrentDir(dir)
|
||||
body
|
||||
setCurrentDir(lastDir)
|
||||
|
||||
proc execNimble(args: varargs[string]): tuple[output: string, exitCode: int] =
|
||||
const tmpNimbleDir = "/tmp/testnimble"
|
||||
var quotedArgs = @args
|
||||
quotedArgs.insert("-y")
|
||||
quotedArgs.insert("--nimbleDir:" & tmpNimbleDir)
|
||||
quotedArgs.insert("nimble")
|
||||
quotedArgs = quotedArgs.map((x: string) => ("\"" & x & "\""))
|
||||
|
||||
let cmd = quotedArgs.join(" ")
|
||||
result = execCmdEx(cmd)
|
||||
checkpoint(cmd)
|
||||
checkpoint(result.output)
|
||||
|
||||
suite "leveldb":
|
||||
|
||||
setup:
|
||||
@ -159,3 +181,20 @@ suite "leveldb":
|
||||
defer: nc.close()
|
||||
nc.put("a", "1")
|
||||
check(toSeq(nc.iter()) == @[("a", "1")])
|
||||
|
||||
suite "package":
|
||||
|
||||
test "import as package":
|
||||
let (output, exitCode) = execNimble("install")
|
||||
check exitCode == QuitSuccess
|
||||
check output.contains("leveldb installed successfully.")
|
||||
|
||||
cd "tests/packagetest":
|
||||
var (output, exitCode) = execNimble("build")
|
||||
check exitCode == QuitSuccess
|
||||
check output.contains("Building")
|
||||
|
||||
(output, exitCode) = execCmdEx("./packagetest")
|
||||
checkpoint output
|
||||
check exitCode == QuitSuccess
|
||||
check output.contains("leveldb works.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user