summary refs log tree commit diff stats
path: root/test/testbc.lua
blob: 05a36cc7efda96f198a3d7e29b2850caa16f6b38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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")))()