diff --git a/test/fixture.h b/test/fixture.h index 5983ae66a3a..2d519f40f45 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -331,8 +331,7 @@ class TestInstance { #define ASSERT_EQUALS_ENUM_LOC( EXPECTED, ACTUAL, FILE_, LINE_ ) assertEqualsEnum(FILE_, LINE_, (EXPECTED), (ACTUAL)) #define ASSERT_EQUALS_ENUM_LOC_MSG( EXPECTED, ACTUAL, MSG, FILE_, LINE_ ) assertEqualsEnum(FILE_, LINE_, (EXPECTED), (ACTUAL), MSG) #define TODO_ASSERT_EQUALS_ENUM( WANTED, CURRENT, ACTUAL ) todoAssertEqualsEnum(__FILE__, __LINE__, WANTED, CURRENT, ACTUAL) -#define ASSERT_THROW_EQUALS( CMD, EXCEPTION, EXPECTED ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) -#define ASSERT_THROW_EQUALS_2( CMD, EXCEPTION, EXPECTED ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const AssertFailedError&) { throw; } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.what()); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) +#define ASSERT_THROW_EQUALS( CMD, EXCEPTION, EXPECTED ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const AssertFailedError&) { throw; } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.what()); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) #define ASSERT_THROW_INTERNAL( CMD, TYPE ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const AssertFailedError&) { throw; } catch (const InternalError& e) { assertEqualsEnum(__FILE__, __LINE__, InternalError::TYPE, e.type); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) #define ASSERT_THROW_INTERNAL_EQUALS( CMD, TYPE, EXPECTED ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const AssertFailedError&) { throw; } catch (const InternalError& e) { assertEqualsEnum(__FILE__, __LINE__, InternalError::TYPE, e.type); assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) #define ASSERT_NO_THROW( CMD ) do { try { (void)(CMD); } catch (const AssertFailedError&) { throw; } catch (...) { assertNoThrowFail(__FILE__, __LINE__, true); } } while (false) diff --git a/test/testpath.cpp b/test/testpath.cpp index 7c181e28afb..5f4770f1cff 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -533,7 +533,7 @@ class TestPath : public TestFixture { #ifndef _WIN32 // the underlying realpath() call only returns something if the path actually exists - ASSERT_THROW_EQUALS_2(Path::getAbsoluteFilePath("testabspath2.txt"), std::runtime_error, "path 'testabspath2.txt' does not exist"); + ASSERT_THROW_EQUALS(Path::getAbsoluteFilePath("testabspath2.txt"), std::runtime_error, "path 'testabspath2.txt' does not exist"); #else ASSERT_EQUALS(Path::toNativeSeparators(Path::join(cwd, "testabspath2.txt")), Path::getAbsoluteFilePath("testabspath2.txt")); #endif @@ -572,7 +572,7 @@ class TestPath : public TestFixture { #endif #ifndef _WIN32 - ASSERT_THROW_EQUALS_2(Path::getAbsoluteFilePath("C:\\path\\files.txt"), std::runtime_error, "path 'C:\\path\\files.txt' does not exist"); + ASSERT_THROW_EQUALS(Path::getAbsoluteFilePath("C:\\path\\files.txt"), std::runtime_error, "path 'C:\\path\\files.txt' does not exist"); #endif // TODO: test UNC paths diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 53e2b2cf3f7..c53fed82e01 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -2866,7 +2866,7 @@ class TestPreprocessor : public TestFixture { std::vector files; TokenList tokenlist{settingsDefault, Standards::Language::CPP}; // TODO: can this happen from application code? if yes we need to turn it into a proper error - ASSERT_THROW_EQUALS_2(preprocess(code, files, "test.cpp", tokenlist, dui), std::runtime_error, "unexpected simplecpp::Output type 9"); + ASSERT_THROW_EQUALS(preprocess(code, files, "test.cpp", tokenlist, dui), std::runtime_error, "unexpected simplecpp::Output type 9"); ASSERT(!tokenlist.front()); // nothing is tokenized when an unknown standard is provided } } diff --git a/test/testprogrammemory.cpp b/test/testprogrammemory.cpp index a6cf933d843..6d7c185e80f 100644 --- a/test/testprogrammemory.cpp +++ b/test/testprogrammemory.cpp @@ -98,8 +98,8 @@ class TestProgramMemory : public TestFixture { void at() const { ProgramMemory pm; - ASSERT_THROW_EQUALS_2(pm.at(123), std::out_of_range, "ProgramMemory::at"); - ASSERT_THROW_EQUALS_2(utils::as_const(pm).at(123), std::out_of_range, "ProgramMemory::at"); + ASSERT_THROW_EQUALS(pm.at(123), std::out_of_range, "ProgramMemory::at"); + ASSERT_THROW_EQUALS(utils::as_const(pm).at(123), std::out_of_range, "ProgramMemory::at"); } }; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index e106bb4ccd8..19c6fab336a 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -1872,11 +1872,11 @@ class TestSymbolDatabase : public TestFixture { // TODO: we should provide our own error message #ifdef _MSC_VER - ASSERT_THROW_EQUALS_2(db->getVariableFromVarId(3), std::out_of_range, "invalid vector subscript"); + ASSERT_THROW_EQUALS(db->getVariableFromVarId(3), std::out_of_range, "invalid vector subscript"); #elif !defined(_LIBCPP_VERSION) - ASSERT_THROW_EQUALS_2(db->getVariableFromVarId(3), std::out_of_range, "vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)"); + ASSERT_THROW_EQUALS(db->getVariableFromVarId(3), std::out_of_range, "vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)"); #else - ASSERT_THROW_EQUALS_2(db->getVariableFromVarId(3), std::out_of_range, "vector"); + ASSERT_THROW_EQUALS(db->getVariableFromVarId(3), std::out_of_range, "vector"); #endif } diff --git a/test/testutils.cpp b/test/testutils.cpp index 0aad2c447a1..2526591e11f 100644 --- a/test/testutils.cpp +++ b/test/testutils.cpp @@ -225,24 +225,24 @@ class TestUtils : public TestFixture { ASSERT_EQUALS(1, ::strToInt("1")); ASSERT_EQUALS(-1, ::strToInt("-1")); ASSERT_EQUALS(1, ::strToInt("1")); - ASSERT_THROW_EQUALS_2(::strToInt(""), std::runtime_error, "converting '' to integer failed - not an integer"); - ASSERT_THROW_EQUALS_2(::strToInt(""), std::runtime_error, "converting '' to integer failed - not an integer"); - ASSERT_THROW_EQUALS_2(::strToInt(" "), std::runtime_error, "converting ' ' to integer failed - not an integer"); - ASSERT_THROW_EQUALS_2(::strToInt(" "), std::runtime_error, "converting ' ' to integer failed - not an integer"); - ASSERT_THROW_EQUALS_2(::strToInt("-1"), std::runtime_error, "converting '-1' to integer failed - needs to be positive"); - ASSERT_THROW_EQUALS_2(::strToInt("1ms"), std::runtime_error, "converting '1ms' to integer failed - not an integer"); - ASSERT_THROW_EQUALS_2(::strToInt("1.0"), std::runtime_error, "converting '1.0' to integer failed - not an integer"); - ASSERT_THROW_EQUALS_2(::strToInt("one"), std::runtime_error, "converting 'one' to integer failed - not an integer"); - ASSERT_THROW_EQUALS_2(::strToInt("1ms"), std::runtime_error, "converting '1ms' to integer failed - not an integer"); - ASSERT_THROW_EQUALS_2(::strToInt("1.0"), std::runtime_error, "converting '1.0' to integer failed - not an integer"); - ASSERT_THROW_EQUALS_2(::strToInt("one"), std::runtime_error, "converting 'one' to integer failed - not an integer"); - ASSERT_THROW_EQUALS_2(::strToInt(std::to_string(static_cast(std::numeric_limits::max()) + 1)), std::runtime_error, "converting '2147483648' to integer failed - out of range (limits)"); - ASSERT_THROW_EQUALS_2(::strToInt(std::to_string(static_cast(std::numeric_limits::min()) - 1)), std::runtime_error, "converting '-2147483649' to integer failed - out of range (limits)"); - ASSERT_THROW_EQUALS_2(::strToInt(std::to_string(static_cast(std::numeric_limits::max()) + 1)), std::runtime_error, "converting '128' to integer failed - out of range (limits)"); - ASSERT_THROW_EQUALS_2(::strToInt(std::to_string(static_cast(std::numeric_limits::min()) - 1)), std::runtime_error, "converting '-129' to integer failed - out of range (limits)"); - ASSERT_THROW_EQUALS_2(::strToInt(std::to_string(static_cast(std::numeric_limits::max()) + 1)), std::runtime_error, "converting '4294967296' to integer failed - out of range (limits)"); - ASSERT_THROW_EQUALS_2(::strToInt("9223372036854775808"), std::runtime_error, "converting '9223372036854775808' to integer failed - out of range (stoll)"); // LLONG_MAX + 1 - ASSERT_THROW_EQUALS_2(::strToInt("18446744073709551616"), std::runtime_error, "converting '18446744073709551616' to integer failed - out of range (stoull)"); // ULLONG_MAX + 1 + ASSERT_THROW_EQUALS(::strToInt(""), std::runtime_error, "converting '' to integer failed - not an integer"); + ASSERT_THROW_EQUALS(::strToInt(""), std::runtime_error, "converting '' to integer failed - not an integer"); + ASSERT_THROW_EQUALS(::strToInt(" "), std::runtime_error, "converting ' ' to integer failed - not an integer"); + ASSERT_THROW_EQUALS(::strToInt(" "), std::runtime_error, "converting ' ' to integer failed - not an integer"); + ASSERT_THROW_EQUALS(::strToInt("-1"), std::runtime_error, "converting '-1' to integer failed - needs to be positive"); + ASSERT_THROW_EQUALS(::strToInt("1ms"), std::runtime_error, "converting '1ms' to integer failed - not an integer"); + ASSERT_THROW_EQUALS(::strToInt("1.0"), std::runtime_error, "converting '1.0' to integer failed - not an integer"); + ASSERT_THROW_EQUALS(::strToInt("one"), std::runtime_error, "converting 'one' to integer failed - not an integer"); + ASSERT_THROW_EQUALS(::strToInt("1ms"), std::runtime_error, "converting '1ms' to integer failed - not an integer"); + ASSERT_THROW_EQUALS(::strToInt("1.0"), std::runtime_error, "converting '1.0' to integer failed - not an integer"); + ASSERT_THROW_EQUALS(::strToInt("one"), std::runtime_error, "converting 'one' to integer failed - not an integer"); + ASSERT_THROW_EQUALS(::strToInt(std::to_string(static_cast(std::numeric_limits::max()) + 1)), std::runtime_error, "converting '2147483648' to integer failed - out of range (limits)"); + ASSERT_THROW_EQUALS(::strToInt(std::to_string(static_cast(std::numeric_limits::min()) - 1)), std::runtime_error, "converting '-2147483649' to integer failed - out of range (limits)"); + ASSERT_THROW_EQUALS(::strToInt(std::to_string(static_cast(std::numeric_limits::max()) + 1)), std::runtime_error, "converting '128' to integer failed - out of range (limits)"); + ASSERT_THROW_EQUALS(::strToInt(std::to_string(static_cast(std::numeric_limits::min()) - 1)), std::runtime_error, "converting '-129' to integer failed - out of range (limits)"); + ASSERT_THROW_EQUALS(::strToInt(std::to_string(static_cast(std::numeric_limits::max()) + 1)), std::runtime_error, "converting '4294967296' to integer failed - out of range (limits)"); + ASSERT_THROW_EQUALS(::strToInt("9223372036854775808"), std::runtime_error, "converting '9223372036854775808' to integer failed - out of range (stoll)"); // LLONG_MAX + 1 + ASSERT_THROW_EQUALS(::strToInt("18446744073709551616"), std::runtime_error, "converting '18446744073709551616' to integer failed - out of range (stoull)"); // ULLONG_MAX + 1 { long tmp;