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

Fix CMake.test() target for Ninja Multi-Config #11594

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion conan/tools/cmake/cmake.py
Expand Up @@ -153,7 +153,8 @@ def test(self, build_type=None, target=None, cli_args=None, build_tool_args=None
return
if not target:
is_multi = is_multi_configuration(self._generator)
target = "RUN_TESTS" if is_multi else "test"
is_ninja = "Ninja" in self._generator
target = "RUN_TESTS" if is_multi and not is_ninja else "test"

self._build(build_type=build_type, target=target, cli_args=cli_args,
build_tool_args=build_tool_args)
42 changes: 42 additions & 0 deletions conans/test/unittests/tools/cmake/test_cmake_test.py
@@ -0,0 +1,42 @@
import pytest

from conan.tools.cmake import CMake
from conan.tools.cmake.presets import write_cmake_presets
from conans.client.conf import get_default_settings_yml
from conans.model.conf import Conf
from conans.model.settings import Settings
from conans.test.utils.mocks import ConanFileMock
from conans.test.utils.test_files import temp_folder


@pytest.mark.parametrize("generator,target", [
("NMake Makefiles", "test"),
("Ninja Makefiles", "test"),
("Ninja Multi-Config", "test"),
("Unix Makefiles", "test"),
("Visual Studio 14 2015", "RUN_TESTS"),
("Xcode", "RUN_TESTS"),
])
def test_run_tests(generator, target):
"""
Testing that the proper test target is picked for different generators, especially multi-config ones.
Issue related: https://github.com/conan-io/conan/issues/11405
"""
settings = Settings.loads(get_default_settings_yml())
settings.os = "Windows"
settings.arch = "x86"
settings.build_type = "Release"
settings.compiler = "Visual Studio"
settings.compiler.runtime = "MDd"
settings.compiler.version = "14"

conanfile = ConanFileMock()
conanfile.conf = Conf()
conanfile.folders.generators = "."
conanfile.folders.set_base_generators(temp_folder())
conanfile.settings = settings

write_cmake_presets(conanfile, "toolchain", generator, {})
cmake = CMake(conanfile)
cmake.test()
assert "'--target' '%s'" % target in conanfile.command
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert "'--target' '%s'" % target in conanfile.command
if platform.system() == "Windows":
assert "--target %s" % target in conanfile.command
else:
assert "'--target' '%s'" % target in conanfile.command

There is a small difference atm in the command in Windows, the args are not quoted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc/ @lasote This is one of the things related to #11553, that seems a bit weird to me, that the commands quoting is different in different systems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. I added the platform import and made the search pattern conditional on the platform.