cmake使⽤ctest测试
cmake  使⽤ ctest  测试1). test.cpp
/// @file test.cpp
/// @brief
/// @author EastonWoo <31417071@qq>
/// 0.01
/// @date 2015-09-12
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
int a = atoi(argv[1]);
int b = atoi(argv[2]);
printf("is %d\n", a+b);
printf("exit 0!\n");
return 0;
}
2).
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
# CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT(TEST_APP)
AUX_SOURCE_DIRECTORY(. DIR_SRCS)
ADD_EXECUTABLE(my_test.elf ${DIR_SRCS})
# 启⽤测试
enable_testing()
# 测试程序是否成功运⾏
# add_test (test_run1 my_test.elf)
add_test (test_run2 my_test.elf 1 2)
# 测试 1 + 3 , 是否输出打印'is 4'
add_test (test_1_plus_3 my_test.elf 1 3)
set_tests_properties (test_1_plus_3
PROPERTIES PASS_REGULAR_EXPRESSION "is 4")  #
3). 运⾏
cmake . && make && make test
4). 打印gnu编译器
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/cmake
[100%] Built target my_test.elf
Test project /tmp/cmake
Start 1: test_run2
1/2 Test #1: test_run2 ........................  Passed    0.00 sec
Start 2: test_1_plus_3
2/2 Test #2: test_1_plus_3 ....................  Passed    0.00 sec
100% tests passed, 0 tests failed out of 2
Total Test time (real) =  0.00 sec
也可以查看 man 1 ctest 帮助, 个⼈感觉还是gtest的单元测试⽜B

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。