Een*_*oku 4 c++ unit-testing code-coverage cmake
我在我的项目中使用Boost 单元测试框架实现了单元测试,并组织成几个模块,即:
#define BOOST_TEST_MODULE Connection_test
#ifndef BOOST_TEST_DYN_LINK
#define BOOST_TEST_DYN_LINK
#endif
#ifndef BOOST_TEST_NO_MAIN
#define BOOST_TEST_NO_MAIN
#endif
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
#define BOOST_TEST_MODULE Connection_test
BOOST_AUTO_TEST_SUITE(Connection_test)
BOOST_AUTO_TEST_CASE(Connection_construction__test) {
***
}
BOOST_AUTO_TEST_SUITE_END()
Run Code Online (Sandbox Code Playgroud)
我将每个模块编译为单个可执行文件。
我想使用CodeCoverage.cmake模块来运行代码覆盖率分析,但我遇到了问题。我应该指定一个测试可执行文件SETUP_TARGET_FOR_COVERAGE_LCOV,但我没有只有一个。
有没有办法一次设置多个测试可执行文件CodeCoverage.cmake?
我已经将测试添加add_test()到我的根 CMakeLists.txt 并像这样修改了我的覆盖目标
include(CTest)
add_test(NAME constant_neuron_test COMMAND constant_neuron_test)
add_test(NAME binary_neuron_test COMMAND binary_neuron_test)
add_test(NAME logistic_neuron_test COMMAND logistic_neuron_test)
add_test(NAME connectionFunctionGeneral_test COMMAND connectionFunctionGeneral_test)
add_test(NAME connection_Function_identity_test COMMAND connection_Function_identity_test)
add_test(NAME neural_network_test COMMAND neural_network_test)
add_test(NAME dataset_test COMMAND dataset_test)
add_test(NAME particle_swarm_test COMMAND particle_swarm_test)
add_test(NAME particle_test COMMAND particle_test)
add_test(NAME NeuralNetworkSum_test COMMAND NeuralNetworkSum_test)
add_test(NAME errorfunction_test COMMAND errorfunction_test)
add_test(NAME DESolver_test COMMAND DESolver_test)
include(CodeCoverage.cmake)
APPEND_COVERAGE_COMPILER_FLAGS()
SETUP_TARGET_FOR_COVERAGE_LCOV(
NAME coverage # New target name
EXECUTABLE ctest -C ${ROOT_DIR}/CTestTestfile.cmake # Executable in PROJECT_BINARY_DIR
DEPENDENCIES ${Boost_LIBRARIES} # Dependencies to build first
)
Run Code Online (Sandbox Code Playgroud)
ctest 本身运行正常:
Test project /home/martin/4Neuro
Start 1: constant_neuron_test
1/12 Test #1: constant_neuron_test ................ Passed 0.04 sec
Start 2: binary_neuron_test
2/12 Test #2: binary_neuron_test .................. Passed 0.04 sec
Start 3: logistic_neuron_test
3/12 Test #3: logistic_neuron_test ................ Passed 0.05 sec
Start 4: connectionFunctionGeneral_test
4/12 Test #4: connectionFunctionGeneral_test ...... Passed 0.04 sec
Start 5: connection_Function_identity_test
5/12 Test #5: connection_Function_identity_test ... Passed 0.04 sec
Start 6: neural_network_test
6/12 Test #6: neural_network_test ................. Passed 0.04 sec
Start 7: dataset_test
7/12 Test #7: dataset_test ........................ Passed 0.04 sec
Start 8: particle_swarm_test
8/12 Test #8: particle_swarm_test ................. Passed 0.04 sec
Start 9: particle_test
9/12 Test #9: particle_test ....................... Passed 0.04 sec
Start 10: NeuralNetworkSum_test
10/12 Test #10: NeuralNetworkSum_test ............... Passed 0.05 sec
Start 11: errorfunction_test
11/12 Test #11: errorfunction_test .................. Passed 0.04 sec
Start 12: DESolver_test
12/12 Test #12: DESolver_test ....................... Passed 0.05 sec
100% tests passed, 0 tests failed out of 12
Total Test time (real) = 0.53 sec
Run Code Online (Sandbox Code Playgroud)
但是当我尝试通过创建我的覆盖率报告时make coverage,我收到此错误:
Processing code coverage counters and generating report.
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov -directory . --zerocounters
Deleting all .da files in . and subdirectories
Done.
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov -c -i -d . -o coverage.base
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcno files ...
geninfo: WARNING: no .gcno files found in . - skipping!
Finished .info-file creation
cd /home/martin/4Neuro/build && ctest -C /home/martin/4Neuro/CTestTestfile.cmake
Test project /home/martin/4Neuro/build
No tests were found!!!
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov --directory . --capture --output-file coverage.info
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcda files ...
geninfo: WARNING: no .gcda files found in . - skipping!
Finished .info-file creation
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov -a coverage.base -a coverage.info --output-file coverage.total
Combining tracefiles.
Reading tracefile coverage.base
lcov: ERROR: no valid records found in tracefile coverage.base
CMakeFiles/coverage.dir/build.make:62: recipe for target 'CMakeFiles/coverage' failed
make[3]: *** [CMakeFiles/coverage] Error 255
make[3]: Leaving directory '/home/martin/4Neuro'
CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/coverage.dir/all' failed
make[2]: *** [CMakeFiles/coverage.dir/all] Error 2
make[2]: Leaving directory '/home/martin/4Neuro'
CMakeFiles/Makefile2:77: recipe for target 'CMakeFiles/coverage.dir/rule' failed
make[1]: *** [CMakeFiles/coverage.dir/rule] Error 2
make[1]: Leaving directory '/home/martin/4Neuro'
Makefile:132: recipe for target 'coverage' failed
make: *** [coverage] Error 2
Run Code Online (Sandbox Code Playgroud)
我已经像这样修改了我的 CMakeLists.txt
include(CTest)
enable_testing()
add_subdirectory(${SRC_DIR} ${PROJECT_BINARY_DIR})
# Adding Unit-tests
add_test(NAME constant_neuron_test COMMAND constant_neuron_test)
add_test(NAME binary_neuron_test COMMAND binary_neuron_test)
add_test(NAME logistic_neuron_test COMMAND logistic_neuron_test)
add_test(NAME connectionFunctionGeneral_test COMMAND connectionFunctionGeneral_test)
add_test(NAME connection_Function_identity_test COMMAND connection_Function_identity_test)
add_test(NAME neural_network_test COMMAND neural_network_test)
add_test(NAME dataset_test COMMAND dataset_test)
add_test(NAME particle_swarm_test COMMAND particle_swarm_test)
add_test(NAME particle_test COMMAND particle_test)
add_test(NAME NeuralNetworkSum_test COMMAND NeuralNetworkSum_test)
add_test(NAME errorfunction_test COMMAND errorfunction_test)
add_test(NAME DESolver_test COMMAND DESolver_test)
include(CodeCoverage.cmake)
APPEND_COVERAGE_COMPILER_FLAGS()
SETUP_TARGET_FOR_COVERAGE_LCOV(
NAME coverage # New target name
EXECUTABLE ctest -j ${n_cores} # Executable in PROJECT_BINARY_DIR
DEPENDENCIES
constant_neuron_test
binary_neuron_test
logistic_neuron_test
connectionFunctionGeneral_test
connection_Function_identity_test
neural_network_test
dataset_test
particle_swarm_test
particle_test
NeuralNetworkSum_test
errorfunction_test
DESolver_test # Dependencies to build first
)
set(COVERAGE_EXCLUDES 'external_dependencies/*')
Run Code Online (Sandbox Code Playgroud)
但是,不幸的是,错误仍然存在
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov -c -i -d . -o coverage.base
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcno files ...
geninfo: WARNING: no .gcno files found in . - skipping!
Finished .info-file creation
cd /home/martin/4Neuro/build && ctest -j 3
Test project /home/martin/4Neuro/build
No tests were found!!!
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov --directory . --capture --output-file coverage.info
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcda files ...
geninfo: WARNING: no .gcda files found in . - skipping!
Finished .info-file creation
cd /home/martin/4Neuro/build && /usr/bin/lcov --gcov-tool /usr/bin/gcov -a coverage.base -a coverage.info --output-file coverage.total
Combining tracefiles.
Reading tracefile coverage.base
lcov: ERROR: no valid records found in tracefile coverage.base
CMakeFiles/coverage.dir/build.make:71: recipe for target 'CMakeFiles/coverage' failed
make[3]: *** [CMakeFiles/coverage] Error 255
make[3]: Leaving directory '/home/martin/4Neuro'
CMakeFiles/Makefile2:81: recipe for target 'CMakeFiles/coverage.dir/all' failed
make[2]: *** [CMakeFiles/coverage.dir/all] Error 2
make[2]: Leaving directory '/home/martin/4Neuro'
CMakeFiles/Makefile2:88: recipe for target 'CMakeFiles/coverage.dir/rule' failed
make[1]: *** [CMakeFiles/coverage.dir/rule] Error 2
make[1]: Leaving directory '/home/martin/4Neuro'
Makefile:132: recipe for target 'coverage' failed
make: *** [coverage] Error 2
Run Code Online (Sandbox Code Playgroud)
好的,我尝试重现您的最小设置集。
\n\n我有:
\n\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 CMakeLists.txt\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 CodeCoverage.cmake\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 test1.cpp\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 test2.cpp\nRun Code Online (Sandbox Code Playgroud)\n\n来自https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmakeCodeCoverage.cmake
CMakeLists.txt 是:
\n\ncmake_minimum_required(VERSION 3.10)\nfind_package(Boost COMPONENTS system filesystem unit_test_framework REQUIRED)\ninclude(CTest)\nenable_testing()\n\nadd_executable(test1_test test1.cpp)\ntarget_link_libraries(test1_test \n ${Boost_FILESYSTEM_LIBRARY}\n ${Boost_SYSTEM_LIBRARY}\n ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})\nadd_executable(test2_test test2.cpp)\ntarget_link_libraries(test2_test\n ${Boost_FILESYSTEM_LIBRARY}\n ${Boost_SYSTEM_LIBRARY}\n ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})\n\nadd_test(NAME test1_test COMMAND test1_test)\nadd_test(NAME test2_test COMMAND test2_test)\n\ninclude(CodeCoverage.cmake)\nAPPEND_COVERAGE_COMPILER_FLAGS()\nSETUP_TARGET_FOR_COVERAGE_LCOV(\n NAME coverage \n EXECUTABLE ctest -j ${n_cores} # Executable in PROJECT_BINARY_DIR\n DEPENDENCIES\n test1_test\n test2_test)\nRun Code Online (Sandbox Code Playgroud)\n\ntest1.cpp(和test2.cpp)是
\n\n#define BOOST_TEST_MODULE test1\n\n#ifndef BOOST_TEST_DYN_LINK\n#define BOOST_TEST_DYN_LINK\n#endif\n\n#define BOOST_TEST_MAIN\n\n#include <boost/test/unit_test.hpp>\n#include <boost/test/output_test_stream.hpp>\n\n#define BOOST_TEST_MODULE test1\n\n\nBOOST_AUTO_TEST_SUITE(test1)\n\n BOOST_AUTO_TEST_CASE(test1__test) {\n BOOST_CHECK_EQUAL(1, 1);\n }\n\nBOOST_AUTO_TEST_SUITE_END()\nRun Code Online (Sandbox Code Playgroud)\n\n现在我这样做:
\n\nmkdir build\ncd build\ncmake ..\nRun Code Online (Sandbox Code Playgroud)\n\n输出是:
\n\n-- The C compiler identification is GNU 7.3.0\n-- The CXX compiler identification is GNU 7.3.0\n-- Check for working C compiler: /usr/bin/cc\n-- Check for working C compiler: /usr/bin/cc -- works\n-- Detecting C compiler ABI info\n-- Detecting C compiler ABI info - done\n-- Detecting C compile features\n-- Detecting C compile features - done\n-- Check for working CXX compiler: /usr/bin/c++\n-- Check for working CXX compiler: /usr/bin/c++ -- works\n-- Detecting CXX compiler ABI info\n-- Detecting CXX compiler ABI info - done\n-- Detecting CXX compile features\n-- Detecting CXX compile features - done\n-- Boost version: 1.65.1\n-- Found the following Boost libraries:\n-- system\n-- filesystem\n-- unit_test_framework\nCMake Warning at CodeCoverage.cmake:116 (message):\n Code coverage results with an optimised (non-Debug) build may be misleading\nCall Stack (most recent call first):\n CMakeLists.txt:20 (include)\n\n\n-- Appending code coverage compiler flags: -g -O0 --coverage -fprofile-arcs -ftest-coverage\n-- Configuring done\n-- Generating done\n-- Build files have been written to: /home/jsantand/t/build\nRun Code Online (Sandbox Code Playgroud)\n\n最后运行make coverage:
Scanning dependencies of target test1_test\n[ 20%] Building CXX object CMakeFiles/test1_test.dir/test1.cpp.o\n[ 40%] Linking CXX executable test1_test\n[ 40%] Built target test1_test\nScanning dependencies of target test2_test\n[ 60%] Building CXX object CMakeFiles/test2_test.dir/test2.cpp.o\n[ 80%] Linking CXX executable test2_test\n[ 80%] Built target test2_test\nScanning dependencies of target coverage\n[100%] Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report.\nDeleting all .da files in . and subdirectories\nDone.\nCapturing coverage data from .\nFound gcov version: 7.3.0\nScanning . for .gcno files ...\nFound 2 graph files in .\nProcessing test1_test.dir/test1.cpp.gcno\nProcessing test2_test.dir/test2.cpp.gcno\nFinished .info-file creation\nTest project /home/jsantand/t/build\n Start 1: test1_test\n1/2 Test #1: test1_test ....................... Passed 0.01 sec\n Start 2: test2_test\n2/2 Test #2: test2_test ....................... Passed 0.01 sec\n\n100% tests passed, 0 tests failed out of 2\n\nTotal Test time (real) = 0.02 sec\nCapturing coverage data from .\nFound gcov version: 7.3.0\nScanning . for .gcda files ...\nFound 2 data files in .\nProcessing test1_test.dir/test1.cpp.gcda\nProcessing test2_test.dir/test2.cpp.gcda\nFinished .info-file creation\nCombining tracefiles.\nReading tracefile coverage.base\nReading tracefile coverage.info\nWriting data to coverage.total\nSummary coverage rate:\n lines......: 65.4% (229 of 350 lines)\n functions..: 68.3% (110 of 161 functions)\n branches...: no data found\nReading tracefile coverage.total\nDeleted 0 files\nWriting data to /home/jsantand/t/build/coverage.info.cleaned\nSummary coverage rate:\n lines......: 65.4% (229 of 350 lines)\n functions..: 68.3% (110 of 161 functions)\n branches...: no data found\nReading data file /home/jsantand/t/build/coverage.info.cleaned\nFound 37 entries.\nFound common filename prefix "/usr/include"\nWriting .css and .png files.\nGenerating output.\nProcessing file /home/jsantand/t/test1.cpp\nProcessing file /home/jsantand/t/test2.cpp\nProcessing file boost/type_index.hpp\nProcessing file boost/function/function_base.hpp\nProcessing file boost/function/function_template.hpp\nProcessing file boost/smart_ptr/shared_ptr.hpp\nProcessing file boost/smart_ptr/detail/sp_counted_base_std_atomic.hpp\nProcessing file boost/smart_ptr/detail/shared_count.hpp\nProcessing file boost/test/unit_test_suite.hpp\nProcessing file boost/test/unit_test.hpp\nProcessing file boost/test/unit_test_log.hpp\nProcessing file boost/test/tools/assertion_result.hpp\nProcessing file boost/test/tools/detail/print_helper.hpp\nProcessing file boost/test/tools/detail/fwd.hpp\nProcessing file boost/test/tools/old/impl.hpp\nProcessing file boost/test/tree/observer.hpp\nProcessing file boost/test/tree/test_unit.hpp\nProcessing file boost/test/tree/fixture.hpp\nProcessing file boost/test/tree/decorator.hpp\nProcessing file boost/test/utils/lazy_ostream.hpp\nProcessing file boost/test/utils/class_properties.hpp\nProcessing file boost/test/utils/trivial_singleton.hpp\nProcessing file boost/test/utils/wrap_stringstream.hpp\nProcessing file boost/test/utils/basic_cstring/bcs_char_traits.hpp\nProcessing file boost/test/utils/basic_cstring/basic_cstring.hpp\nProcessing file boost/type_index/type_index_facade.hpp\nProcessing file boost/type_index/stl_type_index.hpp\nProcessing file boost/type_traits/integral_constant.hpp\nProcessing file c++/7/typeinfo\nProcessing file c++/7/bits/ios_base.h\nProcessing file c++/7/bits/move.h\nProcessing file c++/7/bits/alloc_traits.h\nProcessing file c++/7/bits/stl_construct.h\nProcessing file c++/7/bits/stl_vector.h\nProcessing file c++/7/bits/atomic_base.h\nProcessing file c++/7/bits/allocator.h\nProcessing file c++/7/ext/new_allocator.h\nWriting directory view page.\nOverall coverage rate:\n lines......: 65.4% (229 of 350 lines)\n functions..: 68.3% (110 of 161 functions)\nLcov code coverage info report saved in coverage.info.\nOpen ./coverage/index.html in your browser to view the coverage report.\n[100%] Built target coverage\nRun Code Online (Sandbox Code Playgroud)\n
我也遇到了这个问题,苦苦挣扎了好久才找到解决办法。对我来说,修复方法是将此 CMake 代码移动到定义的任何其他目标之上:
include(CodeCoverage.cmake)
APPEND_COVERAGE_COMPILER_FLAGS()
Run Code Online (Sandbox Code Playgroud)
看起来如果首先定义目标,则不会更新编译器标志。
我已经设法得到一个工作设置:
\n促进:
\nsudo apt-get install libboost-all-dev\nRun Code Online (Sandbox Code Playgroud)\nCMake 3.21.0:(前往https://cmake.org/download/了解最新版本)
\nsudo apt install build-essential libssl-dev\nwget https://github.com/Kitware/CMake/releases/download/v3.21.0/cmake-3.21.0.tar.gz\ntar -zxvf cmake-3.21.0.tar.gz\ncd cmake-3.21.0\n./bootstrap\nmake \nsudo make install \nRun Code Online (Sandbox Code Playgroud)\n文件夹结构:
\n\xe2\x94\x8c mhcl\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac build\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 debug\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 release\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac src\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac biginteger\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 biginteger.cpp\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 biginteger.h\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 CMakeLists.txt\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.cpp\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac test\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 CMakeLists.txt\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 CodeCoverage.cmake\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 test_biginteger_add.cpp\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 test_biginteger_constructor.cpp\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 test_biginteger_divide.cpp\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 test_biginteger_multiply.cpp\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 CMakeLists.txt\nRun Code Online (Sandbox Code Playgroud)\nsrc/biginteger/biginteger.cpp:
\n...\nvoid BigInteger::add(const BigInteger &summand2){\n if(isNegative() == summand2.isNegative()){\n add_digits(summand2);\n }else{\n subtract_digits(summand2);\n }\n if(getNumber(false) == "0") setNegative(false);\n}\n...\nRun Code Online (Sandbox Code Playgroud)\nsrc/biginteger/biginteger.h:
\n#ifndef BIGINTEGER_H_INCLUDED\n#define BIGINTEGER_H_INCLUDED\n\n#include <iostream>\n#include <string>\n#include <algorithm>\n#include <cstring>\n#include <stdexcept>\n\nclass BigInteger{\n\n public:\n BigInteger(const char*);\n...\nRun Code Online (Sandbox Code Playgroud)\nmhcl/CMakeLists.txt:
\ncmake_minimum_required(VERSION 3.20)\nadd_compile_options(-Wall -Wextra -pedantic -Werror)\nproject(MHCL VERSION 0.1 DESCRIPTION "mhcl, a cryptographic library" LANGUAGES CXX)\n\nset(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -fprofile-arcs -ftest-coverage")\nset(CMAKE_CXX_FLAGS_RELEASE "-O2")\n\nadd_subdirectory(test)\nadd_subdirectory(src) \nadd_executable (demo src/main.cpp)\ntarget_link_libraries (demo biginteger)\nRun Code Online (Sandbox Code Playgroud)\nmhcl/src/CMakeLists.txt:
\nadd_library(biginteger biginteger/biginteger.cpp biginteger/biginteger.h)\nRun Code Online (Sandbox Code Playgroud)\nmhcl/src/main.cpp:
\n#include <iostream>\n#include <string>\n#include "biginteger/biginteger.h"\n// this file is not really necessary for testing\nint main(){\n BigInteger b("3");\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\nmhcl/test/CMakeLists.txt:
\nIF(CMAKE_BUILD_TYPE MATCHES Debug)\n find_package (Boost COMPONENTS system filesystem unit_test_framework REQUIRED) # sudo apt-get install libboost-all-dev\n include_directories (${MHCL_SOURCE_DIR}/src ${Boost_INCLUDE_DIRS})\n\n add_executable (test_biginteger_constructor test_biginteger_constructor.cpp)\n target_link_libraries (test_biginteger_constructor biginteger ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})\n\n add_executable (test_biginteger_add test_biginteger_add.cpp)\n target_link_libraries (test_biginteger_add biginteger ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})\n\n add_executable (test_biginteger_multiply test_biginteger_multiply.cpp)\n target_link_libraries (test_biginteger_multiply biginteger ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})\n\n add_executable (test_biginteger_divide test_biginteger_divide.cpp)\n target_link_libraries (test_biginteger_divide biginteger ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})\n\n include(CTest)\n enable_testing()\n\n add_test(NAME test_biginteger_constructor COMMAND test_biginteger_constructor)\n add_test(NAME test_biginteger_add COMMAND test_biginteger_add)\n add_test(NAME test_biginteger_multiply COMMAND test_biginteger_multiply)\n add_test(NAME test_biginteger_divide COMMAND test_biginteger_divide)\n\n include(CodeCoverage.cmake)\n APPEND_COVERAGE_COMPILER_FLAGS()\n setup_target_for_coverage_gcovr_html(NAME coverage EXECUTABLE ctest --schedule-random -j 4 --test-dir test EXCLUDE "/usr/*" "/mnt/v/r3dapple.github.io/encryption/mhcl/test/*" "/mnt/v/r3dapple.github.io/encryption/mhcl/src/main.cpp" DEPENDENCIES test_biginteger_constructor test_biginteger_add test_biginteger_multiply test_biginteger_divide)\nENDIF()\nRun Code Online (Sandbox Code Playgroud)\nmhcl/test/CodeCoverage.cmake:
\nhttps://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake
\nmhcl/test_biginteger_add.cpp:
\n#define BOOST_TEST_MODULE BigIntegerTestAdd\n#include <boost/test/unit_test.hpp>\n#include "../src/biginteger/biginteger.h"\n\nBOOST_AUTO_TEST_SUITE(IDENTITY_ELEMENT)\nBOOST_AUTO_TEST_CASE(ADDITION_ZERO_LENGTH1_184_LENGTH2_1_SIGN1_PLUS_SIGN2_PLUS)\n{\n BigInteger b("7941336097231331222328305438625646002846406186146402399842122390970234239963370898300943198440768677925436553855703282917116959906917075742261367262117888460342170898243453976126509330");\n b.add("0");\n BOOST_CHECK_EQUAL(b.getNumber(), "7941336097231331222328305438625646002846406186146402399842122390970234239963370898300943198440768677925436553855703282917116959906917075742261367262117888460342170898243453976126509330");\n}\nBOOST_AUTO_TEST_SUITE_END()\n...\nRun Code Online (Sandbox Code Playgroud)\n构建调试:
\ncd mhcl/build/debug && cmake -DCMAKE_BUILD_TYPE=Debug ../.. && make && make coverage\nRun Code Online (Sandbox Code Playgroud)\n您的覆盖率报告位于 mhcl/build/debug/coverage/index.html\n
构建版本:
\ncd mhcl/build/release && cmake -DCMAKE_BUILD_TYPE=Release ../.. && make\nRun Code Online (Sandbox Code Playgroud)\n