-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix function call in macro argument (#156)
* Add unit tests to RoughPy_Core Introduced unit tests for the RoughPy_Core module by adding a new `src` directory with necessary CMake file and a sample test case. This aims to ensure better code reliability and automated validation of core functionalities. * Rename string_utilss.h to string_utils.h Corrected a typo in the header file name from string_utilss.h to string_utils.h to ensure consistency and prevent potential issues with file inclusion. Adjusted CMakeLists.txt accordingly to reflect this change. * Refactor macros and improve RPY_CHECK messages Moved and added macros for better preprocessor handling from `macros.h` to a new section. Enhanced RPY_CHECK macro variants in `check.h` to include detailed failure messages for easier debugging. * Add TODO for customizable check messages Inserted a TODO comment to highlight the need for customizable messages in RPY_CHECK macros. This will improve clarity and debugging for future checks. * Fix missing commas in RPY_CHECK macro definitions Added missing commas in the RPY_CHECK_* macro definitions for better clarity and correctness. This change ensures that the macros are formatted correctly and align with typical macro usage standards. * Add throw_exception template for detailed error messages Introduce a templated function `throw_exception` to standardize and improve error reporting. This function concatenates relevant error details such as filename, line number, and function name into a comprehensive message before throwing the specified exception type. * Set default exception type in throw_exception template. Changed the throw_exception template to default to std::runtime_error if no exception type is specified. This improves code simplicity and reduces the need for explicit template arguments. * Add unit tests for RPY_CHECK macros with custom exceptions This commit introduces new unit tests to verify the behavior of various RPY_CHECK macros when throwing both standard runtime exceptions and specific custom exceptions. These tests ensure that the macros function correctly under different failure conditions. * Refactor formatting of error checks and debug assertions Refactored the formatting for the `throw_exception` template function and macros to improve readability. Adjusted the alignment and spacing within the macros and definitions in both `check.h` and `debug_assertion.h` to adhere to consistent code style.
- Loading branch information
1 parent
a51d92a
commit e2b9615
Showing
7 changed files
with
201 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
|
||
|
||
|
||
if(ROUGHPY_BUILD_TESTS) | ||
|
||
|
||
add_executable(test_core | ||
test_check_macros.cpp) | ||
|
||
|
||
target_include_directories(test_core PRIVATE ${ROUGHPY_CORE_INCLUDE}) | ||
|
||
target_link_libraries(test_core PRIVATE RoughPy::Core GTest::gtest) | ||
|
||
setup_roughpy_cpp_tests(test_core) | ||
|
||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// | ||
// Created by sammorley on 15/11/24. | ||
// | ||
|
||
|
||
|
||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "check.h" | ||
|
||
|
||
TEST(CheckMacros, TestCheckFailStandard) | ||
{ | ||
EXPECT_THROW(RPY_CHECK(false), std::runtime_error); | ||
} | ||
|
||
TEST(CheckMacros, TestCHeckWithSpecifiedException) | ||
{ | ||
EXPECT_THROW( | ||
RPY_CHECK(false, "message", std::invalid_argument), | ||
std::invalid_argument | ||
); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckEqFails) | ||
{ | ||
EXPECT_THROW(RPY_CHECK_EQ(1, 2), std::runtime_error); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckEqFailsCustomException) | ||
{ | ||
EXPECT_THROW( | ||
RPY_CHECK_EQ(1, 2, std::invalid_argument), | ||
std::invalid_argument | ||
); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckNeFails) | ||
{ | ||
EXPECT_THROW(RPY_CHECK_NE(1, 1), std::runtime_error); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckNeFailsCustomException) | ||
{ | ||
EXPECT_THROW( | ||
RPY_CHECK_NE(1, 1, std::invalid_argument), | ||
std::invalid_argument | ||
); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckLtFails) | ||
{ | ||
EXPECT_THROW(RPY_CHECK_LT(2, 1), std::runtime_error); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckLtFailsCustomException) | ||
{ | ||
EXPECT_THROW( | ||
RPY_CHECK_LT(2, 1, std::invalid_argument), | ||
std::invalid_argument | ||
); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckLeFails) | ||
{ | ||
EXPECT_THROW(RPY_CHECK_LE(2, 1), std::runtime_error); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckLeFailsCustomException) | ||
{ | ||
EXPECT_THROW( | ||
RPY_CHECK_LE(2, 1, std::invalid_argument), | ||
std::invalid_argument | ||
); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckGtFails) | ||
{ | ||
EXPECT_THROW(RPY_CHECK_GT(1, 2), std::runtime_error); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckGtFailsCustomException) | ||
{ | ||
EXPECT_THROW( | ||
RPY_CHECK_GT(1, 2, std::invalid_argument), | ||
std::invalid_argument | ||
); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckGeFails) | ||
{ | ||
EXPECT_THROW(RPY_CHECK_GE(1, 2), std::runtime_error); | ||
} | ||
|
||
TEST(CheckMacros, TestCheckGeFailsCustomException) | ||
{ | ||
EXPECT_THROW( | ||
RPY_CHECK_GE(1, 2, std::invalid_argument), | ||
std::invalid_argument | ||
); | ||
} |