From ef4bb7ff8e2fc3c7d37adbbdb0565966562bd366 Mon Sep 17 00:00:00 2001 From: SSE4 Date: Tue, 15 Jan 2019 06:53:59 +0700 Subject: [PATCH 1/2] - define environment variables for CTest Signed-off-by: SSE4 --- conans/client/build/cmake.py | 10 +++++++-- .../test/unittests/client/build/cmake_test.py | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py index bc73e718406..b9b60472a3b 100644 --- a/conans/client/build/cmake.py +++ b/conans/client/build/cmake.py @@ -233,12 +233,18 @@ 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, progress=False, 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_PROGRESS_OUTPUT': '1' if progress else '0', + '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): + self._build(args=args, build_dir=build_dir, target=target) @property def verbose(self): diff --git a/conans/test/unittests/client/build/cmake_test.py b/conans/test/unittests/client/build/cmake_test.py index f2ff1b0c43d..6199eeece64 100644 --- a/conans/test/unittests/client/build/cmake_test.py +++ b/conans/test/unittests/client/build/cmake_test.py @@ -1160,3 +1160,24 @@ 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_PROGRESS_OUTPUT"], "0") + 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(progress=True, output_on_failure=True) + self.assertEquals(conanfile.captured_env["CTEST_PROGRESS_OUTPUT"], "1") + self.assertEquals(conanfile.captured_env["CTEST_OUTPUT_ON_FAILURE"], "1") + self.assertEquals(conanfile.captured_env["CTEST_PARALLEL_LEVEL"], "666") From 137144a758928a257009dbaf2a276e7574df328c Mon Sep 17 00:00:00 2001 From: SSE4 Date: Tue, 15 Jan 2019 22:36:03 +0700 Subject: [PATCH 2/2] - remove CTEST_PROGRESS_OUTPUT as it has no effect Signed-off-by: SSE4 --- conans/client/build/cmake.py | 5 ++--- conans/test/unittests/client/build/cmake_test.py | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py index b9b60472a3b..5847f66dca9 100644 --- a/conans/client/build/cmake.py +++ b/conans/client/build/cmake.py @@ -233,14 +233,13 @@ 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, progress=False, output_on_failure=False): + 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" - env = {'CTEST_PROGRESS_OUTPUT': '1' if progress else '0', - 'CTEST_OUTPUT_ON_FAILURE': '1' if output_on_failure else '0'} + 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): diff --git a/conans/test/unittests/client/build/cmake_test.py b/conans/test/unittests/client/build/cmake_test.py index 6199eeece64..c1ced863e7b 100644 --- a/conans/test/unittests/client/build/cmake_test.py +++ b/conans/test/unittests/client/build/cmake_test.py @@ -1171,13 +1171,11 @@ def test_ctest_variables(self): cmake = CMake(conanfile, parallel=False, generator="NMake Makefiles") cmake.test() - self.assertEquals(conanfile.captured_env["CTEST_PROGRESS_OUTPUT"], "0") 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(progress=True, output_on_failure=True) - self.assertEquals(conanfile.captured_env["CTEST_PROGRESS_OUTPUT"], "1") + 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")