summary refs log tree commit diff stats
path: root/testc.lua
blob: e9a793c27a5b15b43be491d077ca10ccacc66878 (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
30
31
32
33
34
35
36
37
38
39
40
41
local function printr(...)
    print(...)
    return ...
end

local collect = {}
local function printr_collect(...)
    table.insert(collect, (...))
    return printr(...)
end

-- used to print what the lua parser (load) is seeing, after cratera has done its thing
loadstring = nil
local realload = load
load = function(target, ...)
    if type(target) == "function" then
        return realload(function() return printr_collect(target()) end, ...)
    else
        return realload(printr_collect(target), ...)
    end
end

local cratera = require "cratera"

-- first test: does it handle empty files properly?
assert(printr(cratera.load("")))()

-- second test: does it handle lua code properly?
assert(printr(cratera.load(io.open("cratera/compiler.lua"):read("*a"))))()

print("-----------------------------------------------------------------------------------------------------------------------")
print(table.concat(collect))

collect = {}

-- third test: does it handle cratera tests properly?
assert(printr(cratera.load(io.open("tests.cratera"):read("*a"))))()

print("-----------------------------------------------------------------------------------------------------------------------")
print(table.concat(collect))