From 0ea4629c3be5a755d520f7a0330625edbcdb571a Mon Sep 17 00:00:00 2001 From: Luis Date: Thu, 20 Oct 2016 10:46:05 +0200 Subject: [PATCH] Profiles added to test command (#580) --- conans/client/command.py | 6 ++-- conans/test/integration/profile_test.py | 39 ++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/conans/client/command.py b/conans/client/command.py index fb378726565..ac8270bc504 100644 --- a/conans/client/command.py +++ b/conans/client/command.py @@ -211,6 +211,7 @@ def test_package(self, *args): 'Use for testing purposes only') parser.add_argument("--update", "-u", action='store_true', default=False, help="update with new upstream packages") + parser.add_argument("--profile", "-pr", default=None, help='Define a profile') self._parse_args(parser) args = parser.parse_args(*args) @@ -276,9 +277,10 @@ def test_package(self, *args): settings=settings, build_mode=args.build, scopes=scopes, - update=args.update) + update=args.update, + profile_name=args.profile) self._test_check(test_folder, test_folder_name) - self._manager.build(test_folder, build_folder, test=True) + self._manager.build(test_folder, build_folder, test=True, profile_name=args.profile) # Alias to test def test(self, *args): diff --git a/conans/test/integration/profile_test.py b/conans/test/integration/profile_test.py index c5c94f2112f..e0f71f4b2c0 100644 --- a/conans/test/integration/profile_test.py +++ b/conans/test/integration/profile_test.py @@ -95,6 +95,43 @@ def scopes_env_test(self): self.assertFalse(os.environ.get("CC", None) == "/path/tomy/gcc") self.assertFalse(os.environ.get("CXX", None) == "/path/tomy/g++") + def test_package_test(self): + test_conanfile = '''from conans.model.conan_file import ConanFile +from conans import CMake +import os + +class DefaultNameConan(ConanFile): + name = "DefaultName" + version = "0.1" + settings = "os", "compiler", "arch", "build_type" + requires = "Hello0/0.1@lasote/stable" + + def build(self): + # Print environment vars + # self.run('cmake %s %s' % (self.conanfile_directory, cmake.command_line)) + if self.settings.os == "Windows": + self.run('echo "My var is %ONE_VAR%"') + else: + self.run('echo "My var is $ONE_VAR"') + + def test(self): + pass + +''' + files = {} + files["conanfile.py"] = conanfile_scope_env + files["test_package/conanfile.py"] = test_conanfile + # Create a profile and use it + self._create_profile("scopes_env", {}, + {}, + {"ONE_VAR": "ONE_VALUE"}) + + self.client.save(files) + self.client.run("test_package --profile scopes_env") + + self._assert_env_variable_printed("ONE_VAR", "ONE_VALUE") + self.assertIn("My var is ONE_VALUE", str(self.client.user_io.out)) + def _assert_env_variable_printed(self, name, value): if platform.system() == "Windows": self.assertIn("%s=%s" % (name, value), self.client.user_io.out) @@ -109,4 +146,4 @@ def _create_profile(self, name, settings, scopes=None, env=None): if scopes: profile.scopes = Scopes.from_list(["%s=%s" % (key, value) for key, value in scopes.items()]) profile.env = env or {} - save(self.client.client_cache.profile_path(name), profile.dumps()) + save(self.client.client_cache.profile_path(name), profile.dumps()) \ No newline at end of file