Skip to content
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

Set run configuration options for debug_test #76

Open
theoribeiro opened this issue Mar 27, 2024 · 5 comments · May be fixed by #77
Open

Set run configuration options for debug_test #76

theoribeiro opened this issue Mar 27, 2024 · 5 comments · May be fixed by #77

Comments

@theoribeiro
Copy link

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
Copy link

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 theoribeiro linked a pull request Apr 5, 2024 that will close this issue
@theoribeiro
Copy link
Author

@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
Copy link

eric-gt commented May 18, 2024

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

@haclark30
Copy link

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
Copy link
Owner

leoluz commented Oct 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants