~technomancy/fennel

ref: 83ccb3c3345e84c59303fcd97db257d533905399 fennel/test/init.lua -rw-r--r-- 1.5 KiB
83ccb3c3Phil Hagelberg Fix apropos tests for other Lua versions. 6 months ago
                                                                                
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
-- We want to make sure the compiler can load under strict mode
local strict = function(_, k) if k then error("STRICT MODE YALL: " .. k) end end
setmetatable(_G, {__index = strict, __newindex = strict})

-- Ensure we're getting the Fennel we expect, not luarocks or anything
package.loaded.fennel = dofile("fennel.lua")
table.insert(package.loaders or package.searchers, package.loaded.fennel.searcher)
setmetatable(_G, nil) -- but we don't want strict mode for tests

local runner = require("test.luaunit").LuaUnit:new()
runner:setOutputType(os.getenv("FNL_TEST_OUTPUT") or "tap")

-- We have to load the tests with the old version of Fennel; otherwise
-- bugs in the current implementation will prevent the tests from loading!
local oldfennel = dofile("old/fennel.lua")

local function testall(suites)
    local instances = {}
    for _, test in ipairs(suites) do
        -- attach test modules (which export k/v tables of test fns) as alists
        local suite = oldfennel.dofile("test/" .. test .. ".fnl",
                                       {useMetadata = true})
        for name, testfn in pairs(suite) do
            table.insert(instances, {name,testfn})
        end
    end
    return runner:runSuiteByInstances(instances)
end

if(#arg == 0) then
   testall({"core", "mangling", "quoting", "misc", "docstring", "fennelview",
            "parser", "failures", "repl", "cli", "macro", "linter",
            "loops", "bit"})
else
   testall(arg)
end

os.exit(runner.result.notSuccessCount == 0 and 0 or 1)