Skip to content

Commit

Permalink
testrunner: added ASSERT_THROW_INTERNAL
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 10, 2024
1 parent 3ad4533 commit e43037d
Show file tree
Hide file tree
Showing 15 changed files with 528 additions and 527 deletions.
1 change: 1 addition & 0 deletions test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ 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_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
2 changes: 1 addition & 1 deletion test/testerrorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class TestErrorLogger : public TestFixture {
"17 Programming error"
"0 ";
ErrorMessage msg;
ASSERT_THROW(msg.deserialize(str), InternalError);
ASSERT_THROW_INTERNAL(msg.deserialize(str), INTERNAL);
}
}

Expand Down
786 changes: 393 additions & 393 deletions test/testgarbage.cpp

Large diffs are not rendered by default.

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(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"
"}"), InternalError);
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_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
34 changes: 17 additions & 17 deletions test/testsimplifytemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ class TestSimplifyTemplate : public TestFixture {
void template27() {
// #3350 - template inside macro call
const char code[] = "X(template<class T> class Fred);";
ASSERT_THROW(tok(code), InternalError);
ASSERT_THROW_INTERNAL(tok(code), SYNTAX);
}

void template28() {
Expand Down Expand Up @@ -1108,7 +1108,7 @@ class TestSimplifyTemplate : public TestFixture {
" return sizeof...(args);\n"
" }();\n"
"}";
ASSERT_THROW(tok(code), InternalError);
ASSERT_THROW_INTERNAL(tok(code), SYNTAX);
}

void template43() { // #5097 - Assert due to '>>' in 'B<A<C>>' not being treated as end of template instantiation
Expand Down Expand Up @@ -3059,14 +3059,14 @@ class TestSimplifyTemplate : public TestFixture {
}

void template125() {
ASSERT_THROW(tok("template<int M, int N>\n"
"class GCD {\n"
"public:\n"
" enum { val = (N == 0) ? M : GCD<N, M % N>::val };\n"
"};\n"
"int main() {\n"
" GCD< 1, 0 >::val;\n"
"}"), InternalError);
ASSERT_THROW_INTERNAL(tok("template<int M, int N>\n"
"class GCD {\n"
"public:\n"
" enum { val = (N == 0) ? M : GCD<N, M % N>::val };\n"
"};\n"
"int main() {\n"
" GCD< 1, 0 >::val;\n"
"}"), INSTANTIATION);
}

void template126() { // #9217
Expand Down Expand Up @@ -4952,15 +4952,15 @@ class TestSimplifyTemplate : public TestFixture {
ASSERT_EQUALS("", errout_str());

// bad code.. missing ">"
ASSERT_THROW(tok("x<y<int> xyz;\n"), InternalError);
ASSERT_THROW_INTERNAL(tok("x<y<int> xyz;\n"), SYNTAX);

// bad code
ASSERT_THROW(tok("typedef\n"
" typename boost::mpl::if_c<\n"
" _visitableIndex < boost::mpl::size< typename _Visitables::ConcreteVisitables >::value\n"
" , ConcreteVisitable\n"
" , Dummy< _visitableIndex >\n"
" >::type ConcreteVisitableOrDummy;\n"), InternalError);
ASSERT_THROW_INTERNAL(tok("typedef\n"
" typename boost::mpl::if_c<\n"
" _visitableIndex < boost::mpl::size< typename _Visitables::ConcreteVisitables >::value\n"
" , ConcreteVisitable\n"
" , Dummy< _visitableIndex >\n"
" >::type ConcreteVisitableOrDummy;\n"), SYNTAX);

// code is ok, don't show syntax error
tok("struct A {int a;int b};\n"
Expand Down
4 changes: 2 additions & 2 deletions test/testsimplifytokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ class TestSimplifyTokens : public TestFixture {
void simplifyKnownVariables16() {
// ticket #807 - segmentation fault when macro isn't found
const char code[] = "void f ( ) { int n = 1; DISPATCH(while); }";
ASSERT_THROW(simplifyKnownVariables(code), InternalError);
ASSERT_THROW_INTERNAL(simplifyKnownVariables(code), UNKNOWN_MACRO);
}

void simplifyKnownVariables17() {
Expand Down Expand Up @@ -2266,7 +2266,7 @@ class TestSimplifyTokens : public TestFixture {
" BENCH1(q = _mhz_M(n); n = 1;)\n"
" use_pointer(q);\n"
"}";
ASSERT_THROW(tokenizeAndStringify(code, true), InternalError);
ASSERT_THROW_INTERNAL(tokenizeAndStringify(code, true), UNKNOWN_MACRO);
}

void simplifyKnownVariables54() { // #4913
Expand Down
20 changes: 10 additions & 10 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ class TestSimplifyTypedef : public TestFixture {
"LOCAL(type1) foo() { }";

// this is invalid C, assert that an "unknown macro" warning is written
ASSERT_THROW(checkSimplifyTypedef(code), InternalError);
ASSERT_THROW_INTERNAL(checkSimplifyTypedef(code), UNKNOWN_MACRO);
}
}

Expand Down Expand Up @@ -2121,7 +2121,7 @@ class TestSimplifyTypedef : public TestFixture {
}

void simplifyTypedef76() { // ticket #2453 segmentation fault
ASSERT_THROW(checkSimplifyTypedef("void f1(typedef int x) {}"), InternalError);
ASSERT_THROW_INTERNAL(checkSimplifyTypedef("void f1(typedef int x) {}"), SYNTAX);
}

void simplifyTypedef77() { // ticket #2554
Expand Down Expand Up @@ -2166,9 +2166,9 @@ class TestSimplifyTypedef : public TestFixture {
}

void simplifyTypedef81() { // ticket #2603 segmentation fault
ASSERT_THROW(checkSimplifyTypedef("typedef\n"), InternalError);
ASSERT_THROW_INTERNAL(checkSimplifyTypedef("typedef\n"), SYNTAX);

ASSERT_THROW(checkSimplifyTypedef("typedef constexpr\n"), InternalError);
ASSERT_THROW_INTERNAL(checkSimplifyTypedef("typedef constexpr\n"), SYNTAX);
}

void simplifyTypedef82() { // ticket #2403
Expand Down Expand Up @@ -2200,13 +2200,13 @@ class TestSimplifyTypedef : public TestFixture {

void simplifyTypedef84() { // ticket #2630 (segmentation fault)
const char code1[] = "typedef y x () x";
ASSERT_THROW(checkSimplifyTypedef(code1), InternalError);
ASSERT_THROW_INTERNAL(checkSimplifyTypedef(code1), SYNTAX);

const char code2[] = "typedef struct template <>";
ASSERT_THROW(checkSimplifyTypedef(code2), InternalError);
ASSERT_THROW_INTERNAL(checkSimplifyTypedef(code2), SYNTAX);

const char code3[] = "typedef ::<>";
ASSERT_THROW(checkSimplifyTypedef(code3), InternalError);
ASSERT_THROW_INTERNAL(checkSimplifyTypedef(code3), SYNTAX);
}

void simplifyTypedef85() { // ticket #2651
Expand Down Expand Up @@ -2444,7 +2444,7 @@ class TestSimplifyTypedef : public TestFixture {

void simplifyTypedef96() { // ticket #2886 (segmentation fault)
const char code[] = "typedef struct x { }";
ASSERT_THROW(tok(code), InternalError);
ASSERT_THROW_INTERNAL(tok(code), SYNTAX);
}

void simplifyTypedef97() { // ticket #2983 (segmentation fault)
Expand Down Expand Up @@ -2511,12 +2511,12 @@ class TestSimplifyTypedef : public TestFixture {

void simplifyTypedef105() { // ticket #3616 (segmentation fault)
const char code[] = "( int typedef char x; ){}";
ASSERT_THROW(tok(code), InternalError);
ASSERT_THROW_INTERNAL(tok(code), SYNTAX);
}

void simplifyTypedef106() { // ticket #3619 (segmentation fault)
const char code[] = "typedef void f ();\ntypedef { f }";
ASSERT_THROW(tok(code), InternalError);
ASSERT_THROW_INTERNAL(tok(code), INTERNAL);
}

void simplifyTypedef107() { // ticket #3963 (bad code => segmentation fault)
Expand Down
8 changes: 4 additions & 4 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3619,10 +3619,10 @@ class TestStl : public TestFixture {
ASSERT_EQUALS("", errout_str());

// #3714 - segmentation fault for syntax error
ASSERT_THROW(check("void f() {\n"
" if (()) { }\n"
"}"),
InternalError);
ASSERT_THROW_INTERNAL(check("void f() {\n"
" if (()) { }\n"
"}"),
AST);

// #3865
check("void f() {\n"
Expand Down
10 changes: 5 additions & 5 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3257,9 +3257,9 @@ class TestSymbolDatabase : public TestFixture {

void symboldatabase5() {
// ticket #2178 - segmentation fault
ASSERT_THROW(check("int CL_INLINE_DECL(integer_decode_float) (int x) {\n"
" return (sign ? cl_I() : 0);\n"
"}"), InternalError);
ASSERT_THROW_INTERNAL(check("int CL_INLINE_DECL(integer_decode_float) (int x) {\n"
" return (sign ? cl_I() : 0);\n"
"}"), UNKNOWN_MACRO);
}

void symboldatabase6() {
Expand Down Expand Up @@ -3360,7 +3360,7 @@ class TestSymbolDatabase : public TestFixture {

void symboldatabase14() {
// ticket #2589 - segmentation fault
ASSERT_THROW(check("struct B : A\n"), InternalError);
ASSERT_THROW_INTERNAL(check("struct B : A\n"), SYNTAX);
}

void symboldatabase17() {
Expand All @@ -3382,7 +3382,7 @@ class TestSymbolDatabase : public TestFixture {

void symboldatabase20() {
// ticket #3013 - segmentation fault
ASSERT_THROW(check("struct x : virtual y\n"), InternalError);
ASSERT_THROW_INTERNAL(check("struct x : virtual y\n"), SYNTAX);
}

void symboldatabase21() {
Expand Down
2 changes: 1 addition & 1 deletion test/testtoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ class TestToken : public TestFixture {
const SimpleTokenizer var(*this, "int a ; int b ;");

// Varid == 0 should throw exception
ASSERT_THROW((void)Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 0),InternalError);
ASSERT_THROW_INTERNAL((void)Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 0),INTERNAL);

ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 1));
ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %name% ; %type% %varid%", 2));
Expand Down
Loading

0 comments on commit e43037d

Please sign in to comment.