Skip to content

Commit

Permalink
Consider default value when resolving environment variable. Fixes #715
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Aug 2, 2022
1 parent 6c24dcb commit 6588b74
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ def _convert_environment_variable(
) -> Optional[str]:
from robotframework_ls.impl.robot_lsp_constants import OPTION_ROBOT_PYTHON_ENV

i = var_name.find("=")
if i > 0:
value_if_not_found = var_name[i + 1 :]
var_name = var_name[:i]

if self.config is None:
value = self._resolve_environment_variable(
var_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,31 @@ def test_code_analysis_environment_variable_in_resource_import_2(
)


def test_code_analysis_environment_variable_default_value(
workspace, libspec_manager, data_regression, monkeypatch
):
monkeypatch.setenv("ENV_VAR_IN_RESOURCE_IMPORT", "./my")

workspace.set_root("case2", libspec_manager=libspec_manager)
doc = workspace.put_doc("my/bar/keywords.resource")
doc.source = """
*** Keywords ***
Common Keyword
Log to console Common keyword"""

doc = workspace.put_doc("case2.robot")
doc.source = """
*** Settings ***
Resource %{RESOURCES_ENV=${RESOURCES}}/keywords.resource
*** Variables ***
${RESOURCES} %{ENV_VAR_IN_RESOURCE_IMPORT}/bar
"""

_collect_errors(workspace, doc, data_regression, basename="no_error")


def test_code_analysis_environment_variable_in_resource_import_3(
workspace, libspec_manager, data_regression
):
Expand Down

0 comments on commit 6588b74

Please sign in to comment.