summary refs log blame commit diff stats
path: root/test/testc.lua
blob: 72ed39321283fef609060005e7c700fdb68adfbe (plain) (tree)
1
2
3
4
5
6
 




                          







                                                                                       


                                      
                                                                            
        
                                                    


       
                                 
 



                                                   
                                                                              





                                                                                                                                
                                                     
                                                                        
 

                                                                                                                                
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("src/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("test/tests.cratera"):read("*a"))))()

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