question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CMake ctest helper

See original GitHub issue

Hi!

The awesome feature, cmake helper, made my life easier to write some receipts, but when I need write some test_package conanfile, I have:

    cmake = None

    def build(self):
        self.cmake = CMake(self.settings)
        self.cmake.configure(self, source_dir=self.conanfile_directory, build_dir="./")
        self.cmake.build(self)

    def test(self):
        target_test = "RUN_TESTS" if self.settings.os == "Windows" else "test"
        self.cmake.build(self, target=target_test)

I use CTest for my unit tests, so, I put enable_testing and add_test in my cmake file, but I need select the target word by platform. Maybe, would be a better approach if I have:

    cmake = None

    def build(self):
        self.cmake = CMake(self.settings)
        self.cmake.configure(self, source_dir=self.conanfile_directory, build_dir="./")
        self.cmake.build(self)

    def test(self):
        self.cmake.test(self)

This helper will solve the target name by platform and call cmake.build.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
uilianriescommented, Jun 25, 2017

Right, was merged in Conan 0.22.

Regards.

1reaction
uilianriescommented, Mar 24, 2017

By default, CMake apply test for Linux, or RUN_TESTS for Visual Studio, as target, when enable_testing() is present in CMakeFile.txt.
Here is the explanation: Testing_With_CTest

However, anyone can create a custom target instead to run CTest:

# CMakeLists.txt
add_executable(test-app main.cpp)
add_custom_target(run-all-tests
                  WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
                  COMMAND test-app)
add_dependecies(run-all-tests test-app)                                

And run:

$ cmake --build . --target run-all-tests

In this case, the better choice is just use cmake.build(self, target="run-all-tests").

Great idea, I can implement this little point 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

ctest(1) — CMake 3.25.1 Documentation
The ctest executable is the CMake test driver program. CMake-generated build trees created for projects that use the enable_testing() and add_test() commands ...
Read more >
CTest - Cross Platform Make - CMake
The "ctest" executable is the CMake test driver program. CMake-generated build trees created for projects that use the ENABLE_TESTING and ADD_TEST commands have ......
Read more >
Testing With CMake and CTest
CTest is an executable that comes with CMake; it handles running the tests for the project. While CTest works well with CMake, you...
Read more >
add_test — CMake 3.25.1 Documentation
This creates a test mytest whose command runs a testDriver tool passing the configuration name and the full path to the executable file...
Read more >
CTest — CMake 3.25.1 Documentation
Configure a project for testing with CTest/CDash. Include this module in the top CMakeLists.txt file of a project to enable testing with CTest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found