Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
- name: Configure and build this project
uses: threeal/[email protected]
with:
source-dir: example
build-dir: example/build
source-dir: error
build-dir: error/build
20 changes: 10 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ jobs:
- name: Configure, build, and test this project
uses: threeal/[email protected]
with:
source-dir: example
build-dir: example/build
source-dir: error
build-dir: error/build
args: -DBUILD_TESTING=ON
run-test: true

- name: Check code coverage
uses: threeal/gcovr-action@main
with:
root: example
root: error
excludes: |
example/build/*
example/test/*
error/build/*
error/test/*
fail-under-line: 100

check-warning:
Expand All @@ -37,8 +37,8 @@ jobs:
- name: Configure and build this project
uses: threeal/[email protected]
with:
source-dir: example
build-dir: example/build
source-dir: error
build-dir: error/build
cxx-flags: -Werror
args: -DBUILD_TESTING=ON

Expand All @@ -52,9 +52,9 @@ jobs:
run: pip3 install cmake-format

- name: Configure CMake
run: cmake example -B example/build
run: cmake error -B error/build

- name: Check code formatting
run: |
cmake --build example/build --target format
cmake --build example/build --target check-format
cmake --build error/build --target format
cmake --build error/build --target check-format
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

A comprehensive collection of [C++](https://isocpp.org/) utility packages.

## Packages

- [Error](./error) [WIP]: Provides utilities for error handling.

## License

This project is licensed under the terms of the [MIT License](./LICENSE).
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 8 additions & 7 deletions example/CMakeLists.txt → error/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
cmake_minimum_required(VERSION 3.0)

project(example)
project(error)

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

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

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
include(cmake/CPM.cmake)
Expand All @@ -19,8 +20,8 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)

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

add_executable(example_test test/example_test.cpp)
target_link_libraries(example_test PRIVATE example Catch2::Catch2WithMain)
catch_discover_tests(example_test)
add_executable(error_test test/error_test.cpp)
target_link_libraries(error_test PRIVATE error Catch2::Catch2WithMain)
catch_discover_tests(error_test)
endif()
endif()
21 changes: 21 additions & 0 deletions error/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Alfi Maulana

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions error/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Error

A C++ package that provides utilities for error handling.

## License

This project is licensed under the terms of the [MIT License](./LICENSE).

Copyright © 2023 [Alfi Maulana](https://github.com/threeal)
File renamed without changes.
28 changes: 28 additions & 0 deletions error/include/error/error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <exception>

namespace error {

/**
* @brief A class that represents error information.
*/
class Error : public std::exception {
private:
const char* message; /**< The error message. */

public:
/**
* @brief Constructs a new error with the given message.
* @param message An error message.
*/
Error(const char* message);

/**
* @brief Returns the explanatory string.
* @return Pointer to a null-terminated string with explanatory information.
*/
const char* what() const noexcept override;
};

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

namespace error {

Error::Error(const char* message) : message(message) {}

const char* Error::what() const noexcept { return message; }

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

TEST_CASE("Error Construction") {
const error::Error err("unknown error");
REQUIRE(std::string("unknown error") == err.what());
}

TEST_CASE("Error Throwing and Catching") {
SECTION("Catch as error::Error") {
try {
throw error::Error("unknown error");
} catch (const error::Error& err) {
REQUIRE(std::string("unknown error") == err.what());
} catch (...) {
FAIL("Expected to be caught as error::Error");
}
}

SECTION("Catch as std::exception") {
try {
throw error::Error("unknown error");
} catch (const std::exception& e) {
REQUIRE(std::string("unknown error") == e.what());
} catch (...) {
FAIL("Expected to be caught as std::exception");
}
}
}
24 changes: 0 additions & 24 deletions example/LICENSE

This file was deleted.

6 changes: 0 additions & 6 deletions example/README.md

This file was deleted.

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

This file was deleted.

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

This file was deleted.

7 changes: 0 additions & 7 deletions example/test/example_test.cpp

This file was deleted.