Skip to content

Commit

Permalink
testrunner: added ASSERT_THROW_INTERNAL_EQUALS
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 10, 2024
1 parent e43037d commit 82a4220
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 94 deletions.
1 change: 1 addition & 0 deletions test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ class TestFixture : public ErrorLogger {
#define ASSERT_THROW_EQUALS( CMD, EXCEPTION, EXPECTED ) do { try { 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 { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.what()); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false)
#define ASSERT_THROW_INTERNAL( CMD, TYPE ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } 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 { CMD; assertThrowFail(__FILE__, __LINE__); } 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 { CMD; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } } while (false)
#define TODO_ASSERT_THROW( CMD, EXCEPTION ) do { try { CMD; } catch (const EXCEPTION&) {} catch (...) { assertThrow(__FILE__, __LINE__); } } while (false)
#define TODO_ASSERT( CONDITION ) do { const bool condition=(CONDITION); todoAssertEquals(__FILE__, __LINE__, true, false, condition); } while (false)
Expand Down
14 changes: 7 additions & 7 deletions test/testerrorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,22 +348,22 @@ class TestErrorLogger : public TestFixture {
// missing/invalid length
// missing separator
ErrorMessage msg;
ASSERT_THROW_EQUALS(msg.deserialize("500foobar"), InternalError, "Internal Error: Deserialization of error message failed - invalid separator");
ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize("500foobar"), INTERNAL, "Internal Error: Deserialization of error message failed - invalid separator");
}
{
// invalid length
ErrorMessage msg;
ASSERT_THROW_EQUALS(msg.deserialize("foo foobar"), InternalError, "Internal Error: Deserialization of error message failed - invalid length");
ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize("foo foobar"), INTERNAL, "Internal Error: Deserialization of error message failed - invalid length");
}
{
// mismatching length
ErrorMessage msg;
ASSERT_THROW_EQUALS(msg.deserialize("8 errorId"), InternalError, "Internal Error: Deserialization of error message failed - premature end of data");
ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize("8 errorId"), INTERNAL, "Internal Error: Deserialization of error message failed - premature end of data");
}
{
// incomplete message
ErrorMessage msg;
ASSERT_THROW_EQUALS(msg.deserialize("7 errorId"), InternalError, "Internal Error: Deserialization of error message failed - invalid length");
ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize("7 errorId"), INTERNAL, "Internal Error: Deserialization of error message failed - invalid length");
}
{
// invalid CWE ID
Expand All @@ -376,7 +376,7 @@ class TestErrorLogger : public TestFixture {
"17 Programming error"
"0 ";
ErrorMessage msg;
ASSERT_THROW_EQUALS(msg.deserialize(str), InternalError, "Internal Error: Deserialization of error message failed - invalid CWE ID - not an integer");
ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize(str), INTERNAL, "Internal Error: Deserialization of error message failed - invalid CWE ID - not an integer");
}
{
// invalid hash
Expand All @@ -389,7 +389,7 @@ class TestErrorLogger : public TestFixture {
"17 Programming error"
"0 ";
ErrorMessage msg;
ASSERT_THROW_EQUALS(msg.deserialize(str), InternalError, "Internal Error: Deserialization of error message failed - invalid hash - not an integer");
ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize(str), INTERNAL, "Internal Error: Deserialization of error message failed - invalid hash - not an integer");
}
{
// out-of-range CWE ID
Expand All @@ -402,7 +402,7 @@ class TestErrorLogger : public TestFixture {
"17 Programming error"
"0 ";
ErrorMessage msg;
ASSERT_THROW_INTERNAL(msg.deserialize(str), INTERNAL);
ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize(str), INTERNAL, "Internal Error: Deserialization of error message failed - invalid CWE ID - out of range (limits)");
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/testgarbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,10 @@ class TestGarbage : public TestFixture {
}

void garbageCode99() { // #6726
ASSERT_THROW_INTERNAL(checkCode("{ xs :: i(:) ! ! x/5 ! !\n"
"i, :: a :: b integer, } foo2(x) :: j(:)\n"
"b type(*), d(:), a x :: end d(..), foo end\n"
"foo4 b d(..), a a x type(*), b foo2 b"), INTERNAL);
ASSERT_THROW_INTERNAL_EQUALS(checkCode("{ xs :: i(:) ! ! x/5 ! !\n"
"i, :: a :: b integer, } foo2(x) :: j(:)\n"
"b type(*), d(:), a x :: end d(..), foo end\n"
"foo4 b d(..), a a x type(*), b foo2 b"), INTERNAL, "Internal error. AST cyclic dependency.");
}

void garbageCode100() { // #6840
Expand Down
16 changes: 8 additions & 8 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3090,14 +3090,14 @@ class TestLeakAutoVarRecursiveCountLimit : public TestFixture {
}

void recursiveCountLimit() { // #5872 #6157 #9097
ASSERT_THROW_INTERNAL(checkP("#define ONE else if (0) { }\n"
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n"
"void foo() {\n"
" if (0) { }\n"
" THOU THOU\n"
"}"), LIMIT);
ASSERT_THROW_INTERNAL_EQUALS(checkP("#define ONE else if (0) { }\n"
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n"
"void foo() {\n"
" if (0) { }\n"
" THOU THOU\n"
"}"), LIMIT, "Internal limit: CheckLeakAutoVar::checkScope() Maximum recursive count of 1000 reached.");
ASSERT_NO_THROW(checkP("#define ONE if (0) { }\n"
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
Expand Down
Loading

0 comments on commit 82a4220

Please sign in to comment.