catchorg / catchorg/Catch2

Problem with pluggin Catch in

Open
#1,900 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

Hi, I have a problem with plugging Catch in to my project, using git-submodule style. Could you help me with that? Might be that I'm missing something...
Here's how my project looks like:
```
my_project/
build/
src/
hello.h # function to be tested
hello.cc # TEST_CASE
main.test.cc # CATCH_CONFIG_MAIN
CMakeLists.txt
extern/
Catch2/ # git submodule
CMakeLists.txt
```
And particular files:
```cmake
# CMakeLists.txt
add_subdirectory(extern/Catch2)
include(extern/Catch2/contrib/Catch.cmake)
add_subdirectory(src)

# src/CMakeLists.txt
add_library(my_lib SHARED hello.cc)
add_executable(tests main.test.cc)
target_include_directories(my_lib PRIVATE .. ../extern/Catch2/single_include)
target_include_directories(tests PRIVATE ../extern/Catch2/single_include)
target_link_libraries(tests PRIVATE my_lib)
catch_discover_tests(tests)
```

Now, when I try to build it, Catch tells me, he can't find any tests in the executable:
```
$ cmake .. && make
[...]
CMake Warning at /extern/Catch2/contrib/CatchAddTests.cmake:38 (message):
Test executable
'/build/src/tests'
contains no tests!
```

For the sake of consistency, here's how my project files look like:
```c++
// hello.h
#ifndef HELLO_H_
#define HELLO_H_
namespace my_lib {
template
T Factorial( T number ) {
return number <= 1 ? number : Factorial(number-1)*number;
}
}
#endif

// hello.cc
#include
#include
namespace test {
TEMPLATE_TEST_CASE("Factorial", "[fact]", int, float, uint64_t) {
REQUIRE( my_lib::Factorial(0) == 1 );
REQUIRE( my_lib::Factorial(1) == 1 );
REQUIRE( my_lib::Factorial(2) == 2 );
REQUIRE( my_lib::Factorial(3) == 6 );
REQUIRE( my_lib::Factorial(10) == 3628800 );
}
} // namespace test

// main.test.cc
#define CATCH_CONFIG_MAIN
#include
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.