Skip to content

Commit ad10f7f

Browse files
committed
Option to pass ctest extra args
1 parent 88e07c6 commit ad10f7f

6 files changed

Lines changed: 69 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ local osys = require("cmake-tools.osys")
2828
require("cmake-tools").setup {
2929
cmake_command = "cmake", -- this is used to specify cmake command path
3030
ctest_command = "ctest", -- this is used to specify ctest command path
31+
ctest_extra_args = {}, -- this is used to specify extra args for ctest
3132
cmake_use_preset = true,
3233
cmake_regenerate_on_save = true, -- auto generate when save CMakeLists.txt
3334
cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- this will be passed when invoke `CMakeGenerate`

lua/cmake-tools/config.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ local Config = {
1111
build_directory = nil,
1212
query_directory = nil,
1313
reply_directory = nil,
14+
ctest = {
15+
extra_args = {},
16+
},
1417
build_type = nil,
1518
variant = nil,
1619
build_target = nil,
@@ -48,7 +51,9 @@ function Config:new(const)
4851

4952
obj.executor = const.cmake_executor
5053
obj.runner = const.cmake_runner
51-
54+
for _,v in pairs(const.ctest_extra_args) do
55+
table.insert(obj.ctest.extra_args, v)
56+
end
5257
return obj
5358
end
5459

lua/cmake-tools/const.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local osys = require("cmake-tools.osys")
22
local const = {
33
cmake_command = "cmake", -- this is used to specify cmake command path
44
ctest_command = "ctest", -- this is used to specify ctest command path
5+
ctest_extra_args = {}, -- this is used to specify extra arguments for ctest
56
cmake_use_preset = true, -- when `false`, this is used to define if the `--preset` option should be use on cmake commands
67
cmake_regenerate_on_save = true, -- auto generate when save CMakeLists.txt
78
cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- this will be passed when invoke `CMakeGenerate`

lua/cmake-tools/test/ctest.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ function ctest.run(ctest_command, test_name, build_dir, env, config, opt)
3939
opt = opt or {}
4040

4141
local args = { "--test-dir", utils.transform_path(build_dir), "-R", test_name, opt.args }
42+
for _, v in pairs(config.ctest.extra_args) do
43+
table.insert(args, v)
44+
end
4245
utils.run(cmd, config.env_script, env, args, config.cwd, config.runner, nil)
4346
end
4447

tests/config_spec.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
local const = require("cmake-tools.const")
2+
3+
describe('Config', function()
4+
local Config
5+
local local_const
6+
7+
before_each(function()
8+
package.loaded['cmake-tools.config'] = nil
9+
Config = require('cmake-tools.config')
10+
local_const = vim.deepcopy(const)
11+
end)
12+
13+
it('should parse user provided ctest arguments', function()
14+
local_const.ctest_extra_args = { "-j", "6" }
15+
local config = Config:new(local_const)
16+
assert.are_same({ "-j", "6" }, config.ctest.extra_args)
17+
end)
18+
19+
it('should parse user ctest empty arguments', function()
20+
local config = Config:new(const)
21+
assert.are_same({}, config.ctest.extra_args)
22+
end)
23+
end)

tests/ctest_spec.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
local match = require('luassert.match')
2+
local stub = require('luassert.stub')
3+
local const = require('cmake-tools.const')
4+
local ctest = require("cmake-tools.test.ctest")
5+
local utils = require('cmake-tools.utils')
6+
7+
describe("run", function()
8+
local local_const
9+
local Config
10+
local expected
11+
before_each(function()
12+
package.loaded['cmake-tools.config'] = nil
13+
Config = require('cmake-tools.config')
14+
local_const = vim.deepcopy(const)
15+
expected = { "--test-dir", "build_dir", "-R", "test_name" }
16+
stub(utils, "run")
17+
end)
18+
19+
it("takes extra args from user config", function()
20+
local_const.ctest_extra_args = { "-j", "6" }
21+
local config = Config:new(local_const)
22+
ctest:run("test_name", "build_dir", "env", config, {})
23+
table.insert(expected, "-j")
24+
table.insert(expected, "6")
25+
assert.stub(utils.run).was.called_with(match._, match._, match._, expected,
26+
match._, match._, match._)
27+
end)
28+
29+
it("ignores extra args if not provided", function()
30+
local config = Config:new(const)
31+
ctest:run("test_name", "build_dir", "env", config, {})
32+
assert.stub(utils.run).was.called_with(match._, match._, match._, expected,
33+
match._, match._, match._)
34+
end)
35+
end)

0 commit comments

Comments
 (0)