Skip to content

Commit

Permalink
fix for test_requires required components (#17174)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Oct 17, 2024
1 parent 66008be commit 15a9072
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conans/model/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def aggregate(self, other):
self.transitive_libs = self.transitive_libs or other.transitive_libs
if not other.test:
self.test = False # it it was previously a test, but also required by non-test
self.is_test = self.is_test or other.is_test
# package_id_mode is not being propagated downstream. So it is enough to check if the
# current require already defined it or not
if self.package_id_mode is None:
Expand Down Expand Up @@ -344,6 +345,7 @@ def transform_downstream(self, pkg_type, require, dep_pkg_type):

if self.test:
downstream_require.test = True
downstream_require.is_test = require.is_test

# If the current one is resolving conflicts, the downstream one will be too
downstream_require.force = require.force
Expand Down
32 changes: 32 additions & 0 deletions test/integration/graph/test_test_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,38 @@ def package_info(self):
assert "libc/0.1: Created package" in c.out


def test_requires_transitive_diamond_components_order():
"""
like the above, but in different order
libc --(test-requires)---> liba
|-----> libb -----------/
https://github.com/conan-io/conan/issues/17164
"""
c = TestClient(light=True)
libc = textwrap.dedent("""
from conan import ConanFile
class LibC(ConanFile):
name = "libc"
version = "0.1"
def requirements(self):
self.test_requires("liba/1.0")
self.requires("libb/1.0")
def package_info(self):
self.cpp_info.components["comp"].libs = ["libc"]
self.cpp_info.components["comp"].requires.append("libb::libb")
""")
c.save({"liba/conanfile.py": GenConanfile("liba", "1.0"),
"libb/conanfile.py": GenConanfile("libb", "1.0").with_requires("liba/1.0"),
"libc/conanfile.py": libc})
c.run("create liba")
c.run("create libb")
c.run("create libc")
# This used to crash due to component not defined to liba
assert "libc/0.1: Created package" in c.out


def test_test_requires_options():
""" the default_options = {} values also propagate to ``test_requires()`` """
c = TestClient(light=True)
Expand Down

0 comments on commit 15a9072

Please sign in to comment.