Skip to content

Commit

Permalink
feat(error): add Error struct
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Jun 21, 2023
1 parent bb5176b commit 60e3d63
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
5 changes: 3 additions & 2 deletions error/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ cmake_minimum_required(VERSION 3.0)
project(error)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wpedantic")
set(CMAKE_CXX_STANDARD 11)

add_library(error src/example.cpp)
add_library(error src/error.cpp)
target_include_directories(error PUBLIC include)

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
Expand All @@ -19,7 +20,7 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fPIC -O0")

add_executable(error_test test/example_test.cpp)
add_executable(error_test test/error_test.cpp)
target_link_libraries(error_test PRIVATE error Catch2::Catch2WithMain)
catch_discover_tests(error_test)
endif()
Expand Down
18 changes: 18 additions & 0 deletions error/include/error/error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <exception>

namespace error {

/**
* @brief A struct that represents error information.
*/
struct Error : public std::exception {
/**
* @brief Returns the explanatory string.
* @return Pointer to a null-terminated string with explanatory information.
*/
const char* what() const noexcept override;
};

} // namespace error
7 changes: 0 additions & 7 deletions error/include/example/example.hpp

This file was deleted.

7 changes: 7 additions & 0 deletions error/src/error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <error/error.hpp>

namespace error {

const char* Error::what() const noexcept { return "unknown error"; }

} // namespace error
7 changes: 0 additions & 7 deletions error/src/example.cpp

This file was deleted.

8 changes: 8 additions & 0 deletions error/test/error_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <catch2/catch_test_macros.hpp>
#include <error/error.hpp>

TEST_CASE("test Error::what") {
const error::Error err;
const std::string expected("unknown error");
REQUIRE(expected.compare(err.what()) == 0);
}
7 changes: 0 additions & 7 deletions error/test/example_test.cpp

This file was deleted.

0 comments on commit 60e3d63

Please # to comment.