Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: define environment variables for CTest #4299

Merged
merged 2 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions conans/client/build/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,17 @@ def install(self, args=None, build_dir=None):
"defined" % cmake_install_prefix_var_name)
self._build(args=args, build_dir=build_dir, target="install")

def test(self, args=None, build_dir=None, target=None):
def test(self, args=None, build_dir=None, target=None, output_on_failure=False):
if not self._conanfile.should_test:
return
if not target:
target = "RUN_TESTS" if self.is_multi_configuration else "test"
self._build(args=args, build_dir=build_dir, target=target)

env = {'CTEST_OUTPUT_ON_FAILURE': '1' if output_on_failure else '0'}
if self.parallel:
env['CTEST_PARALLEL_LEVEL'] = str(cpu_count(self._conanfile.output))
with tools.environment_append(env):
SSE4 marked this conversation as resolved.
Show resolved Hide resolved
self._build(args=args, build_dir=build_dir, target=target)

@property
def verbose(self):
Expand Down
19 changes: 19 additions & 0 deletions conans/test/unittests/client/build/cmake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,3 +1160,22 @@ def test_vcvars_applied(self, generator, compiler, version):
vcvars_mock.__exit__ = mock.MagicMock(return_value=None)
cmake.build()
self.assertTrue(vcvars_mock.called, "vcvars weren't called")

def test_ctest_variables(self):
conanfile = ConanFileMock()
settings = Settings.loads(default_settings_yml)
settings.os = "Windows"
settings.compiler = "Visual Studio"
settings.compiler.version = "14"
conanfile.settings = settings

cmake = CMake(conanfile, parallel=False, generator="NMake Makefiles")
cmake.test()
self.assertEquals(conanfile.captured_env["CTEST_OUTPUT_ON_FAILURE"], "0")
self.assertNotIn("CTEST_PARALLEL_LEVEL", conanfile.captured_env)

with tools.environment_append({"CONAN_CPU_COUNT": "666"}):
cmake = CMake(conanfile, parallel=True, generator="NMake Makefiles")
cmake.test(output_on_failure=True)
self.assertEquals(conanfile.captured_env["CTEST_OUTPUT_ON_FAILURE"], "1")
self.assertEquals(conanfile.captured_env["CTEST_PARALLEL_LEVEL"], "666")