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

How do I achieve the effect of `DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING` with Catch2?

The doctest C++ test framework has a DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING configuration option. This option allows me to write char * tls_password; // ... CHECK(tsl_password == "swordfish"); That is, use == to compare C strings without…
user7610
  • 25,267
  • 15
  • 124
  • 150
0
votes
1 answer

Catch2: Test all permutations of two lists of types

I need to write some unit tests in Catch2 where each test case should be executed for each possible permutation of two lists of types. I'd love something like // Some types defined in my project class A; class B; PERMUTATION_TEST_CASE ("Foo", (A,…
PluginPenguin
  • 1,576
  • 11
  • 25
0
votes
1 answer

Catch2 CLion error, "No tests were found"

I have a folder structure like and I am trying to get Catch2 setup, my CMake files look like: the topmost CMake: cmake_minimum_required(VERSION 3.21) project(throwaway) set(CMAKE_CXX_STANDARD…
k huang
  • 409
  • 3
  • 10
0
votes
0 answers

Try Catch on a custom HttpException fires when returning null

When I run my app with the code below, even if the responseData['error'] returns null, I still get an error that is thrown to my HttpException for error handling and it returns the catch portion of the try catch block of my error handling. Thus…
0
votes
0 answers

Trying to setup Catch2 with Cmake and c++-20, but getting SIGSEGV when testing strings

I've playing around with cpp20, lately I've been trying to create some tests for my project, but every time I try to test anything related to strings I'd get a SIGSEGV signal. This is an example of my tests #include #include…
Siel347
  • 1
  • 2
0
votes
0 answers

How to use catch2 for testing a big project in Visual Studio

I have a big project in Visual Studio 2019. And I want to test it by Catch2 library. I'd like to know how to include this library correctly in my project? For example, in main.cpp I do: #include #include #define…
SuperPuper
  • 51
  • 1
  • 1
  • 5
0
votes
1 answer

Catch2 Framework Error: unknown type name 'DNA'clang-tidy(clang-diagnostic-error)

I'm using catch2 framework for unit testing. Below is the command I use for compiling the test file. bin/tests: ./tests/tests.cc ./src/dna_strand.cc ./includes/dna_strand.hpp $(CXX) $(CXXFLAGS) ./tests/tests.cc ./src/dna_strand.cc -o $@ I'm trying…
meseee
  • 1
  • 1
0
votes
0 answers

extern "C" function returning struct behaves unexpectedly

I'm writing a C project and I want to test it using catch2 framework. But I'm having some odd behaviors with a function that returns a struct. The C code is bellow: stream_type.h #ifndef STREAM_TYPE #define STREAM_TYPE #include #ifdef…
0
votes
0 answers

Debugging fails on Catch2 tests

I have been trying to debug my catch2 tests lately but everytime it fails. When I run the program, it compiles and everything seems fine. I get this error saying the exe file does not exist and offers me to configure the launch.json file. When I…
0
votes
1 answer

Disable thread leak test in ThreadSanitizer?

I'm using ThreadSanitizer with Catch2. Unfortunately, ThreadSanitizer is finding thread leaks with Catch2 and Thread race conditions in my code. Is there any way to disable ThreadSanitizer's thread leak detection but leaving on its race condition…
vy32
  • 28,461
  • 37
  • 122
  • 246
0
votes
0 answers

directory layout & CMakeList.txt for application with unittest

I am learning C++ and am working on a QT5 application which is going pretty well. I am at the point where I need to implement some unittests (catch2) on a few specific parts of the application. I am lost... I know how to write the tests and there is…
Flip Vernooij
  • 889
  • 6
  • 15
0
votes
0 answers

Got error MSB3073 while installing Catch2

When I install catch2 I have this error: Command I used: git clone https://github.com/catchorg/Catch2.git cd Catch2 cmake -Bbuild -H. -DBUILD_TESTING=OFF cmake --build build/ --target install Then when I use cmake --build build/ --target install, I…
0
votes
1 answer

Make long header files compile once?

Alright so I'm using the "Catch2" framework for C++ Unit Testing and in my "testMain.cpp" (Doesn't matter) I include the single header version of it #include "Catch.hpp". The problem is every time I write just a small test, I have to compile the…
Oogway101
  • 83
  • 1
  • 5
0
votes
1 answer

C++ TEST_CASE not found in scope

I am trying to work on a C++ tutorial for my college. I tried everything possible, such as importing Catch library in a catch.hpp file, but I always get the error of TEST_CASE not found in scope. Can anyone help me here? I really need to get this to…
James Fang
  • 61
  • 3
0
votes
1 answer

How to get catch2 to print the compared C-style string's contents?

I'm using catch2 (latest release - 2.13.6 as of this moment), and in my testcases I have a bunch of checks similar to the following: CHECK(!strcmp(my_str, "some literal string here")); where the literal is different for each testcase and obviously…
einpoklum
  • 118,144
  • 57
  • 340
  • 684