From ea05a9db6c250989742ecec7abebbaa204a3bdb3 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 20 Mar 2023 01:07:39 +0000 Subject: add basic testing script --- test.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test.lua diff --git a/test.lua b/test.lua new file mode 100644 index 0000000..56537d6 --- /dev/null +++ b/test.lua @@ -0,0 +1,38 @@ +local n = 1 +local function test(res, ermsg) + if not res then error(ermsg) + else + print("ok",n) + n = n + 1 + end +end + +local lmdb=require'lmdb' +local env=lmdb.open("data") +test(env,"no env") + +local txn = env:txn_begin(true) +test(txn, "no txn") + +local db = txn:open() +test(db, "no db") +db["foo"]="bar" +db["the"]="of the" +test(db["foo"] == "bar","no eq 1") + +test(txn:commit()) + +local txn2 = env:txn_begin() +test(txn2,"no txn2") +local db2 = txn2:open() +test(db2, "no db2") + +test(db2["the"] == "of the", "no eq 2") +test(txn2:commit()) + +local ok,v = pcall(function() return db2["foo"] end) +test(not ok,"shouldn't be able to access db from closed txn") +print("ok, got msg",v) + +print() +print("everything good!!!") -- cgit v1.2.3