diff --git a/edk2toolext/environment/rust.py b/edk2toolext/environment/rust.py index 792f2e08..9df15705 100644 --- a/edk2toolext/environment/rust.py +++ b/edk2toolext/environment/rust.py @@ -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) diff --git a/tests.unit/test_rust_environment.py b/tests.unit/test_rust_environment.py index d03427cf..f15bc48f 100644 --- a/tests.unit/test_rust_environment.py +++ b/tests.unit/test_rust_environment.py @@ -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):