catch2

How can I use Catch2 to test my CMake static library project?

拜拜、爱过 提交于 2021-01-28 05:09:21
问题 I'm writing a static library which contains some shared code between several projects. In order to verify that the code in this library functions properly I'd like to use Catch2 to do some unit testing on it. Unfortunately, when attempting to run the tests I run into the problem that the compilation's output file is a shared library (.a), rather than an executable. I'm sure I can create a separate project which uses the functions from my static library, and subsequently run tests that way,

Controlling output of Boost.Test source location format

情到浓时终转凉″ 提交于 2020-12-07 07:32:52
问题 Catch2 and Boost.Test provide similar features for writing unit tests. For a certain project I have to use Boost.Test instead of Catch2. The problem I have is that both use different format outputs. For example, Catch2 will say that the was a fail in test.cpp:9 (see example below). However Boost.Test will say test.cpp(9): error in ... . This format doesn't allow my editor to recognize the output as a source location. Is there way to make Boost.Test output the source location as file.ext

Controlling output of Boost.Test source location format

梦想的初衷 提交于 2020-12-07 07:32:33
问题 Catch2 and Boost.Test provide similar features for writing unit tests. For a certain project I have to use Boost.Test instead of Catch2. The problem I have is that both use different format outputs. For example, Catch2 will say that the was a fail in test.cpp:9 (see example below). However Boost.Test will say test.cpp(9): error in ... . This format doesn't allow my editor to recognize the output as a source location. Is there way to make Boost.Test output the source location as file.ext

Best practices for Unit testing with Catch2 in Visual Studio

丶灬走出姿态 提交于 2020-12-01 12:18:35
问题 I'm new to unit testing in C++ and want to get some advice on this. I use Visual Studio 2019 for development and I chose Catch2 as my testing library, I also got the Test Adapter for Catch2 installed. I read docs for both Catch2 and Test Adapter for Catch2 on GitHub, but I still cannot figure out a proper way to use unit test in Visual Studio. Let's assume that I already have a project with some classes in it and I want to test those classes. Should I put files with test code in the same

How to get a relative path for CMake unit tests?

末鹿安然 提交于 2020-07-23 06:05:30
问题 I have a project built with CMake that uses Catch2 for unit tests. Some of the unit tests exercise code that loads data from a file like this: std::string resource_dir = "TEST_CWD/resources/"; std::ifstream infile{resource_dir + "datafile.txt"} The question is how to properly get the value of TEST_CWD . The directory structure is simple (and not set in stone): my_project/ test/ resources/datafile.txt loader_test.cpp Leaving TEST_CWD blank sometimes works, but breaks when running tests through

How to get a relative path for CMake unit tests?

自古美人都是妖i 提交于 2020-07-23 06:04:06
问题 I have a project built with CMake that uses Catch2 for unit tests. Some of the unit tests exercise code that loads data from a file like this: std::string resource_dir = "TEST_CWD/resources/"; std::ifstream infile{resource_dir + "datafile.txt"} The question is how to properly get the value of TEST_CWD . The directory structure is simple (and not set in stone): my_project/ test/ resources/datafile.txt loader_test.cpp Leaving TEST_CWD blank sometimes works, but breaks when running tests through

How to get a relative path for CMake unit tests?

心已入冬 提交于 2020-07-23 06:02:10
问题 I have a project built with CMake that uses Catch2 for unit tests. Some of the unit tests exercise code that loads data from a file like this: std::string resource_dir = "TEST_CWD/resources/"; std::ifstream infile{resource_dir + "datafile.txt"} The question is how to properly get the value of TEST_CWD . The directory structure is simple (and not set in stone): my_project/ test/ resources/datafile.txt loader_test.cpp Leaving TEST_CWD blank sometimes works, but breaks when running tests through

【解锁】Catch2——C++测试框架(Quick Start)

人盡茶涼 提交于 2020-02-26 10:54:39
Catch2 Catch2是及其简单的C++测试框架,与gtest,boost.test和CppUnit相比Catch2非常小,甚至你只需要一个头文件就可以轻松的使用了。在小型项目里面可以很方便的用它搭建测试框架,同时配合简单的打桩框架 stub ,分分钟让你的测试用例跑起来。 今天,我们就来【解锁】Catch2。 获取 有两种方法获取Catch2: 一种是直接下载头文件 catch.hpp ——推荐使用这种方式,可以简单的融入你的项目。 另一种是,获取catch2源码, https://github.com/catchorg/Catch2.git 适合二次开发或者学习里面的demo。 编译 因为我们今天要通过分析几个Catch2的examples来解锁Catch2的用法,所以用源码进行编译。 1.获取源码 git clone https://github.com/catchorg/Catch2.git 2.开启examples编译 cmake -DCATCH_BUILD_EXAMPLES=ON ../ (base) frank@deepin:~/git/Catch2$ mkdir build (base) frank@deepin:~/git/Catch2$ cd build/ (base) frank@deepin:~/git/Catch2/build$ cmake

Can't use overloaded comparison operator with Catch test

拜拜、爱过 提交于 2020-02-05 04:25:00
问题 I have a simple unit-test using Catch 2.11.1: #define CATCH_CONFIG_MAIN #include "catch.hpp" #include <utility> #include <any> namespace A::B { namespace C { struct S { }; } using type = std::pair<C::S, std::any>; } inline bool operator==(A::B::type const&, A::B::type const&) { return true; } TEST_CASE("test", "[test]") { auto t1 = std::make_pair(A::B::C::S(), std::any()); auto t2 = std::make_pair(A::B::C::S(), std::any()); REQUIRE(t1 == t2); } The above simple programs generates the