1

I am new to the C++ language and I am trying to understand the Catch2 unit test framework. I followed the example given on the github page.

I use visual studio code with the compiler g++ 12.2.0. I made a simple project with two files;

catch.hpp

test.cpp

the catch.hpp file contains the source downloaded from the github repo.

/*
 *  Catch v2.13.9
 *  Generated: 2022-04-12 22:37:23.260201
 *  ----------------------------------------------------------
 *  This file has been merged from multiple headers. Please don't edit it directly
 *  Copyright (c) 2022 Two Blue Cubes Ltd. All rights reserved.
 *
 *  Distributed under the Boost Software License, Version 1.0. (See accompanying
 *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 */

On the other hand, I made a simple test file, test.cpp, which contains;

#define CATCH_CONFIG_MAIN  // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"

TEST_CASE("some test", "[simple_test_case]"){
    REQUIRE(1 == 1);
}

When I run the compile task from visual studio code to compile the test.cpp file, the build is finished correctly. If I then try to run the build executable, nothing happens. If I try to debug the test.cpp file, also nothing happens and no breakpoint is hit. Furthermore, an error message is given,

ERROR: Unable to start debugging. Unexpected GDB output from command "-exec- run". During startup program exited with code 0xc0000139.

Does anyone know what I am doing wrong? I think I missed something, but I cannot grasp what it is.

rrnl
  • 11
  • 2
  • How are you building this code? Is this a [mre]? – Alan Birtles Oct 02 '22 at 19:00
  • I did not link to the Catch2Main library. But this was also not mentioned in the tutorial provided. Is this necessary? And how does that work? This is the minimal reproducible example, I only used these files in the project and used the g++ compiler to compile the test.cpp file via the run build task in visual studio code. I also tried to just use the command line ```g++ test.cpp```, however, this yields the same result. – rrnl Oct 02 '22 at 19:06
  • I used your test.cpp, and downloaded catch.hpp from that repo. Compiled and ran and the one test passed, for me. I don't use Visual Studio Code (nothing against it, I just use Vim). – Eljay Oct 02 '22 at 19:12
  • And you compiled on the command line directly? Only the test.cpp file? Did you run on Windows or Linux? I used mainly Windows, but also tried on a virtual machine with Ubuntu also yielded the same result for me. – rrnl Oct 02 '22 at 20:01
  • Ah, I have it working on Ubuntu now, however, Windows still not executing it properly. – rrnl Oct 02 '22 at 20:17
  • I tried it with the windows compiler from visual studio 2022 and it works. Maybe there is some problem between Windows 11 OS and the g++ compiler with the Catch2 header-only library. It works now, thank you for helping! – rrnl Oct 21 '22 at 09:34
  • It is probably something to do with the version of Catch2, version 3 requires linking against Catch2::Catch2WithMain – Mehdi Aug 22 '23 at 12:09

0 Answers0