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

Debug Test can't receive DYLD_LIBRARY_PATH variable in macOS. #5131

Closed
zhen8838 opened this issue Mar 29, 2022 · 6 comments · Fixed by #5137
Closed

Debug Test can't receive DYLD_LIBRARY_PATH variable in macOS. #5131

zhen8838 opened this issue Mar 29, 2022 · 6 comments · Fixed by #5137

Comments

@zhen8838
Copy link

Issue Description

I set the DYLD_LIBRARY_PATH in the zshrc, then run dotnet test print the env variable value. but when I use debug Test , It can not get the variable value.

I record a video:

  1. I have not set the CUSTOM_VAR in the zshrc, then run the dotnet test, It's can print the DYLD_LIBRARY_PATH variable value.
  2. I set the CUSTOM_VAR in the zshrc, then restart the vscode and click Debut Test, Now in terminal we can see the CUSTOM_VAR variable, but DYLD_LIBRARY_PATH is null.
  3. use dotnet test, I can get both environment variable value.
a.a.a.a.2022-03-29.13.24.57.mov

Steps to Reproduce

  1. write the export DYLD_LIBRARY_PATH="xxx" in the ~/.zshrc
  2. restart the viscose
  3. click the debug test with code:
   [Fact]
    public void TestGETENV()
    {
        // var env = System.Environment.GetEnvironmentVariables();
        // foreach (var k in env.Keys)
        // {
        //     System.Console.WriteLine(k + ": " + env[k]);
        // }
        System.Console.WriteLine("Get DYLD_LIBRARY_PATH : " + System.Environment.GetEnvironmentVariable("DYLD_LIBRARY_PATH"));
        System.Console.WriteLine("Get CUSTOM_VAR : " + System.Environment.GetEnvironmentVariable("CUSTOM_VAR"));
    }

Expected Behavior

will print the Get DYLD_LIBRARY_PATH : xxx

Actual Behavior

Get DYLD_LIBRARY_PATH :

Logs

OmniSharp log

Post the output from Output--> [info]: OmniSharp.DotNetTest.VSTestManager read: {"MessageType":"TestSession.Connected","Payload":null} [info]: OmniSharp.DotNetTest.VSTestManager read: {"MessageType":"ProtocolVersion","Payload":1} [info]: OmniSharp.DotNetTest.DebugSessionManager Debug session started. [info]: OmniSharp.DotNetTest.DebugSessionManager Debug session ended.

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.65.2
C# Extension: 1.24.1

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

Runtime Environment:
OS Name: Mac OS X
OS Version: 12.3
OS Platform: Darwin
RID: osx.12-arm64
Base Path: /usr/local/share/dotnet/sdk/6.0.201/

Host (useful for support):
Version: 6.0.3
Commit: c24d9a9c91

.NET SDKs installed:
6.0.201 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.3 [/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
better-comments aaron-bond 2.1.0
change-case wmaurer 1.0.0
clang-format xaver 1.9.0
codestream CodeStream 12.13.0
copilot GitHub 1.9.5350
csharp ms-dotnettools 1.24.1
doxdocgen cschlosser 1.4.0
file-icons file-icons 1.0.29
gitlens eamodio 12.0.5
hexeditor ms-vscode 1.9.5
icons-carbon antfu 0.2.4
increment-selection albymor 0.2.0
material-theme zhuangtongfa 3.13.20
remote-ssh ms-vscode-remote 0.76.1
remote-ssh-edit ms-vscode-remote 0.76.1
test-adapter-converter ms-vscode 0.1.5
todo-tree Gruntfuggly 0.0.215
vscode-clangd llvm-vs-code-extensions 0.1.15
vscode-lldb vadimcn 1.7.0
vscode-test-explorer hbenl 2.21.1
vscode-wakatime WakaTime 18.0.8
vscode-yaml redhat 1.5.1
vscodeintellicode VisualStudioExptTeam 1.2.17
@nohwnd nohwnd self-assigned this Mar 29, 2022
@nohwnd
Copy link
Member

nohwnd commented Mar 30, 2022

When you run dotnet test from command line it will inherit the environment variables from the commandline, but if you run Debug test, it will delegate the debugging to the omnisharp server and that will delegate to vstest.console, you can provide runsettings to omnisharp, and runsettings can define environment variables.

In your workspace settings.json

{
    "omnisharp.testRunSettings": "runsettings.runsettings"
}

in runsettings.runsettings

<RunSettings>
    <RunConfiguration>
        <EnvironmentVariables>
            <DYLD_LIBRARY_PATH>AA</DYLD_LIBRARY_PATH>
        </EnvironmentVariables>
    </RunConfiguration>
</RunSettings>

in UnitTest1.cs

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace mstest6;

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        var v = Environment.GetEnvironmentVariable("DYLD_LIBRARY_PATH");
        Assert.AreEqual("AA", v);
    }
}

The env value is read and fails the test because I expect empty string instead:

----- Test Execution Summary -----

mstest6.UnitTest1.TestMethod1:
    Outcome: Passed
    
Total tests: 1. Passed: 1. Failed: 0. Skipped: 0

@nohwnd nohwnd closed this as completed Mar 30, 2022
@zhen8838
Copy link
Author

zhen8838 commented Mar 30, 2022

@nohwnd Thank you for your patient reply, but I encountered a problem in the process of Debug Test:

a.a.a.a.2022-03-30.23.09.45.mov

Maybe when debug Test,It's not accept the .runsettings file?

@nohwnd nohwnd reopened this Mar 31, 2022
@nohwnd
Copy link
Member

nohwnd commented Mar 31, 2022

You are right :) I thought I tried that, but my original example was using failing assertion to write the value to the screen, so I might have mistaken the failing assertion message, and overlook the actual failure.

The error seems to be here:

https://github.com/OmniSharp/omnisharp-vscode/blob/7689b0d3dd615224ac890dd9bccf9fb0bdae4a64/src/features/dotnetTest.ts#L367-L368

Debugger uses custom launcher, so test platform responds with info that says how testhost should be started, instead of starting it by itself. The environment variables arrive on the request, but are not passed on.

@nohwnd
Copy link
Member

nohwnd commented Apr 1, 2022

@zhen8838 Yet again this is closed. We currently have a release pending. This will be in the next one, which is usually once a month. A possible workaround, if feasible for you, is setting the env variable in a console / terminal, and start VSCode from there. That way the whole process tree including the debugger and omnisharp server will inherit it. It is little less dynamic than providing a settings file, but should work nonetheless.

@zhen8838
Copy link
Author

zhen8838 commented Apr 1, 2022

@nohwnd Thank you very much for your help! 👍

@nohwnd
Copy link
Member

nohwnd commented Apr 1, 2022

@zhen8838 I had hard time not including it in the release, so I just included it. The artifacts are now being uploaded. And there should be new version available soon, with this fix, 1.24.2.

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

Successfully merging a pull request may close this issue.

2 participants