diff --git a/include/errors/error.hpp b/include/errors/error.hpp index 55006d7..c664762 100644 --- a/include/errors/error.hpp +++ b/include/errors/error.hpp @@ -18,6 +18,12 @@ class Error { Error(const std::shared_ptr& message_ptr); public: + + /** + * @brief Constructs an empty error object. + */ + Error(); + /** * @brief Returns the error message. * diff --git a/src/error.cpp b/src/error.cpp index a7bb996..40d756f 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -4,6 +4,8 @@ namespace errors { Error::Error(const std::shared_ptr& message_ptr) : message_ptr(message_ptr) {} +Error::Error() {} + std::string_view Error::message() const { if (!message_ptr) return "no error"; return *message_ptr; diff --git a/test/error_test.cpp b/test/error_test.cpp index cbfb3e6..6b8b1a4 100644 --- a/test/error_test.cpp +++ b/test/error_test.cpp @@ -3,13 +3,15 @@ #include TEST_CASE("Error Construction") { - const errors::Error err = errors::make("unknown error"); + const auto err = errors::make("unknown error"); + REQUIRE(err); REQUIRE(err.message() == "unknown error"); } -TEST_CASE("Error Checking") { - const auto err = errors::make("unknown error"); - REQUIRE(err); +TEST_CASE("Empty Error Construction") { + const errors::Error err; + REQUIRE_FALSE(err); + REQUIRE(err.message() == "no error"); } TEST_CASE("Error Printing Using OStream") {