Skip to content

Commit

Permalink
fix: version ranges without user/channel
Browse files Browse the repository at this point in the history
  • Loading branch information
jgsogo committed Sep 4, 2019
1 parent df44fea commit 42ea6ec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions conans/search/search.py
Expand Up @@ -108,7 +108,7 @@ def search_recipes(cache, pattern=None, ignorecase=True):
refs = [ConanFileReference.load_dir_repr(folder) for folder in subdirs]
refs.extend(cache.editable_packages.edited_refs.keys())
if pattern:
refs = [r for r in refs if _partial_match(pattern, r)]
refs = [r for r in refs if _partial_match(pattern, repr(r))]
refs = sorted(refs)
return refs

Expand All @@ -117,7 +117,7 @@ def _partial_match(pattern, ref):
"""
Finds if pattern matches any of partial sums of tokens of conan reference
"""
tokens = str(ref).replace('/', ' / ').replace('@', ' @ ').replace('#', ' # ').split()
tokens = ref.replace('/', ' / ').replace('@', ' @ ').replace('#', ' # ').split()

def partial_sums(iterable):
partial = ''
Expand Down
41 changes: 41 additions & 0 deletions conans/test/functional/graph/version_range_no_userchannel_test.py
@@ -0,0 +1,41 @@
# coding=utf-8

import unittest

from conans.test.utils.tools import TestClient, GenConanfile


class VersionRangeNoUserChannelTestCase(unittest.TestCase):

def test_match(self):
t = TestClient()
t.save({"conanfile.py": GenConanfile(), })
t.run("export . libB/1.0@")

# Use version ranges without user/channel
t.save({"conanfile.py": GenConanfile().with_require_plain("libB/[~1.x]")})
t.run("info . --only requires")
self.assertIn("Version range '~1.x' required by 'conanfile.py'"
" resolved to 'libB/1.0' in local cache", t.out)

def test_no_match(self):
t = TestClient()
t.save({"conanfile.py": GenConanfile(), })
t.run("export . libB/1.0@user/channel")

# Use version ranges without user/channel
t.save({"conanfile.py": GenConanfile().with_require_plain("libB/[~1.x]")})
t.run("info . --only requires", assert_error=True)
self.assertIn("ERROR: Version range '~1.x' from requirement 'libB/[~1.x]' required"
" by 'conanfile.py' could not be resolved in local cache", t.out)

def test_no_match_with_userchannel(self):
t = TestClient()
t.save({"conanfile.py": GenConanfile(), })
t.run("export . libB/1.0@")

# Use version ranges with user/channel
t.save({"conanfile.py": GenConanfile().with_require_plain("libB/[~1.x]@user/channel")})
t.run("info . --only requires", assert_error=True)
self.assertIn("ERROR: Version range '~1.x' from requirement 'libB/[~1.x]@user/channel'"
" required by 'conanfile.py' could not be resolved in local cache", t.out)

0 comments on commit 42ea6ec

Please sign in to comment.