Questions tagged [catch2]

Catch is a unit testing framework for C++

Catch2 offers a BDD syntax, fixtures, Matchers and dynamic data-generation, and a simplified syntax using overloaded assertions. Catch2 is designed for simplicity – it is released as a single include file and allows the use of natural C++ expressions inside assertions.

Catch2 is hosted on GitHub, available at catch-lib.net, and is openly discussed in a Google group.

153 questions
0
votes
0 answers

Test a custom c++ macro with catch2

I have a custom macro #define MYMACRO(a, b) ({if (a>b) {return a;}}b;) I want to be able to test this macro with CATCH2. Something like: TEST_CASE("Check inequality") { int result = MYMACRO(1, 2); REQUIRE(result==2); } This does not work. I get…
devOrange
  • 11
  • 2
0
votes
0 answers

Dependency for native build in Meson

I have a Meson project that includes a test suite to be run on the build machine even during cross compilation. The test executables are tagged native: true, but they pull in catch2 as a dependency through the wrapdb, and that isn't native, leading…
Simon Richter
  • 28,572
  • 1
  • 42
  • 64
0
votes
2 answers

Is there a better way to test for Liskov substitution principle using catch2?

I want to check that other classes meet the same specifications as my base class but, I don't want to repeat the same code. A solution that I am thinking of is passing a class as an argument to a test case and I'd be able to invoke the same methods…
Brandon
  • 1
  • 3
0
votes
1 answer

How to specify which test to run (by label) using ctest with Catch2 framework?

Catch2 can add label to each test case,e.g testf.cpp: TEST_CASE("test function","[part-1]") Then using the command line, we can specify only to run part-1 ./testf [part-1] So my question is how to achieve the same effect when using ctest. I know…
qiu
  • 13
  • 4
0
votes
0 answers

How to avoid ctest running catch2's benchmark by default (make benchmarks ber untime opt-in rather than opt-out)?

I use catch2 extensively as part of my testing ecosystem, which gets fired by CLion running "ctest" during development and just running "ctest" by hand in CI. My issue is, I can't seem to find a decent way to have those benchmarks be an opt-in type…
hak8or
  • 488
  • 2
  • 9
  • 28
0
votes
0 answers

Creating a Cartesian product of sections in Catch2

I have some code: #include #include TEST_CASE("Section showcase") { { SECTION("A1") { std::cout << "A1 "; } SECTION("A2") { std::cout << "A2 "; …
Stein
  • 3,179
  • 5
  • 27
  • 51
0
votes
2 answers

React - catch error - problem with console.log

I have small problem, but I don't know what I doing wrong. I have function like below. In .catch alert working ok and I see error in browser, but I have problem with this same error in console.log <- I don't see anything Basically, I wanted to…
kamels90
  • 1
  • 2
0
votes
1 answer

How to make Catch2 version 3 tests use logcat on android devices?

I have a cmake + Qt based project, it compiles fine and runs on my android device. i see stuff printed to logcat (inside Qt Creator), when using qDebug. But there is no output from Catch2. I suspect, that it keeps printing to stdout or stderr, which…
Adam
  • 488
  • 4
  • 17
0
votes
1 answer

Problem linking to Catch2 library installed with Conan 2.0 in CMake

I recreated my issue on smaller project. Let's assume there are these files (also build directory): ├── add.hpp ├── add-test.cpp ├── CMakeLists.txt └── conanfile.txt add.hpp: inline int add(int a, int b) { return a + b; } add-test.cpp: #include…
Fungor
  • 15
  • 3
0
votes
0 answers

Cmake Catch2 Link Multiple Libraries containing tests into a Single One

I have multiple child libraries with their own tests cases. I am trying to find a way to combine them together to form a single executable/library that runs all the tests instead of independent ones. However it seems all tests and the runner need to…
0
votes
0 answers

Catch2 v3 - undefined reference to

I have this project for university which we have to make a small game in C++. I'm trying to use Test Driven Development for the most fundamental parts of the game so I was trying to set up Catch2, I already set up CMake and it works just fine, then…
Rulz
  • 1
0
votes
0 answers

Migrating Catch2 from v2 to v3 causes error

I'm trying to migrate my C++ project to use Catch2 v3, but I ran into an error: /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x1b): undefined reference to `main' Now, if I understand…
johnscapw
  • 1
  • 2
0
votes
0 answers

VSCode Outline View for C++ Catch Testing TEST_CASEs

I am using VSCode for C++ Catch2 code and find the Outline View to be lacking stubs for each TEST_CASE or SECTION. Is there a way to edit the VSCode's Outline View to be able to parse these macros?
Vasseurth
  • 6,354
  • 12
  • 53
  • 81
0
votes
1 answer

[UT][Catch2] Several test cases or one with several sections

Let's say we want to test one file (or class). What should be better approach (always? maybe in special cases?)? Framework Catch2: https://github.com/catchorg/Catch2 Several test cases TEST_CASE("First", "[some_details]") { Class obj; …
0
votes
0 answers

Catch2 special characters in TEST_CASE name

I'm using CMake's 3.18 CTest with the Catch2 3.1.1 framework for testing purposes, and am currently having problems finding what the valid characters are in Catch2's macro TEST_CASE's name parameter. For instance, I created a test…
user3007875
  • 123
  • 7