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

csharp.unitTestDebuggingOptions.env broken as of 1.24.2 #5309

Closed
tillig opened this issue Jul 13, 2022 · 6 comments · Fixed by #5315
Closed

csharp.unitTestDebuggingOptions.env broken as of 1.24.2 #5309

tillig opened this issue Jul 13, 2022 · 6 comments · Fixed by #5315

Comments

@tillig
Copy link

tillig commented Jul 13, 2022

Issue Description

Prior to v1.24.2 you could specify environment variables to use during unit test debugging in your settings.json under csharp.unitTestDebuggingOptions (which says any lauch.json option is available).

As of v1.24.2, environment variables provided via csharp.unitTestDebuggingOptions no longer show up in the unit test debugging environment.

If I had to guess, it has to do with this commit which changed the way environment variables get passed during the debug operation.

Steps to Reproduce

In settings.json, add an environment variable to use during unit testing:

{
  "csharp.unitTestDebuggingOptions": {
    "env": {
      "EXAMPLE": "1"
    }
  }
}

Create a unit test that tries to read that variable.

[Fact]
public void ExampleTest()
{
  Assert.False(String.IsNullOrEmpty(Environment.GetVariable("EXAMPLE"));
}

Use the Code Lens to debug that test.

Expected Behavior

I expect the test to pass - the environment variable should be there because it was provided in the debugging options.

Actual Behavior

The test fails - the environment variable is not present.

Logs

OmniSharp log

No relevant logs are captured.

C# log

No relevant logs are captured.

Environment information

VSCode version: 1.69.1
C# Extension: 1.24.1

Mono Information OmniSharp using built-in mono
Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.301 Commit: 43f9b18481

Runtime Environment:
OS Name: Mac OS X
OS Version: 12.4
OS Platform: Darwin
RID: osx.12-x64
Base Path: /usr/local/share/dotnet/sdk/6.0.301/

Host (useful for support):
Version: 6.0.6
Commit: 7cca709db2

.NET SDKs installed:
3.1.413 [/usr/local/share/dotnet/sdk]
5.0.400 [/usr/local/share/dotnet/sdk]
6.0.301 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.19 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.19 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
auto-close-tag formulahendry 0.5.14
auto-rename-tag formulahendry 0.1.10
azure-account ms-vscode 0.11.0
beautify HookyQR 1.5.0
better-comments aaron-bond 3.0.0
better-toml bungcip 0.3.2
code-spell-checker streetsidesoftware 2.3.0
color-info bierner 0.7.0
cpptools ms-vscode 1.11.2
csharp ms-dotnettools 1.24.1
cucumberautocomplete alexkrechik 2.15.2
docomment k--kato 0.1.31
dotenv mikestead 1.0.1
dotnet-test-explorer formulahendry 0.7.7
ecdc mitchdenny 1.8.0
EditorConfig EditorConfig 0.16.4
fabric8-analytics redhat 0.3.6
git-extension-pack donjayamanne 0.1.3
git-graph mhutchie 1.30.0
githistory donjayamanne 0.6.19
gitignore codezombiech 0.8.0
gitlens eamodio 12.1.2
go golang 0.34.1
html-css-class-completion Zignd 1.20.0
java redhat 1.8.0
jupyter ms-toolsai 2022.6.1101950301
jupyter-keymap ms-toolsai 1.0.0
jupyter-renderers ms-toolsai 1.0.8
jwt-debugger yokawasa 0.4.2
live-server ms-vscode 0.2.12
markdown-all-in-one yzhang 3.4.3
markdown-emoji bierner 0.2.1
marp-vscode marp-team 1.5.2
material-theme zhuangtongfa 3.15.2
metals scalameta 1.18.0
msbuild-project-tools tintoy 0.4.4
nc-gcode ML 0.13.0
npm-intellisense christian-kohler 1.4.2
openvpn idleberg 0.2.3
output-colorizer IBM 0.1.2
path-intellisense christian-kohler 2.8.1
plantuml jebbs 2.17.3
powershell ms-vscode 2022.6.3
prettier-toml bodil 0.1.0
project-manager alefragnani 12.6.0
python ms-python 2022.10.0
rainbow-csv mechatroner 2.4.0
remote-containers ms-vscode-remote 0.241.3
remote-repositories ms-vscode 0.14.0
remote-ssh ms-vscode-remote 0.84.0
remote-ssh-edit ms-vscode-remote 0.80.0
remote-wsl ms-vscode-remote 0.66.3
remotehub GitHub 0.36.0
restructuredtext lextudio 189.0.0
rewrap stkb 1.16.3
scala scala-lang 0.5.5
simple-rst trond-snekvik 1.5.2
sort-lines Tyriar 1.9.1
sort-lines-by-selection earshinov 1.0.0
spectral stoplight 1.0.0
terraform hashicorp 2.23.0
todo-tree Gruntfuggly 0.0.215
vscode-arduino vsciot-vscode 0.4.12
vscode-azurefunctions ms-azuretools 1.7.4
vscode-azureresourcegroups ms-azuretools 0.5.4
vscode-azurestorage ms-azuretools 0.14.2
vscode-code-review d-koppenhagen 1.32.1
vscode-commons redhat 0.0.6
vscode-cosmosdb ms-azuretools 0.19.2
vscode-coverage-gutters ryanluker 2.10.1
vscode-dapr ms-azuretools 0.6.0
vscode-docker ms-azuretools 1.22.1
vscode-eslint dbaeumer 2.2.6
vscode-graphviz joaompinto 0.0.6
vscode-icons vscode-icons-team 11.13.0
vscode-java-debug vscjava 0.42.0
vscode-java-dependency vscjava 0.20.0
vscode-java-pack vscjava 0.24.0
vscode-java-test vscjava 0.35.2
vscode-json-stable-stringify TravisIllig 1.2.1
vscode-kubernetes-tools ms-kubernetes-tools 1.3.10
vscode-markdownlint DavidAnson 0.47.0
vscode-maven vscjava 0.36.0
vscode-npm-script eg2 0.3.28
vscode-open-in-github ziyasal 1.3.6
vscode-open-multiple-files fabiospampinato 1.4.0
vscode-openapi 42Crunch 4.11.2
vscode-pylance ms-python 2022.7.20
vscode-remote-extensionpack ms-vscode-remote 0.21.0
vscode-xml redhat 0.21.0
vscode-yaml redhat 1.9.1
vscodeintellicode VisualStudioExptTeam 1.2.22
xml DotJoshJohnson 2.5.1
yaml-plus-json hilleer 1.10.0
@gregg-miskelly
Copy link
Contributor

gregg-miskelly commented Jul 22, 2022

This is "by design" as env isn't a supported option for unit test debugging (see here), and it would be overwritten here.

I think the way to do what you are trying to do is with a .runsettings file.

Documentation: https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2022

Setting: https://github.com/OmniSharp/omnisharp-vscode/blob/88ad237e1e904ad0f91d2de39c30132198a02dcb/package.json#L1091

@tillig
Copy link
Author

tillig commented Jul 22, 2022

Then at the very least, the docs two lines down from that are wrong - any launch.json option is not valid.

I figured that's where it was getting overridden, which is why I linked to the commit that changed the behavior.

I'd like to challenge the idea that this is by design based on the docs. It seems like the intent actually was to allow launch.json stuff to work... And it did for a while! It seems like it still could if the environment got merged with the settings rather than completely overridden.

If I do end up having to use .runsettings, how do I set that so it only gets used during test debugging? I didn't see a specific option to indicate a .runsettings file in the unit test debugging options. Maybe I missed it? It was admittedly a bit confusing that the .runsettings page says it works for VS but specifically shows VS Code as not being supported. Stale docs?

@gregg-miskelly
Copy link
Contributor

We intentionally do not allow env or any other launch.json option that only can be applied to launch because it is up to the unit test framework as to if the debugger launches or attaches to the worker process. But I would agree that Any launch.json option is valid here is incorrect. I will send a PR to update the documentation.

@tillig
Copy link
Author

tillig commented Jul 22, 2022

Fair enough. Can you point me to how to specify a .runsettings in the unitTestDebuggingOptions?

@gregg-miskelly
Copy link
Contributor

I only know the debugging side of things, but you would use omnisharp.testRunSettings. That should apply both when debugging and when not.

@tillig
Copy link
Author

tillig commented Jul 22, 2022

Ah! Excellent. I'll give that a shot. I appreciate the help and the pointers!

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.

2 participants