From 9f6535bcd8e69aa2fcdb61b2ffa61aa1598080bb Mon Sep 17 00:00:00 2001 From: Andrea Ballestrazzi Date: Fri, 9 Sep 2022 20:21:15 +0200 Subject: [PATCH 1/3] Added value_test.cpp file. --- test/CMakeLists.txt | 5 ++++- test/value_test.cpp | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/value_test.cpp 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..4f6e406 --- /dev/null +++ b/test/value_test.cpp @@ -0,0 +1,4 @@ +// Copyright (C) 2022 Andrea Ballestrazzi + +#include +#include From 00721776e01cdaf51ff565aa4c93200fffaeeaf2 Mon Sep 17 00:00:00 2001 From: Andrea Ballestrazzi Date: Fri, 9 Sep 2022 20:51:20 +0200 Subject: [PATCH 2/3] Added initial Value unit tests. --- test/value_test.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/test/value_test.cpp b/test/value_test.cpp index 4f6e406..ea5d518 100644 --- a/test/value_test.cpp +++ b/test/value_test.cpp @@ -1,4 +1,58 @@ // Copyright (C) 2022 Andrea Ballestrazzi -#include +#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); + } + } + } + } +} From 2b8f9007d5b28844f5e14ae323b7d8820245710f Mon Sep 17 00:00:00 2001 From: Andrea Ballestrazzi Date: Fri, 9 Sep 2022 20:54:19 +0200 Subject: [PATCH 3/3] Added unit test step to ubuntu workflow. --- .github/workflows/ubuntu.yml | 3 +++ 1 file changed, 3 insertions(+) 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]