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

Debugging tests doesn't set environment variables #237

Closed
4 tasks done
dadocolussi opened this issue Nov 23, 2020 · 4 comments
Closed
4 tasks done

Debugging tests doesn't set environment variables #237

dadocolussi opened this issue Nov 23, 2020 · 4 comments

Comments

@dadocolussi
Copy link

dadocolussi commented Nov 23, 2020

Checklist

  • The issue is about this extension and NOT about a fork.
  • Check the known issues list.
  • The latest version of the extension was used.
  • It is not related to remote-vscode or I checked the following issue

Describe the bug

Environment variable set under advancedExecutables in settings.json is not set when debugging test cases. When running a test case (without debugging it), the environment variable is available as expected. The problem is reproducible only when debugging. The problem is also reproducible locally as well as using remote-ssh.

To Reproduce

I have the following settings.json entry. I expect it to have the effect of HELLO environment variable being set for the test process:

	"testMate.cpp.test.advancedExecutables": [
		{
			"pattern": "MyUnitTestProgram",
			"env": {"HELLO":"Hello World!"}
		}

I have the following Catch2 test case that checks the presence of the environment variable. The problem is reproducible with Google Test, too.

TEST_CASE("HELLO environment variable is set")
{
	const char *s = ::getenv("HELLO");
	REQUIRE(s != nullptr);
}

Debug the test case and it'll fail. Run it normally without debugging, and it'll succeed.

Desktop

  • Extension Version:3.6.7
  • VS Code Version: 1.51.1
  • Catch2 / Google Test / DOCTest Version: 2.13.3
  • OS Type and Version: macOS 10.15.7
  • Using remote-ssh/docker/wsl?: remote-ssh and local.
@matepek
Copy link
Owner

matepek commented Nov 23, 2020

Hello,

Nice bug report.
Could you tell me which debug adapter are you using?
Or you can send me the logs.
One line would be really important: Debug: resolved debugConfig

@dadocolussi
Copy link
Author

I'm using ms-vscode.cpptools. Is that what you mean?

@dadocolussi
Copy link
Author

My current workaround is to remove testMate.cpp.debug.configTemplate and duplicate the environment variables in the first matching entry in launch.json (described in the config template documentation). The environment variables from launch.json do make it to the process when debugging. I still need the same variables under testMate.cpp.test.advancedExecutables when running the tests without debugging.

With the workaround, I observe in the logs:

  • Using debug { debugConfigTemplateSource: 'fromLaunchJson' }.
  • Debug: resolved debugConfig: contains:
    • environment: [ { name: 'HELLO', value: 'Hello World!' } ], and this is visible in the process.
    • env contains HELLO: 'Hello World!' and this is not visible in the process.

@matepek
Copy link
Owner

matepek commented Nov 29, 2020

It would have been interesting also that how the log looks like in case of the original repro/issue.

You've probably already read the documentation.

Well there is always the option to fill your own debug config. The mechanism I created is merely a fallback. Anyhow I tried to fix it. Check the next release.

@matepek matepek closed this as completed Nov 29, 2020
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

No branches or pull requests

2 participants