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
4
votes
1 answer

Catch2 undefined reference to Catch::StringMaker

I am using Catch2 from the actual devel branch and I have a linker error when trying to compare two vector The issue can be reproduced as following: #include #include #include…
Elvis Dukaj
  • 7,142
  • 12
  • 43
  • 85
4
votes
3 answers

Unresolved External Symbol errors while using Catch2

I am trying to do Catch2 Unit Testing in Visual Studio. I have created a small test project to practice. When I try to compile this test project, I get a linker error. I am now trying to diagnose this linker error, but the Catch2.hpp header file…
mana
  • 545
  • 4
  • 12
4
votes
4 answers

Is it possible to use Catch2 for testing an MPI code?

I'm working with a fairly big MPI code. I started to include unit tests into the existing code base. However, as soon as the unit under test uses an MPI routine the test executable crashes with the error message "calling an MPI routine before…
SamVanDonut
  • 361
  • 2
  • 14
4
votes
0 answers

How to pass command-line arguments in CTest at runtime?

I would like to pass parameters to our Catch2 tests via ctest when running through bamboo or jenkins so that they product junit test results. So I would like to do something like: make test ARGS="-r junit -o test_results.xml" That would forward…
Jer
  • 88
  • 7
4
votes
2 answers

What is the canonical way to check for approximate zeros in Catch2?

What is the canonical way to compare to approximate zeros in Catch2? I found this way given a tolerance of 1e-12, but it is not clear it is the best way: TEST("a approx. equal to b", "[test]"){ REQUIRE( a - b == (0_a).margin(1e-12) ); } I am…
alfC
  • 14,261
  • 4
  • 67
  • 118
4
votes
1 answer

Printing floating-point values with full precision with Catch2

I have some test code using catch2, that does check wether some computation returns a floating-point null value. CHECK( someFunc() == 0. ); The problem is that when the test fails because of very small non-null value (say 1.234E-16), the values are…
kebs
  • 6,387
  • 4
  • 41
  • 70
4
votes
1 answer

Catch2 runs test once more if all sections fail

I have the following piece of code that I run with the latest (2.4.0) version of Catch2: #include "catch.hpp" #include TEST_CASE("Test") { int x = 0; SECTION("A") { std::cout << "A"; ++x; …
Nikola Benes
  • 2,372
  • 1
  • 20
  • 33
3
votes
1 answer

is there a construct in catch2 to express a mapping of inputs vs. expected values?

I have a set of inputs and their corresponding expected outputs for a function. The test is currently written as follows: TEST_CASE("test reverse_and_double") { struct { string input, string expected_output } tests[] = { { "abcd", "dcba"…
Grim Fandango
  • 2,296
  • 1
  • 19
  • 27
3
votes
2 answers

Comparison with std::nullopt in Catch2 gives unreadable results

I have the following check in my cpp test, which is written with Catch2: REQUIRE(foo() == std::nullopt); The test fails with a meaningless message when the function returns std::optional: REQUIRE( foo() == std::nullopt ) with expansion: …
Nane
  • 133
  • 1
  • 1
  • 9
3
votes
1 answer

Combining AND and OR in Catch2 test tags

I have a set of Catch2 test cases, segregated by language and by type. For example: TEST_CASE("zh-CN CPU test", "[zh-CN][cpu]") { REQUIRE(result); } TEST_CASE("zh-CN verification test", "[zh-CN][ModelVerification]") { …
Eric Brown
  • 13,774
  • 7
  • 30
  • 71
3
votes
0 answers

How to properly setup Catch2 tests in a Makefile?

I'm trying to setup tests with Catch2 and setup a testing rule in a Makefile, it's a pre-requisite, I can't use CMake. I'm not sure how to go about that. For example, I have something along those lines: src | |--------- model | …
Nathan Furnal
  • 2,236
  • 3
  • 12
  • 25
3
votes
1 answer

Why do some Conan packages delete CMake Package information

I'm relatively new to Conan. I'm trying to use packages provided by conan in a very natural cmake way...i.e. I don't want anything conan specific in the consuming library's CMakeLists.txt. I just want to find_package my dependency,…
schrödinbug
  • 692
  • 9
  • 19
3
votes
1 answer

Can Catch2 be used with C language?

I am writing a dll which supports interfacing with both C and C++ language applications. The dll itself is written in C++, so the question is can i use Catch2 framework for unittesting both C and C++ applications ? What are the things i need to look…
3
votes
0 answers

Catch2 alternative Section behaviour

I am using Catch2 and I am trying to build a test case which does a complicate setup before the sections, represented in the listing by the initialization of a MyObject instance. I like the idea of sections, since they keep the tests separated, but…
NotMe
  • 65
  • 5
3
votes
1 answer

How do fix a "RETURN missing for non-void function" error in tromeloeil?

I'm trying to figure out how to use the Trompeloeil library with C++11. With this example, I've run into a huge amount of build errors, and I can't understand why. #define CATCH_CONFIG_MAIN #include "catch.hpp" #include #include…
MightyDodongo
  • 101
  • 1
  • 4
1
2
3
10 11