cmake 使用 ctest 测试

cmake  使用 ctest  测试

1). test.cpp

/// @file test.cpp
/// @brief
/// @author EastonWoo <31417071@qq.com>
/// 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). CMakeLists.txt


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). 打印

-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/cmake
[100%] Built target my_test.elf
Running tests...
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值