From 90bb8d54b61b1b295239da0eb540e653d0f02226 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 13 Dec 2020 11:45:00 +0100 Subject: [PATCH] Rename Assert.hpp --> Ensure.hpp, style fixes. --- src/Collections/Dictionary.hpp | 2 +- src/{Assert.hpp => Ensure.hpp} | 2 +- src/Memory/__BorrowedPtr.hpp | 2 +- src/Memory/__OptionalBorrowedPtr.hpp | 2 +- src/Memory/__OptionalUniquePtr.hpp | 2 +- src/Memory/__OptionalUniquePtrList.hpp | 4 ++-- src/Memory/__ScopedPtr.hpp | 2 +- src/Memory/__UniquePtr.hpp | 2 +- src/Memory/__UniquePtrList.hpp | 2 +- src/Random.hpp | 2 +- tests/EnsureTests.cpp | 15 +++++++++------ 11 files changed, 20 insertions(+), 17 deletions(-) rename src/{Assert.hpp => Ensure.hpp} (97%) diff --git a/src/Collections/Dictionary.hpp b/src/Collections/Dictionary.hpp index 2ddb486..c37ad0b 100644 --- a/src/Collections/Dictionary.hpp +++ b/src/Collections/Dictionary.hpp @@ -1,6 +1,6 @@ #ifndef ARBUTILS_DICTIONARY_HPP #define ARBUTILS_DICTIONARY_HPP -#include "../Assert.hpp" +#include "../Ensure.hpp" namespace ArbUt { /// @brief Wrapper around unordered_map, allowing safer access and adding several helper methods. diff --git a/src/Assert.hpp b/src/Ensure.hpp similarity index 97% rename from src/Assert.hpp rename to src/Ensure.hpp index 8fee4df..240cfe0 100644 --- a/src/Assert.hpp +++ b/src/Ensure.hpp @@ -10,7 +10,7 @@ #define Ensure(expr) \ if (!(expr)) { \ std::stringstream ss; \ - ss << "[" << file_name(__FILE__) << ":" << __LINE__ << "] ENSURE FAILED: \""; \ + ss << "[" << file_name(__FILE__) << ":" << __LINE__ << "] ENSURE FAILED: \""; \ ss << #expr << "\""; \ throw ArbUt::Exception(ss.str()); \ } diff --git a/src/Memory/__BorrowedPtr.hpp b/src/Memory/__BorrowedPtr.hpp index ee63693..fb6af2b 100644 --- a/src/Memory/__BorrowedPtr.hpp +++ b/src/Memory/__BorrowedPtr.hpp @@ -1,7 +1,7 @@ #ifndef ARBUTILS___BORROWEDPTR_HPP #define ARBUTILS___BORROWEDPTR_HPP -#include "../Assert.hpp" +#include "../Ensure.hpp" namespace ArbUt { /// @brief A borrowed pointer is used to indicate a pointer that is not owned by its holder. As with all Arbutils diff --git a/src/Memory/__OptionalBorrowedPtr.hpp b/src/Memory/__OptionalBorrowedPtr.hpp index 2dddc15..d37a92f 100644 --- a/src/Memory/__OptionalBorrowedPtr.hpp +++ b/src/Memory/__OptionalBorrowedPtr.hpp @@ -1,7 +1,7 @@ #ifndef ARBUTILS___OPTIONALBORROWEDPTR_HPP #define ARBUTILS___OPTIONALBORROWEDPTR_HPP -#include "../Assert.hpp" +#include "../Ensure.hpp" namespace ArbUt { /// @brief An optional borrowed pointer is used to indicate a pointer that is not owned by its holder. This pointer diff --git a/src/Memory/__OptionalUniquePtr.hpp b/src/Memory/__OptionalUniquePtr.hpp index 56e0412..c4db339 100644 --- a/src/Memory/__OptionalUniquePtr.hpp +++ b/src/Memory/__OptionalUniquePtr.hpp @@ -1,7 +1,7 @@ #ifndef ARBUTILS_OPTIONALOptionalUniquePtr_HPP #define ARBUTILS_OPTIONALOptionalUniquePtr_HPP -#include "../Assert.hpp" +#include "../Ensure.hpp" namespace ArbUt { /// @brief An optional unique pointer is used to indicate a pointer that is owned by its holder, and will be deleted diff --git a/src/Memory/__OptionalUniquePtrList.hpp b/src/Memory/__OptionalUniquePtrList.hpp index 51915a0..cd64c6a 100644 --- a/src/Memory/__OptionalUniquePtrList.hpp +++ b/src/Memory/__OptionalUniquePtrList.hpp @@ -17,8 +17,8 @@ namespace ArbUt { /// @brief Initialises a OptionalUniquePtrList from a std::vector of raw pointers. /// @param vec A std::vector of raw pointers. inline OptionalUniquePtrList(const std::vector& vec) noexcept : _vector(vec) {} - /// @brief Initialises a OptionalUniquePtrList with a certain capacity reserved for use. This does not set immediate - /// size. + /// @brief Initialises a OptionalUniquePtrList with a certain capacity reserved for use. This does not set + /// immediate size. /// @param capacity The desired capacity. explicit inline OptionalUniquePtrList(size_t capacity) : _vector() { _vector.reserve(capacity); } /// @brief Initialises a OptionalUniquePtrList from a initialiser_list. diff --git a/src/Memory/__ScopedPtr.hpp b/src/Memory/__ScopedPtr.hpp index 4c34d8a..9b43614 100644 --- a/src/Memory/__ScopedPtr.hpp +++ b/src/Memory/__ScopedPtr.hpp @@ -1,7 +1,7 @@ #ifndef ARBUTILS___SCOPEDPTR_HPP #define ARBUTILS___SCOPEDPTR_HPP -#include "../Assert.hpp" +#include "../Ensure.hpp" namespace ArbUt { /// @brief An optional unique pointer is used to indicate a pointer that is owned by its holder, and will be deleted diff --git a/src/Memory/__UniquePtr.hpp b/src/Memory/__UniquePtr.hpp index ea6ebdd..d329064 100644 --- a/src/Memory/__UniquePtr.hpp +++ b/src/Memory/__UniquePtr.hpp @@ -1,7 +1,7 @@ #ifndef ARBUTILS___UNIQUEPTR_HPP #define ARBUTILS___UNIQUEPTR_HPP -#include "../Assert.hpp" +#include "../Ensure.hpp" namespace ArbUt { /// @brief A unique pointer is used to indicate a pointer that is owned by its holder, and will be deleted when its diff --git a/src/Memory/__UniquePtrList.hpp b/src/Memory/__UniquePtrList.hpp index 515fd17..f720ed4 100644 --- a/src/Memory/__UniquePtrList.hpp +++ b/src/Memory/__UniquePtrList.hpp @@ -1,7 +1,7 @@ #ifndef ARBUTILS___UNIQUEPTRLIST_HPP #define ARBUTILS___UNIQUEPTRLIST_HPP -#include "../Assert.hpp" +#include "../Ensure.hpp" #include "__BorrowedPtr.hpp" namespace ArbUt { diff --git a/src/Random.hpp b/src/Random.hpp index 966966e..fb8e58e 100644 --- a/src/Random.hpp +++ b/src/Random.hpp @@ -5,7 +5,7 @@ #include #include #include "../extern/pcg_random.hpp" -#include "Assert.hpp" +#include "Ensure.hpp" namespace ArbUt { /// @brief A helper class for getting random numbers. diff --git a/tests/EnsureTests.cpp b/tests/EnsureTests.cpp index 2475d36..e9c17d8 100644 --- a/tests/EnsureTests.cpp +++ b/tests/EnsureTests.cpp @@ -1,9 +1,11 @@ #include "../extern/doctest.hpp" -#include "../src/Assert.hpp" +#include "../src/Ensure.hpp" void TestWrapper(bool wrapperExpression) { Ensure(wrapperExpression) } -void TestWrapperNotNull(void* value) {EnsureNotNull(value) } +void TestWrapperNotNull(void* value){EnsureNotNull(value)} -TEST_CASE("Ensure succeeds if true") { REQUIRE_NOTHROW(TestWrapper(true)); } +TEST_CASE("Ensure succeeds if true") { + REQUIRE_NOTHROW(TestWrapper(true)); +} TEST_CASE("Ensure throws if false") { REQUIRE_THROWS(TestWrapper(false)); } @@ -17,10 +19,11 @@ TEST_CASE("Ensure throws if false with message") { throw ArbUt::Exception("Didn't throw."); } -TEST_CASE("Multiple asserts") {Ensure(true) Ensure(true) Ensure(true) -} +TEST_CASE("Multiple asserts"){Ensure(true) Ensure(true) Ensure(true)} -TEST_CASE("EnsureNotNull throws if nullptr") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); } +TEST_CASE("EnsureNotNull throws if nullptr") { + REQUIRE_THROWS(TestWrapperNotNull(nullptr)); +} TEST_CASE("Ensure for each") { auto i = {10, 500, 2300, 454};