Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Add test suite #2

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
5 changes: 4 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
58 changes: 58 additions & 0 deletions test/value_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (C) 2022 Andrea Ballestrazzi

#include <catch2/catch_template_test_macros.hpp>
#include <popl.hpp>

// C++ STL
#include <string_view>
#include <memory>

namespace test{

template<typename T>
static void assertValueCorrectlyConstructed(
const popl::Value<T>& 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<popl::Value<TestType>> valueUnderTest{};

// Precondition
REQUIRE_NOTHROW(valueUnderTest
= std::make_unique<popl::Value<TestType>>(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<TestType>(std::string{INVALID_SHORT_NAME}, std::string{VALID_LONG_NAME}, std::string{VALID_DESCRIPTION}),
std::invalid_argument);
}
}
}
}
}