for MathFunctions :我们想安装库和头文件 for the application :我们想安装可执行文件 and 配置头文件.
现在我们就可以测试以下我们的应用了,在顶层的CMakeLists.txt的末尾添加如下的代码:
enable_testing() # does the application run 第一个测试 add_test(NAME Runs COMMAND Tutorial 25) # does the usage message work? 第二个测试 add_test(NAME Usage COMMAND Tutorial) set_tests_properties(Usage PROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number" ) # define a function to simplify adding tests 以下为第三个测试 function(do_test target arg result) add_test(NAME Comp${arg} COMMAND ${target} ${arg}) set_tests_properties(Comp${arg} PROPERTIES PASS_REGULAR_EXPRESSION ${result} ) endfunction(do_test) # do a bunch of result based tests do_test(Tutorial 4 "4 is 2") do_test(Tutorial 9 "9 is 3") do_test(Tutorial 5 "5 is 2.236") do_test(Tutorial 7 "7 is 2.645") do_test(Tutorial 25 "25 is 5") do_test(Tutorial -25 "-25 is [-nan|nan|0]") do_test(Tutorial 0.0001 "0.0001 is 0.01")添加完成后,重新编译,进到可执行文件所在的文件夹,执行ctest -N 执行下面的命令ctest -VV,会执行我们定义的测试,以下为执行结果: 对于多配置生成器(例如Visual Studio),必须指定配置类型。 例如,要在Debug模式下运行测试,请从构建目录(而不是Debug子目录!)中使用ctest -C Debug -VV。 或者,从IDE构建RUN_TESTS目标。