Skip to content

Commit

Permalink
Profiles added to test command (conan-io#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasote authored Oct 20, 2016
1 parent 64e3813 commit 0ea4629
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 4 additions & 2 deletions conans/client/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
39 changes: 38 additions & 1 deletion conans/test/integration/profile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())

0 comments on commit 0ea4629

Please sign in to comment.