Skip to content

Option to pass extra arguments to ctest #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ local osys = require("cmake-tools.osys")
require("cmake-tools").setup {
cmake_command = "cmake", -- this is used to specify cmake command path
ctest_command = "ctest", -- this is used to specify ctest command path
ctest_extra_args = {}, -- this is used to specify extra args for ctest
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can put this variable into Config.base_settings? So we can edit it easily.

cmake_use_preset = true,
cmake_regenerate_on_save = true, -- auto generate when save CMakeLists.txt
cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- this will be passed when invoke `CMakeGenerate`
Expand Down
7 changes: 6 additions & 1 deletion lua/cmake-tools/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ local Config = {
build_directory = nil,
query_directory = nil,
reply_directory = nil,
ctest = {
extra_args = {},
},
build_type = nil,
variant = nil,
build_target = nil,
Expand Down Expand Up @@ -46,7 +49,9 @@ function Config:new(const)

obj.executor = const.cmake_executor
obj.runner = const.cmake_runner

for _, v in pairs(const.ctest_extra_args) do
table.insert(obj.ctest.extra_args, v)
end
return obj
end

Expand Down
1 change: 1 addition & 0 deletions lua/cmake-tools/const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local osys = require("cmake-tools.osys")
local const = {
cmake_command = "cmake", -- this is used to specify cmake command path
ctest_command = "ctest", -- this is used to specify ctest command path
ctest_extra_args = {}, -- this is used to specify extra arguments for ctest
cmake_use_preset = true, -- when `false`, this is used to define if the `--preset` option should be use on cmake commands
cmake_regenerate_on_save = true, -- auto generate when save CMakeLists.txt
cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- this will be passed when invoke `CMakeGenerate`
Expand Down
3 changes: 3 additions & 0 deletions lua/cmake-tools/test/ctest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function ctest.run(ctest_command, test_name, build_dir, env, config, opt)
opt = opt or {}

local args = { "--test-dir", utils.transform_path(build_dir), "-R", test_name, opt.args }
for _, v in pairs(config.ctest.extra_args) do
table.insert(args, v)
end
utils.run(
cmd,
config.env_script,
Expand Down
23 changes: 23 additions & 0 deletions tests/config_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local const = require("cmake-tools.const")

describe("Config", function()
local Config
local local_const

before_each(function()
package.loaded["cmake-tools.config"] = nil
Config = require("cmake-tools.config")
local_const = vim.deepcopy(const)
end)

it("should parse user provided ctest arguments", function()
local_const.ctest_extra_args = { "-j", "6" }
local config = Config:new(local_const)
assert.are_same({ "-j", "6" }, config.ctest.extra_args)
end)

it("should parse user ctest empty arguments", function()
local config = Config:new(const)
assert.are_same({}, config.ctest.extra_args)
end)
end)
37 changes: 37 additions & 0 deletions tests/ctest_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local match = require("luassert.match")
local stub = require("luassert.stub")
local const = require("cmake-tools.const")
local ctest = require("cmake-tools.test.ctest")
local utils = require("cmake-tools.utils")

describe("run", function()
local local_const
local Config
local expected
before_each(function()
package.loaded["cmake-tools.config"] = nil
Config = require("cmake-tools.config")
local_const = vim.deepcopy(const)
expected = { "--test-dir", "build_dir", "-R", "test_name" }
stub(utils, "run")
end)

it("takes extra args from user config", function()
local_const.ctest_extra_args = { "-j", "6" }
local config = Config:new(local_const)
ctest:run("test_name", "build_dir", "env", config, {})
table.insert(expected, "-j")
table.insert(expected, "6")
assert
.stub(utils.run).was
.called_with(match._, match._, match._, expected, match._, match._, match._, match._)
end)

it("ignores extra args if not provided", function()
local config = Config:new(const)
ctest:run("test_name", "build_dir", "env", config, {})
assert
.stub(utils.run).was
.called_with(match._, match._, match._, expected, match._, match._, match._, match._)
end)
end)
Loading