aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-03-20 01:07:39 +0000
committerthe lemons <citrons@mondecitronne.com>2023-03-20 22:50:18 -0500
commitea05a9db6c250989742ecec7abebbaa204a3bdb3 (patch)
treece71dd1e8befa245d6a41048adea9c84cb5f2a69
parent9ce7a7ed9818208791041a29e6653e16b81d8604 (diff)
add basic testing script
-rw-r--r--test.lua38
1 files changed, 38 insertions, 0 deletions
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!!!")