Skip to content

Commit 00c5dcd

Browse files
authored
feat: add support to create empty error (#101)
* test: merge error checking test to error construction test * feat: add `Error::Error()` constructor
1 parent a34183f commit 00c5dcd

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

include/errors/error.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class Error {
1818
Error(const std::shared_ptr<const std::string>& message_ptr);
1919

2020
public:
21+
22+
/**
23+
* @brief Constructs an empty error object.
24+
*/
25+
Error();
26+
2127
/**
2228
* @brief Returns the error message.
2329
*

src/error.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace errors {
44

55
Error::Error(const std::shared_ptr<const std::string>& message_ptr) : message_ptr(message_ptr) {}
66

7+
Error::Error() {}
8+
79
std::string_view Error::message() const {
810
if (!message_ptr) return "no error";
911
return *message_ptr;

test/error_test.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
#include <sstream>
44

55
TEST_CASE("Error Construction") {
6-
const errors::Error err = errors::make("unknown error");
6+
const auto err = errors::make("unknown error");
7+
REQUIRE(err);
78
REQUIRE(err.message() == "unknown error");
89
}
910

10-
TEST_CASE("Error Checking") {
11-
const auto err = errors::make("unknown error");
12-
REQUIRE(err);
11+
TEST_CASE("Empty Error Construction") {
12+
const errors::Error err;
13+
REQUIRE_FALSE(err);
14+
REQUIRE(err.message() == "no error");
1315
}
1416

1517
TEST_CASE("Error Printing Using OStream") {

0 commit comments

Comments
 (0)