![]() ![]() Passed 0.11 secĢ/2 Test #2: TestTextMiningApp. Test project ġ/2 Test #1: TestTextMiningCompiler. equivalent to calling ctest): $ make test Set(pathword "$/test.txt" "totoro.txt"Īnd no need to add a time call since total time of execution is automatically measured when executing the test via make test (which is btw. Using the name of an executable's CMake target as "command" in add_test() directly replaces it with the excutable's path: cmake_minimum_required(VERSION 2.8.9) get test reports via ctest (distributed with CMake). It enables - besides calling something like make test to run the tests - the possibility to e.g. When it gets to tests in CMake I prefer to use add_test(). How can I have the make run function? or other custom function? Set_property(TARGET TextMiningCompiler PROPERTY CXX_STANDARD 11) Set_property(TARGET TextMiningApp PROPERTY CXX_STANDARD 11) I made this CMakefile: cmake_minimum_required(VERSION 2.8.9)Īdd_executable(TextMiningApp TextMiningApp.cpp)Īdd_executable(TextMiningCompiler TextMiningCompiler.cpp trie.cpp read_words_file.cpp) TextMiningCompiler $(pathword) totoro.txtĬat test.txt | time. G++ $(flags) TextMiningApp.cpp -o TextMiningApp G++ $(flags) TextMiningCompiler.cpp trie.cpp -o TextMiningCompiler TextMiningCompiler: TextMiningCompiler.cpp trie.cpp I use makefile not only for build my project but also to test my project.įor exemple this makefile: pathword=words.txtĭefault: TextMiningCompiler TextMiningApp ![]() ![]() See Catch2 chapter and replace with DocTest.I use usually makefile for project but I want to start learn CMake. DocTest: A replacement for Catch2 that is supposed to compile much faster and be cleaner.Catch2: A modern, PyTest-like framework with clever macros.GoogleTest: A popular option from Google.Look at the subchapters for recipes for popular frameworks. For example, if your master project was called MyProject and you had an examples/simple project that could build by itself, this would look like: add_test( If you want to run CMake to build a project as part of a test, you can do that too (in fact, this is how CMake tests itself). Which would use the output location (thus, the executable) of the produced target. It would also be valid to put the generator expression: add_test(NAME TestName COMMAND $) If you put something else besides a target name after COMMAND, it will register as a command line to run. You can register targets with: add_test(NAME TestName COMMAND TargetName) The main use case for the override above is actually in this book's own examples, as the master CMake project really does want to run all the subproject tests. In the rare case that you really do want to enable testing on both packages, you can provide an override: if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MYPROJECT_BUILD_TESTING) AND BUILD_TESTING) The reason for this is that if someone else includes your package, and they use BUILD_TESTING, they probably do not want your tests to build. When you add your test folder, you should do something like this: if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) The ctest command without arguments will run the entire set of tests. Or you can do this yourself by directly calling enable_testing(). For example, you can tell CMake that you need the netcdf and openmpi libraries. Which will enable testing and set a BUILD_TESTING option so users can turn testing on and off (along with a few other things). In your main CMakeLists.txt you need to add the following function call (not in a subfolder): if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |