Skip to content

Commit

Permalink
Guard against unknown languages attribute values (#17512)
Browse files Browse the repository at this point in the history
Guard against languages misstype
  • Loading branch information
AbrilRBS authored Dec 19, 2024
1 parent 581a04a commit d819621
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conans/model/conan_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def __init__(self, display_name=""):
self.generators = [self.generators]
if isinstance(self.languages, str):
self.languages = [self.languages]
if not all(lang == "C" or lang == "C++" for lang in self.languages):
raise ConanException("Only 'C' and 'C++' languages are allowed in 'languages' attribute")
if isinstance(self.settings, str):
self.settings = [self.settings]
self.requires = Requirements(self.requires, self.build_requires, self.test_requires,
Expand Down
19 changes: 19 additions & 0 deletions test/integration/conanfile/conanfile_errors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,22 @@ def package_info(self):
tc.run("create cmake")
tc.run("create . -b=missing -pr=profile")
assert "cmake/1.0 -> True" not in tc.out


@pytest.mark.parametrize("languages", [
"['C', 'CXX']",
"['CXX']",
"'CXX'",
])
def test_language_unexpected(languages):
tc = TestClient(light=True)
tc.save({"conanfile.py": GenConanfile().with_class_attribute(f"languages = {languages}")})
tc.run("inspect .", assert_error=True)
assert "Only 'C' and 'C++' languages are allowed in 'languages' attribute" in tc.out


def test_empty_languages():
tc = TestClient(light=True)
tc.save({"conanfile.py": GenConanfile().with_class_attribute("languages = []")})
tc.run("inspect .")
assert "Only 'C' and 'C++' languages are allowed in 'languages' attribute" not in tc.out

0 comments on commit d819621

Please sign in to comment.