Skip to content

Commit

Permalink
[fix] Test more package names converted to CamelCase in 'conan new -t…
Browse files Browse the repository at this point in the history
…' command (#6821)

* snake_case to CamelCase

* test other valid names for packages
  • Loading branch information
jgsogo committed Apr 14, 2020
1 parent 6d5d86f commit 2c73083
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 1 addition & 3 deletions conans/client/cmd/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ def cmd_new(ref, header=False, pure_c=False, test=False, exports_sources=False,
user, channel = tokens[1].split("/")
else:
user, channel = "user", "channel"

pattern = re.compile('[\W_]+')
package_name = pattern.sub('', name).capitalize()
package_name = re.sub(r"(?:^|[\W_])(\w)", lambda x: x.group(1).upper(), name)
except ValueError:
raise ConanException("Bad parameter, please use full package name,"
"e.g.: MyLib/1.2.3@user/testing")
Expand Down
18 changes: 13 additions & 5 deletions conans/test/functional/command/new_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import textwrap
import unittest

from parameterized import parameterized

from conans.test.utils.test_files import temp_folder
from conans.test.utils.tools import TestClient
from conans.tools import save
from conans.util.files import load


class NewTest(unittest.TestCase):
class NewCommandTest(unittest.TestCase):

def template_test(self):
client = TestClient()
Expand Down Expand Up @@ -87,23 +89,29 @@ def new_error_test(self):
self.assertIn("ERROR: Value provided for channel, 'u' (type str), is too short. Valid "
"names must contain at least 2 characters.", client.out)

def new_dash_test(self):
@parameterized.expand([("My-Package", "MyPackage"),
("my-package", "MyPackage"),
("my_package", "MyPackage"),
("my.Package", "MyPackage"),
("my+package", "MyPackage")])
def naming_test(self, package_name, python_class_name):
""" packages with dash
"""
client = TestClient()
client.run('new My-Package/1.3@myuser/testing -t')
client.run('new {}/1.3@myuser/testing -t'.format(package_name))
root = client.current_folder
self.assertTrue(os.path.exists(os.path.join(root, "conanfile.py")))
content = load(os.path.join(root, "conanfile.py"))
self.assertIn('name = "My-Package"', content)
self.assertIn('class {}Conan(ConanFile):'.format(python_class_name), content)
self.assertIn('name = "{}"'.format(package_name), content)
self.assertIn('version = "1.3"', content)
self.assertTrue(os.path.exists(os.path.join(root, "test_package/conanfile.py")))
self.assertTrue(os.path.exists(os.path.join(root, "test_package/CMakeLists.txt")))
self.assertTrue(os.path.exists(os.path.join(root, "test_package/example.cpp")))
# assert they are correct at least
client.run("export . myuser/testing")
client.run("search")
self.assertIn("My-Package/1.3@myuser/testing", client.out)
self.assertIn("{}/1.3@myuser/testing".format(package_name), client.out)

def new_header_test(self):
client = TestClient()
Expand Down

0 comments on commit 2c73083

Please sign in to comment.