Commit ee843f57 by FritzFlorian

Add cach2 testing support.

parent 6d03890c
...@@ -25,4 +25,13 @@ add_subdirectory(extern/catch2) ...@@ -25,4 +25,13 @@ add_subdirectory(extern/catch2)
# Include all internal subprojects (library, examples, testing). # Include all internal subprojects (library, examples, testing).
add_subdirectory(lib/pls) add_subdirectory(lib/pls)
add_subdirectory(app/playground) # Include examples
\ No newline at end of file add_subdirectory(app/playground)
# Add optional tests
option(PACKAGE_TESTS "Build the tests" ON)
if(PACKAGE_TESTS)
enable_testing()
add_subdirectory(test)
add_test(NAME AllTests COMMAND tests)
endif()
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace pls { namespace pls {
void hello(); void hello();
int test_adder(int a, int b);
} }
#endif #endif
\ No newline at end of file
...@@ -6,4 +6,8 @@ namespace pls { ...@@ -6,4 +6,8 @@ namespace pls {
void hello() { void hello() {
std::cout << "Hello from PLS!" << std::endl; std::cout << "Hello from PLS!" << std::endl;
} }
int test_adder(int a, int b) {
return a + b;
}
} }
\ No newline at end of file
add_executable(tests
main.cpp
example_tests.cpp)
target_link_libraries(tests catch2 pls)
\ No newline at end of file
#include <catch.hpp>
#include <pls/library.h>
// BDD style
SCENARIO( "the test_adder works", "[library]" ) {
GIVEN ("two numbers") {
WHEN ( "they are positive") {
THEN ( "the result is positive") {
REQUIRE(pls::test_adder(1, 2) >= 0);
}
THEN ( "the result is the sum of both") {
REQUIRE(pls::test_adder(1, 4) == 5);
}
}
}
}
// Normal Style
TEST_CASE( "the test_adder can sumup", "[libray]") {
}
\ No newline at end of file
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment