mirror of
https://github.com/intel/llvm.git
synced 2026-01-17 23:45:25 +08:00
Summary:
If no custom launching is used, lldb-vscode launches a program with an empty environment by default. In some scenarios, the user might want to simply use the same environment as the IDE to have a set of working environment variables (e.g. PATH wouldn't be empty). In fact, most DAPs in VSCode have this behavior by default. In other cases the user definitely needs to set their custom environment, which is already supported. To make the first case easier for the user (e.g. not having to copy the PATH to the launch.json every time they want to debug simple programs that rely on PATH), a new option is now offered. inheritEnvironment will launch the program copying its own environment, and it's just a boolean flag.
{F11347695}
Reviewers: clayborg, aadsm, diazhector98, kusmour
Subscribers: labath, JDevlieghere, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D74636
108 lines
3.1 KiB
Python
108 lines
3.1 KiB
Python
"""
|
|
Test lldb-vscode environment variables
|
|
"""
|
|
|
|
|
|
import lldbvscode_testcase
|
|
import unittest2
|
|
import vscode
|
|
import os
|
|
from lldbsuite.test import lldbutil
|
|
from lldbsuite.test.decorators import *
|
|
from lldbsuite.test.lldbtest import *
|
|
|
|
class TestVSCode_variables(lldbvscode_testcase.VSCodeTestCaseBase):
|
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
def getEnvOutputByProgram(self):
|
|
env = {}
|
|
for line in self.get_stdout().encode('utf-8').splitlines():
|
|
(name, value) = line.split("=")
|
|
env[name] = value
|
|
return env
|
|
|
|
@skipIfWindows
|
|
@skipIfRemote
|
|
def test_empty_environment(self):
|
|
"""
|
|
Tests running a process with an empty environment
|
|
"""
|
|
program = self.getBuildArtifact("a.out")
|
|
self.build_and_launch(program)
|
|
self.continue_to_exit()
|
|
env = self.getEnvOutputByProgram()
|
|
|
|
self.assertNotIn("PATH", env)
|
|
|
|
@skipIfWindows
|
|
@skipIfRemote
|
|
def test_inheriting_environment(self):
|
|
"""
|
|
Tests running a process inheriting the environment
|
|
"""
|
|
program = self.getBuildArtifact("a.out")
|
|
self.build_and_launch(program, inheritEnvironment=True, env=["FOO=bar"])
|
|
self.continue_to_exit()
|
|
env = self.getEnvOutputByProgram()
|
|
|
|
self.assertEqual(env["PATH"], os.environ['PATH'])
|
|
self.assertEqual(env["FOO"], "bar")
|
|
|
|
@skipIfWindows
|
|
@skipIfRemote
|
|
def test_override_when_inheriting_environment(self):
|
|
"""
|
|
Tests the environment variables priority.
|
|
The launch.json's environment has precedence.
|
|
"""
|
|
program = self.getBuildArtifact("a.out")
|
|
new_path_value = "#" + os.environ["PATH"]
|
|
|
|
self.build_and_launch(
|
|
program,
|
|
inheritEnvironment=True,
|
|
env=["PATH=" + new_path_value])
|
|
self.continue_to_exit()
|
|
env = self.getEnvOutputByProgram()
|
|
|
|
self.assertEqual(env["PATH"], new_path_value)
|
|
|
|
@skipIfWindows
|
|
@skipIfRemote
|
|
def test_empty_environment_custom_launcher(self):
|
|
"""
|
|
Tests running a process with an empty environment from a custom
|
|
launcher
|
|
"""
|
|
program = self.getBuildArtifact("a.out")
|
|
self.build_and_create_debug_adaptor()
|
|
|
|
launchCommands = [
|
|
'target create "%s"' % (program),
|
|
"run"
|
|
]
|
|
self.launch(launchCommands=launchCommands)
|
|
self.continue_to_exit()
|
|
env = self.getEnvOutputByProgram()
|
|
self.assertNotIn("PATH", env)
|
|
|
|
@skipIfWindows
|
|
@skipIfRemote
|
|
def test_inheriting_environment_custom_launcher(self):
|
|
"""
|
|
Tests running a process from a custom launcher inheriting the
|
|
environment
|
|
"""
|
|
program = self.getBuildArtifact("a.out")
|
|
self.build_and_create_debug_adaptor()
|
|
|
|
launchCommands = [
|
|
'target create "%s"' % (program),
|
|
"run"
|
|
]
|
|
self.launch(launchCommands=launchCommands, inheritEnvironment=True)
|
|
self.continue_to_exit()
|
|
env = self.getEnvOutputByProgram()
|
|
self.assertIn("PATH", env)
|