Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testrunner: improved InternalError assertions #6262

Merged
merged 2 commits into from
Apr 10, 2024
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
2 changes: 2 additions & 0 deletions test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ class TestFixture : public ErrorLogger {
#define ASSERT_THROW( CMD, EXCEPTION ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) {} catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false)
#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
2 changes: 1 addition & 1 deletion test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class TestAutoVariables : public TestFixture {
}

void testautovar12() { // Ticket #5024, #5050 - Crash on invalid input
ASSERT_THROW(check("void f(int* a) { a = }"), InternalError);
ASSERT_THROW_INTERNAL(check("void f(int* a) { a = }"), SYNTAX);
check("struct custom_type { custom_type(int) {} };\n"
"void func(int) {}\n"
"int var;\n"
Expand Down
12 changes: 6 additions & 6 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2787,12 +2787,12 @@ class TestCondition : public TestFixture {
"}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", errout_str());

ASSERT_THROW(check("void f(int x) {\n" // #8217 - crash for incomplete code
" if (x > 100) { return; }\n"
" X(do);\n"
" if (x > 100) {}\n"
"}"),
InternalError);
ASSERT_THROW_INTERNAL(check("void f(int x) {\n" // #8217 - crash for incomplete code
" if (x > 100) { return; }\n"
" X(do);\n"
" if (x > 100) {}\n"
"}"),
SYNTAX);

check("void f(const int *i) {\n"
" if (!i) return;\n"
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(msg.deserialize(str), InternalError);
ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize(str), INTERNAL, "Internal Error: Deserialization of error message failed - invalid CWE ID - out of range (limits)");
}
}

Expand Down
Loading
Loading