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

Allow [tool] or [tools] section in Rust Env Checker #931

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion edk2toolext/environment/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _get_required_tool_versions() -> Dict[str, str]:
try:
with open(WORKSPACE_TOOLCHAIN_FILE, "r") as toml_file:
content = toml_file.read()
match = re.search(r"\[tool\]\n((?:.+\s*=\s*.+\n?)*)", content)
match = re.search(r"\[tool(?:s)?\]\n((?:.+\s*=\s*.+\n?)*)", content)
if match:
for line in match.group(1).splitlines():
(tool, version) = line.split("=", maxsplit=1)
Expand Down
24 changes: 12 additions & 12 deletions tests.unit/test_rust_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,18 @@ def test_verify_rust_src_component_is_installed(
self.assertTrue(result)

def test_get_required_tool_versions(self):
# Test when the workspace toolchain file exists and contains valid tool versions
with patch(
"builtins.open",
mock_open(
read_data='[toolchain]\nchannel = "1.76.0"\n\n[tool]\ncargo-make = "0.37.9"\ncargo-tarpaulin = "0.27.3"'
),
):
tool_versions = _get_required_tool_versions()
assert tool_versions == {
"cargo-make": "0.37.9",
"cargo-tarpaulin": "0.27.3",
}
test_data = [
'[toolchain]\nchannel = "1.76.0"\n\n[tool]\ncargo-make = "0.37.9"\ncargo-tarpaulin = "0.27.3"',
'[toolchain]\nchannel = "1.76.0"\n\n[tools]\ncargo-make = "0.37.9"\ncargo-tarpaulin = "0.27.3"',
]

for data in test_data:
with patch("builtins.open", mock_open(read_data=data)):
tool_versions = _get_required_tool_versions()
assert tool_versions == {
"cargo-make": "0.37.9",
"cargo-tarpaulin": "0.27.3",
}

# Test when the workspace toolchain file does not exist
with patch("builtins.open", side_effect=FileNotFoundError):
Expand Down