diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index c7e3ac5..7e0f0d8 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -28,5 +28,8 @@ jobs: - name: CMake Build run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + - name: Unit Tests + run: cd ./bin && ./popl_test --order rand [unit] + - name: Functional Tests run: cd ./bin && ./popl_test --order rand [functional] diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d476dcb..9525c21 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,10 @@ # Copyright (C) 2022 Andrea Ballestrazzi # ================ Test Executable ================ -set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_main.cpp) +set( + TEST_SOURCES + "${CMAKE_CURRENT_SOURCE_DIR}/test_main.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/value_test.cpp") add_executable(popl_test ${TEST_SOURCES}) set(POPL_TEST_BIN_DIR "${PROJECT_SOURCE_DIR}/bin") diff --git a/test/value_test.cpp b/test/value_test.cpp new file mode 100644 index 0000000..ea5d518 --- /dev/null +++ b/test/value_test.cpp @@ -0,0 +1,58 @@ +// Copyright (C) 2022 Andrea Ballestrazzi + +#include +#include + +// C++ STL +#include +#include + +namespace test{ + + template + static void assertValueCorrectlyConstructed( + const popl::Value& actual, + const std::string& expectedShortName, + const std::string& expectedLongName, + const std::string& expectedDescription) { + CHECK(actual.short_name() == expectedShortName[0]); + CHECK(actual.long_name() == expectedLongName); + CHECK(actual.description() == expectedDescription); + } + +} // namespace test + +TEMPLATE_TEST_CASE("Value class unit test", "[unit][value]", + std::string, std::int32_t) { + SECTION("Constructors tests") { + SECTION("When valid values are passed to constructors") { + static constexpr std::string_view SHORT_NAME{"t"}; + static constexpr std::string_view LONG_NAME{"test"}; + static constexpr std::string_view VALUE_DESCRIPTION{"Test value description"}; + + SECTION("Constructor #1 should correctly set the value's state") { + std::unique_ptr> valueUnderTest{}; + + // Precondition + REQUIRE_NOTHROW(valueUnderTest + = std::make_unique>(std::string{SHORT_NAME}, std::string{LONG_NAME}, std::string{VALUE_DESCRIPTION})); + + test::assertValueCorrectlyConstructed(*valueUnderTest, std::string{SHORT_NAME}, std::string{LONG_NAME}, std::string{VALUE_DESCRIPTION}); + } + } + + SECTION("When invalid values are passed to constructors") { + static constexpr std::string_view INVALID_SHORT_NAME{"test_short_name"}; + static constexpr std::string_view VALID_LONG_NAME{"test"}; + static constexpr std::string_view VALID_DESCRIPTION{"Test value description"}; + + SECTION("When passing an invalid short name") { + SECTION("Constructor #1 should throw an std::invalid_argument exception") { + REQUIRE_THROWS_AS( + popl::Value(std::string{INVALID_SHORT_NAME}, std::string{VALID_LONG_NAME}, std::string{VALID_DESCRIPTION}), + std::invalid_argument); + } + } + } + } +}