Set run configuration options for debug_test #76

Closed
opened 2024-03-27 19:49:02 +03:00 by theoribeiro · 6 comments
theoribeiro commented 2024-03-27 19:49:02 +03:00 (Migrated from github.com)

I have a use case where I need to set up an environment variable only when debugging tests. We're using Temporal and for it not to timeout it needs a TEMPORAL_DEBUG variable set when debugging.

It would be great if we could configure extra run options to debug_test so that we can set not only this but other configuration options as well.

Would you be willing to accept a PR for this?

I have a use case where I need to set up an environment variable only when debugging tests. We're using Temporal and for it not to timeout it needs a TEMPORAL_DEBUG variable set when debugging. It would be great if we could configure extra run options to `debug_test` so that we can set not only this but other configuration options as well. Would you be willing to accept a PR for this?
friesencr commented 2024-04-03 21:27:19 +03:00 (Migrated from github.com)

I have a use case that needs to set cwd and env. It would be nice to be able to merge table into what is running. I have a workaround for some of the options. I just override the ones that this plugin adds after setup but it doesn't work for test.

This is what I am doing to fix some of my problems.

dap.configurations.go = {
				{
					type = "go",
					name = "(Arguments)",
					request = "launch",
					program = "${workspaceFolder}",
					cwd = "${workspaceFolder}",
					args = get_arguments,
					env = { LOG_COLOR = "0", },
				},
}
I have a use case that needs to set cwd and env. It would be nice to be able to merge table into what is running. I have a workaround for some of the options. I just override the ones that this plugin adds after setup but it doesn't work for test. This is what I am doing to fix some of my problems. ``` dap.configurations.go = { { type = "go", name = "(Arguments)", request = "launch", program = "${workspaceFolder}", cwd = "${workspaceFolder}", args = get_arguments, env = { LOG_COLOR = "0", }, }, } ```
theoribeiro commented 2024-04-05 16:49:27 +03:00 (Migrated from github.com)

@friesencr I created a #77 to add an option for extra configuration arguments specifically for when calling debug_test().

For all other configurations, I've been just adding arguments manually by looping through the default provided configs after setup.

@friesencr I created a #77 to add an option for extra configuration arguments specifically for when calling `debug_test()`. For all other configurations, I've been just adding arguments manually by looping through the default provided configs after setup.
eric-gt commented 2024-05-18 11:51:45 +03:00 (Migrated from github.com)

I'd also like to see this implemented. debug_test is an incredible convenience feature, but it's useless if your project has any kind of complex setup.

For example, I'm working on a repo that requires the --with-config flag to be set for testing and running locally. Since I can't pass that argument into any of the provided configs except (Arguments), I'm stuck manually passing in runtime regexes, and I can't take advantage of the really nice current test detection.

Another potential approach would be to have debug_test modify a predefined config that users can override. That way the function signature stays the same, and we can customize to our heart's content.
e.g.

-- WARNING: UNTESTED
-- get the basic config, which may have been overridden by the user
local function get_base_config(configName)
  local dap = load_module("dap")
  for _, v in ipairs(dap.configurations.go) do
    if v.name == configName then
      return v
    end
  end
end

local function debug_test(testname, testpath, build_flags)
  local dap = load_module("dap")
  local baseConfig = get_base_config("Debug test")
  local config = vim.tbl_deep_extend("force", {}, baseConfig, {
    -- merge user defined config with default args/build flags, and add the testname/path
    name = testname,
    program = testpath,
    args = vim.tbl_deep_extend("force", {}, baseConfig.args, { "-test.run", "^" .. testname .. "$" }),
    buildFlags = vim.tbl_deep_extend("force", {}, baseConfig.build_flags, build_flags or {}),
  })
  dap.run(config)
end
I'd also like to see this implemented. `debug_test` is an incredible convenience feature, but it's useless if your project has any kind of complex setup. For example, I'm working on a repo that requires the `--with-config` flag to be set for testing and running locally. Since I can't pass that argument into any of the provided configs except `(Arguments)`, I'm stuck manually passing in runtime regexes, and I can't take advantage of the really nice current test detection. Another potential approach would be to have `debug_test` modify a predefined config that users can override. That way the function signature stays the same, and we can customize to our heart's content. e.g. ```lua -- WARNING: UNTESTED -- get the basic config, which may have been overridden by the user local function get_base_config(configName) local dap = load_module("dap") for _, v in ipairs(dap.configurations.go) do if v.name == configName then return v end end end local function debug_test(testname, testpath, build_flags) local dap = load_module("dap") local baseConfig = get_base_config("Debug test") local config = vim.tbl_deep_extend("force", {}, baseConfig, { -- merge user defined config with default args/build flags, and add the testname/path name = testname, program = testpath, args = vim.tbl_deep_extend("force", {}, baseConfig.args, { "-test.run", "^" .. testname .. "$" }), buildFlags = vim.tbl_deep_extend("force", {}, baseConfig.build_flags, build_flags or {}), }) dap.run(config) end ```
haclark30 commented 2024-10-10 23:14:40 +03:00 (Migrated from github.com)

I'd also like to see this added. I'm working on a project with the oci8 SQL driver which requires the PKG_CONFIG_PATH environment variable to be set. I'm able to debug the whole project using a custom config, but I'd like to be able to use "Debug Test" for this as well.

I'd also like to see this added. I'm working on a project with the oci8 SQL driver which requires the `PKG_CONFIG_PATH` environment variable to be set. I'm able to debug the whole project using a custom config, but I'd like to be able to use "Debug Test" for this as well.
leoluz commented 2024-10-17 04:51:17 +03:00 (Migrated from github.com)

It would be very helpful if someone provided a minimal Go project setup as a PR in the tests folder to reproduce this scenario with a failing debug test.

It would be very helpful if someone provided a minimal Go project setup as a PR in the `tests` folder to reproduce this scenario with a failing debug test.
stale[bot] commented 2025-04-15 21:35:20 +03:00 (Migrated from github.com)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
NeonXP/nvim-dap-go#76
No description provided.