diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d78f85..9e97d5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,4 +25,13 @@ add_subdirectory(extern/catch2) # Include all internal subprojects (library, examples, testing). add_subdirectory(lib/pls) -add_subdirectory(app/playground) \ No newline at end of file +# Include examples +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() diff --git a/lib/pls/include/pls/library.h b/lib/pls/include/pls/library.h index 6c821dc..6efc19f 100644 --- a/lib/pls/include/pls/library.h +++ b/lib/pls/include/pls/library.h @@ -3,6 +3,7 @@ namespace pls { void hello(); + int test_adder(int a, int b); } #endif \ No newline at end of file diff --git a/lib/pls/src/library.cpp b/lib/pls/src/library.cpp index 2339915..6634af0 100644 --- a/lib/pls/src/library.cpp +++ b/lib/pls/src/library.cpp @@ -6,4 +6,8 @@ namespace pls { void hello() { std::cout << "Hello from PLS!" << std::endl; } + + int test_adder(int a, int b) { + return a + b; + } } \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..929af12 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(tests + main.cpp + example_tests.cpp) +target_link_libraries(tests catch2 pls) \ No newline at end of file diff --git a/test/example_tests.cpp b/test/example_tests.cpp new file mode 100644 index 0000000..7774ebf --- /dev/null +++ b/test/example_tests.cpp @@ -0,0 +1,22 @@ +#include +#include + +// 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 diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..6fb1ee3 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,3 @@ +#define CATCH_CONFIG_MAIN +#include +