-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.nvim
More file actions
executable file
·50 lines (47 loc) · 1.37 KB
/
test.nvim
File metadata and controls
executable file
·50 lines (47 loc) · 1.37 KB
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
42
43
44
45
46
47
48
49
50
#!/usr/bin/env -S nvim -l
local function cwd()
local sep = package.config:sub(1, 1)
local info = debug.getinfo(1, "S")
local source = info.source
if source:sub(1, 1) == "@" then
local realpath = ((vim or {}).uv or (vim or {}).loop or {}).fs_realpath
local path = source:sub(2)
path = realpath and realpath(path) or path
local dir, file = path:match("^(.*[" .. sep .. "])([^" .. sep .. "]+)$")
return dir or ("." .. sep), file
end
return "." .. sep, nil
end
local here = cwd()
vim.opt.runtimepath:prepend(here)
local testdir = here .. "tests/"
package.path = testdir .. "gambiarra/?.lua;" .. package.path
local test = require("gambiarra")
local files = test.read_dir(testdir, function(filename)
return filename:match("_test%.lua$")
end)
for _, file in ipairs(files) do
local success, msg = pcall(loadfile, testdir .. file)
if success then
---@cast msg function
success, msg = pcall(msg, test)
end
io.write(
"\n "
.. test.icons._end
.. " "
.. file
.. " "
.. (success and test.icons.pass or test.icons.fail)
.. (msg and " : " .. tostring(msg) or "")
.. "\n"
)
end
test.await(function(self)
self.report()
if (self.tests_failed or 0) > 0 then
os.exit(1)
else
os.exit(0)
end
end)