I've already used Catch2 for testing sucessfully, but this time a problem occurred. I am pushing Catch2 submodule to me project (this is not a -v2.x branch) and include "../Catch2/src/catch2/catch_all.hpp" to my test files. The problem is that in catch_all.hpp all of the included .hpp files (like <catch2/benchmark/catch_benchmark_all.hpp>, <catch2/catch_approx.hpp> and so on) are not found. I've checked paths but they seem to be fine. Any ideas what is wrong with it?
Here's an example of my code.
I am adding a Catch2 submodule with command
git submodule add https://github.com/catchorg/Catch2.git
CMakeFile.txt:
cmake_minimum_required(VERSION 3.20)
project(proj)
set(CMAKE_CXX_STANDARD 17)
set (sources
./main.cpp
./test_main.cpp
./test.cpp)
add_executable(mainApp ${sources})
target_compile_options(mainApp PRIVATE -Wall -pedantic -std=c++17)
target_link_libraries(mainApp)
set (tests
./test_main.cpp
./test.cpp)
add_subdirectory(Catch2)
add_executable(runTests ${tests})
target_compile_options(mainApp PRIVATE -g)
target_link_libraries(runTests PRIVATE Catch2::Catch2WithMain)
test_main.cpp:
#define CATCH_CONFIG_MAIN
#include"Catch2/src/catch2/catch_all.hpp"
test.cpp:
#include"Catch2/src/catch2/catch_all.hpp"
TEST_CASE("BasicTest_1", "FirstTest") {
REQUIRE(1 == 1);
}
main.cpp is just a simple helloworld for now.
TEST_CASE doesn't work either, it says "C++ requires a type specifier for all declarations".
You are including test_main.cpp
and test.cpp
in mainApp
.
Which means that files in mainApp
try to #include"Catch2/src/catch2/catch_all.hpp"
without linking to the Catch2 library and includes.
Remove the test files from the mainApp
sources and try again.