|
1 | | -import os |
2 | | -import textwrap |
3 | | -import unittest |
| 1 | +from conans.test.assets.genconanfile import GenConanfile |
| 2 | +from conans.test.utils.tools import TestClient |
4 | 3 |
|
5 | | -import pytest |
6 | 4 |
|
7 | | -from conans.util.env import environment_update |
8 | | -from conans.paths import CONANFILE |
9 | | -from conans.test.utils.tools import TestClient, load |
10 | | -import json |
11 | | - |
12 | | - |
13 | | -@pytest.mark.xfail(reason="Conflict Output have changed") |
14 | | -class ConflictDiamondTest(unittest.TestCase): |
15 | | - conanfile = textwrap.dedent(""" |
16 | | - from conan import ConanFile |
17 | | -
|
18 | | - class HelloReuseConan(ConanFile): |
19 | | - name = "%s" |
20 | | - version = "%s" |
21 | | - requires = %s |
22 | | - """) |
23 | | - |
24 | | - def _export(self, name, version, deps=None, export=True): |
25 | | - deps = ", ".join(['"%s"' % d for d in deps or []]) or '""' |
26 | | - conanfile = self.conanfile % (name, version, deps) |
27 | | - files = {CONANFILE: conanfile} |
28 | | - self.client.save(files, clean_first=True) |
29 | | - if export: |
30 | | - self.client.run("export . --user=lasote --channel=stable") |
31 | | - |
32 | | - def setUp(self): |
33 | | - self.client = TestClient() |
34 | | - self._export("hello0", "0.1") |
35 | | - self._export("hello0", "0.2") |
36 | | - self._export("hello1", "0.1", ["hello0/0.1@lasote/stable"]) |
37 | | - self._export("Hello2", "0.1", ["hello0/0.2@lasote/stable"]) |
38 | | - |
39 | | - def test_conflict(self): |
40 | | - """ There is a conflict in the graph: branches with requirement in different |
41 | | - version, Conan will raise |
| 5 | +class TestConflictDiamondTest: |
| 6 | + def test_version_diamond_conflict(self): |
42 | 7 | """ |
43 | | - self._export("Hello3", "0.1", ["hello1/0.1@lasote/stable", "hello2/0.1@lasote/stable"], |
44 | | - export=False) |
45 | | - self.client.run("install . --build missing", assert_error=True) |
46 | | - self.assertIn("Conflict in hello2/0.1@lasote/stable:\n" |
47 | | - " 'hello2/0.1@lasote/stable' requires 'hello0/0.2@lasote/stable' " |
48 | | - "while 'hello1/0.1@lasote/stable' requires 'hello0/0.1@lasote/stable'.\n" |
49 | | - " To fix this conflict you need to override the package 'hello0' in " |
50 | | - "your root package.", self.client.out) |
51 | | - self.assertNotIn("Generated conaninfo.txt", self.client.out) |
52 | | - |
53 | | - def test_override_silent(self): |
54 | | - """ There is a conflict in the graph, but the consumer project depends on the conflicting |
55 | | - library, so all the graph will use the version from the consumer project |
| 8 | + test that we obtain a version conflict with a diamond, and that we can fix it by |
| 9 | + defining an override in the "game" consumer |
56 | 10 | """ |
57 | | - self._export("Hello3", "0.1", |
58 | | - ["hello1/0.1@lasote/stable", "hello2/0.1@lasote/stable", |
59 | | - "hello0/0.1@lasote/stable"], export=False) |
60 | | - self.client.run("install . --build missing", assert_error=False) |
61 | | - self.assertIn("hello2/0.1@lasote/stable: requirement hello0/0.2@lasote/stable overridden" |
62 | | - " by Hello3/0.1 to hello0/0.1@lasote/stable", |
63 | | - self.client.out) |
64 | | - |
65 | | - |
66 | | -@pytest.mark.xfail(reason="UX conflict error to be completed") |
67 | | -def test_create_werror(): |
68 | | - client = TestClient() |
69 | | - client.save({"conanfile.py": """from conan import ConanFile |
70 | | -class Pkg(ConanFile): |
71 | | -pass |
72 | | - """}) |
73 | | - client.run("export . --name=LibA --version=0.1 --user=user --channel=channel") |
74 | | - client.run("export conanfile.py --name=LibA --version=0.2 --user=user --channel=channel") |
75 | | - client.save({"conanfile.py": """from conan import ConanFile |
76 | | -class Pkg(ConanFile): |
77 | | -requires = "LibA/0.1@user/channel" |
78 | | - """}) |
79 | | - client.run("export ./ --name=LibB --version=0.1 --user=user --channel=channel") |
80 | | - client.save({"conanfile.py": """from conan import ConanFile |
81 | | -class Pkg(ConanFile): |
82 | | -requires = "LibA/0.2@user/channel" |
83 | | - """}) |
84 | | - client.run("export . --name=LibC --version=0.1 --user=user --channel=channel") |
85 | | - client.save({"conanfile.py": """from conan import ConanFile |
86 | | -class Pkg(ConanFile): |
87 | | -requires = "LibB/0.1@user/channel", "LibC/0.1@user/channel" |
88 | | - """}) |
89 | | - client.run("create ./conanfile.py consumer/0.1@lasote/testing", assert_error=True) |
90 | | - self.assertIn("ERROR: Conflict in LibC/0.1@user/channel", |
91 | | - client.out) |
| 11 | + c = TestClient() |
| 12 | + c.save({"math/conanfile.py": GenConanfile("math"), |
| 13 | + "engine/conanfile.py": GenConanfile("engine", "1.0").with_requires("math/1.0"), |
| 14 | + "ai/conanfile.py": GenConanfile("ai", "1.0").with_requires("math/1.0.1"), |
| 15 | + "game/conanfile.py": GenConanfile("game", "1.0").with_requires("engine/1.0", |
| 16 | + "ai/1.0"), |
| 17 | + }) |
| 18 | + c.run("create math --version=1.0") |
| 19 | + c.run("create math --version=1.0.1") |
| 20 | + c.run("create math --version=1.0.2") |
| 21 | + c.run("create engine") |
| 22 | + c.run("create ai") |
| 23 | + c.run("install game", assert_error=True) |
| 24 | + assert "Version conflict: ai/1.0->math/1.0.1, game/1.0->math/1.0" in c.out |
| 25 | + |
| 26 | + def _game_conanfile(version, reverse=False): |
| 27 | + if reverse: |
| 28 | + return GenConanfile("game", "1.0")\ |
| 29 | + .with_requirement(f"math/{version}", override=True)\ |
| 30 | + .with_requirement("engine/1.0")\ |
| 31 | + .with_requirement("ai/1.0") |
| 32 | + else: |
| 33 | + return GenConanfile("game", "1.0").with_requirement("engine/1.0") \ |
| 34 | + .with_requirement("ai/1.0") \ |
| 35 | + .with_requirement(f"math/{version}", override=True) |
| 36 | + |
| 37 | + for v in ("1.0", "1.0.1", "1.0.2"): |
| 38 | + c.save({"game/conanfile.py": _game_conanfile(v)}) |
| 39 | + c.run("install game") |
| 40 | + c.assert_listed_require({f"math/{v}": "Cache"}) |
| 41 | + |
| 42 | + # Check that order of requirements doesn't affect |
| 43 | + for v in ("1.0", "1.0.1", "1.0.2"): |
| 44 | + c.save({"game/conanfile.py": _game_conanfile(v, reverse=True)}) |
| 45 | + c.run("install game") |
| 46 | + c.assert_listed_require({f"math/{v}": "Cache"}) |
0 commit comments