Skip to content

Commit 58550b5

Browse files
committed
Option to pass ctest extra args
1 parent 1ee065c commit 58550b5

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
@@ -9,6 +9,9 @@ local Config = {
99
build_directory = nil,
1010
query_directory = nil,
1111
reply_directory = nil,
12+
ctest = {
13+
extra_args = {},
14+
},
1215
build_type = nil,
1316
variant = nil,
1417
build_target = nil,
@@ -46,7 +49,9 @@ function Config:new(const)
4649

4750
obj.executor = const.cmake_executor
4851
obj.runner = const.cmake_runner
49-
52+
for _,v in pairs(const.ctest_extra_args) do
53+
table.insert(obj.ctest.extra_args, v)
54+
end
5055
return obj
5156
end
5257

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
@@ -37,6 +37,9 @@ function ctest.run(ctest_command, test_name, build_dir, env, config, opt)
3737
opt = opt or {}
3838

3939
local args = { "--test-dir", utils.transform_path(build_dir), "-R", test_name, opt.args }
40+
for _, v in pairs(config.ctest.extra_args) do
41+
table.insert(args, v)
42+
end
4043
utils.run(
4144
cmd,
4245
config.env_script,

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._, 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._, match._)
34+
end)
35+
end)

0 commit comments

Comments
 (0)