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

fix issue with test_requires and components #13191

Merged
merged 1 commit into from
Feb 27, 2023
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
4 changes: 3 additions & 1 deletion conans/model/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,13 @@ def check_component_requires(self, conanfile):
# Only direct host dependencies can be used with components
direct_dependencies = [d.ref.name
for d, _ in conanfile.dependencies.filter({"direct": True,
"build": False}).items()]
"build": False,
"test": False}).items()]
for e in external:
if e not in direct_dependencies:
raise ConanException(
f"{conanfile}: required component package '{e}::' not in dependencies")
# TODO: discuss if there are cases that something is required but not transitive
for e in direct_dependencies:
if e not in external:
raise ConanException(
Expand Down
30 changes: 30 additions & 0 deletions conans/test/integration/graph/test_test_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,33 @@ def build_requirements(self):
assert "gtest/1.0: MYOPTION: 2" in c.out
c.run("create engine -o gtest*:myoption=3")
assert "gtest/1.0: MYOPTION: 3" in c.out


def test_requires_components():
""" this test used to fail with "gtest" not required by components
It is important to have at least 1 external ``requires`` because with
no requires at all it doesn't fail.
https://github.com/conan-io/conan/issues/13187
"""
c = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile

class MyLib(ConanFile):
name = "mylib"
version = "0.1"

requires = "openssl/1.1"
test_requires = "gtest/1.0"

def package_info(self):
self.cpp_info.components["mylib"].requires = ["openssl::openssl"]
""")
c.save({"gtest/conanfile.py": GenConanfile("gtest", "1.0"),
"openssl/conanfile.py": GenConanfile("openssl", "1.1"),
"pkg/conanfile.py": conanfile})
c.run("create gtest")
c.run("create openssl")
c.run("create pkg")
# This NO LONGER FAILS
c.assert_listed_require({"gtest/1.0": "Cache"}, test=True)