summary refs log tree commit diff stats
path: root/test/testbc.lua
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2024-05-27 00:11:26 -0300
committerSoniEx2 <endermoneymod@gmail.com>2024-05-27 00:11:26 -0300
commite62ec5ac36188cb12411a8c720daebce77ecf645 (patch)
treeb1a2ce8e95ffc6e92ee31c1e271b0fcafe8a0b2f /test/testbc.lua
parent9dea1c26b487ae723d99ba1e5e5887b09aec87dd (diff)
Set up a "build system"
Diffstat (limited to 'test/testbc.lua')
-rw-r--r--test/testbc.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/testbc.lua b/test/testbc.lua
new file mode 100644
index 0000000..05a36cc
--- /dev/null
+++ b/test/testbc.lua
@@ -0,0 +1,29 @@
+local cratera = require "cratera"
+
+local function stream(filename, mode)
+    local file, err = io.open(filename, mode)
+    if not file then return nil, err end
+    return function()
+        local data, err = file:read(8192)
+        if not data then file:close() return nil, err end
+        return data
+    end
+end
+
+-- load tests, streaming
+local tests = assert(cratera.load(stream("test/tests.cratera", "rb")))
+
+-- dump tests
+local testsdump = string.dump(tests)
+
+-- check if cratera can load them
+assert(cratera.load(testsdump))()
+
+-- output to a file
+local file = io.open("out/test/testsdump.cratera", "wb")
+assert(file:write(testsdump))
+assert(file:flush())
+assert(file:close())
+
+-- load again, streaming, precompiled, and from a file
+assert(cratera.load(stream("out/test/testsdump.cratera", "rb")))()