-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathctest.lua
More file actions
59 lines (47 loc) · 1.37 KB
/
ctest.lua
File metadata and controls
59 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
51
52
53
54
55
56
57
58
59
local Job = require("plenary.job")
local utils = require("cmake-tools.utils")
local const = require("cmake-tools.const")
local ctest = {
job = nil,
}
function ctest.list_all_tests(build_dir, callback)
local result = {}
ctest.job = Job:new({
command = "ctest",
args = { "--test-dir", build_dir, "--show-only=json-v1" },
on_exit = function(j, _, _)
vim.schedule(function()
local json_data = ""
for _, v in pairs(j:result()) do
json_data = json_data .. v
end
result = vim.fn.json_decode(json_data)
local tests = {}
for _, item in ipairs(result.tests) do
table.insert(tests, item["name"])
end
callback(tests)
end)
end,
})
ctest.job:start()
end
function ctest.run(ctest_command, test_name, build_dir, env, config, opt)
local cmd = ctest_command
opt = opt or {}
local args = { "--test-dir", utils.transform_path(build_dir), "-R", test_name, opt.args }
for _, v in pairs(config.base_settings.ctest_extra_args) do
table.insert(args, v)
end
utils.run(cmd, config.env_script, env, args, config.cwd, config.runner, nil)
end
function ctest.stop()
if not ctest.job or ctest.job.is_shut_down then
return
end
ctest.job:shutdown(1, 9)
for _, pid in ipairs(vim.api.nvim_get_proc_children(ctest.job.pid)) do
vim.loop.kill(pid, 9)
end
end
return ctest