Skip to content

Commit

Permalink
testrunner: small ASSERT_THROW* cleanup (#6853)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored Oct 6, 2024
1 parent 58ad295 commit e2a4b19
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 65 deletions.
5 changes: 3 additions & 2 deletions test/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,9 @@ TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::library(const char l
if (REDUNDANT_CHECK && std::find(settings.libraries.cbegin(), settings.libraries.cend(), lib) != settings.libraries.cend())
throw std::runtime_error("redundant setting: libraries (" + std::string(lib) + ")");
// TODO: exename is not yet set
if (settings.library.load(fixture.exename.c_str(), lib).errorcode != Library::ErrorCode::OK)
throw std::runtime_error("library '" + std::string(lib) + "' not found");
const Library::ErrorCode lib_error = settings.library.load(fixture.exename.c_str(), lib).errorcode;
if (lib_error != Library::ErrorCode::OK)
throw std::runtime_error("loading library '" + std::string(lib) + "' failed - " + std::to_string(static_cast<int>(lib_error)));
// strip extension
std::string lib_s(lib);
const std::string ext(".cfg");
Expand Down
1 change: 0 additions & 1 deletion test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ class TestInstance {
#define ASSERT_EQUALS_MSG( EXPECTED, ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG)
#define ASSERT_EQUALS_ENUM( EXPECTED, ACTUAL ) assertEqualsEnum(__FILE__, __LINE__, (EXPECTED), (ACTUAL))
#define TODO_ASSERT_EQUALS_ENUM( WANTED, CURRENT, ACTUAL ) todoAssertEqualsEnum(__FILE__, __LINE__, WANTED, CURRENT, ACTUAL)
#define ASSERT_THROW( CMD, EXCEPTION ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) {} catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false)
#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 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 InternalError& e) { assertEqualsEnum(__FILE__, __LINE__, InternalError::TYPE, e.type); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false)
Expand Down
12 changes: 6 additions & 6 deletions test/testgarbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,12 @@ class TestGarbage : public TestFixture {

void garbageCode23() {
//garbage code : don't crash (#3481)
ASSERT_THROW_EQUALS(checkCode("{\n"
" if (1) = x\n"
" else abort s[2]\n"
"}"),
InternalError,
"syntax error");
ASSERT_THROW_INTERNAL_EQUALS(checkCode("{\n"
" if (1) = x\n"
" else abort s[2]\n"
"}"),
SYNTAX,
"syntax error");
}

void garbageCode24() {
Expand Down
9 changes: 8 additions & 1 deletion test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,14 @@ class TestSymbolDatabase : public TestFixture {
// three elements: varId 0 also counts via a fake-entry
ASSERT(v && db->variableList().size() == 3);

ASSERT_THROW(db->getVariableFromVarId(3), std::out_of_range);
// 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");
#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)");
#else
ASSERT_THROW_EQUALS_2(db->getVariableFromVarId(3), std::out_of_range, "vector");
#endif
}

void hasRegularFunction() {
Expand Down
110 changes: 55 additions & 55 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7135,19 +7135,19 @@ class TestTokenizer : public TestFixture {
ASSERT_NO_THROW(tokenizeAndStringify("enum { E = int{} };"));

ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("int a() { b((c)return 0) }"), SYNTAX, "syntax error");
ASSERT_THROW_EQUALS(tokenizeAndStringify("int f() { MACRO(x) return 0; }"),
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");

ASSERT_THROW_EQUALS(tokenizeAndStringify("void f(int i) {\n" // #11770
" if (i == 0) {}\n"
" else if (i == 1) {}\n"
" else\n"
" MACRO(i)\n"
"}\n"
"void g() {}\n"),
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");
ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("int f() { MACRO(x) return 0; }"),
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");

ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f(int i) {\n" // #11770
" if (i == 0) {}\n"
" else if (i == 1) {}\n"
" else\n"
" MACRO(i)\n"
"}\n"
"void g() {}\n"),
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");
ASSERT_NO_THROW(tokenizeAndStringify("void f(int i) {\n"
" if (i == 0) {}\n"
" else if (i == 1) {}\n"
Expand All @@ -7156,45 +7156,45 @@ class TestTokenizer : public TestFixture {
"}\n"
"void g() {}\n"));

ASSERT_THROW_EQUALS(tokenizeAndStringify("class C : public QObject {\n" // #11770
" struct S { static void g() {} };\n"
"private Q_SLOTS:\n"
" void f() { S::g(); }\n"
"};\n"),
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it.");
ASSERT_THROW_EQUALS(tokenizeAndStringify("class C : public QObject {\n"
" struct S { static void g() {} };\n"
"private slots:\n"
" void f() { S::g(); }\n"
"};\n"),
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.");

ASSERT_THROW_EQUALS(tokenizeAndStringify("namespace U_ICU_ENTRY_POINT_RENAME(icu) { }\n"
"namespace icu = U_ICU_ENTRY_POINT_RENAME(icu);\n"
"namespace U_ICU_ENTRY_POINT_RENAME(icu) {\n"
" class BreakIterator;\n"
"}\n"
"typedef int UStringCaseMapper(icu::BreakIterator* iter);\n"),
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If U_ICU_ENTRY_POINT_RENAME is a macro then please configure it.");

ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { MACRO(x(), y(), \"abc\", z(); ok = true); }\n"), // #12006
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");

ASSERT_THROW_EQUALS(tokenizeAndStringify("int (*f) MACRO((void *));\n"), // #12010
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");

ASSERT_THROW_EQUALS(tokenizeAndStringify("struct S { int a[2] PACKED; };\n"),
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If PACKED is a macro then please configure it.");

ASSERT_THROW_EQUALS(tokenizeAndStringify("MACRO(a, b,,)\n"),
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");
ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("class C : public QObject {\n" // #11770
" struct S { static void g() {} };\n"
"private Q_SLOTS:\n"
" void f() { S::g(); }\n"
"};\n"),
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it.");
ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("class C : public QObject {\n"
" struct S { static void g() {} };\n"
"private slots:\n"
" void f() { S::g(); }\n"
"};\n"),
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.");

ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("namespace U_ICU_ENTRY_POINT_RENAME(icu) { }\n"
"namespace icu = U_ICU_ENTRY_POINT_RENAME(icu);\n"
"namespace U_ICU_ENTRY_POINT_RENAME(icu) {\n"
" class BreakIterator;\n"
"}\n"
"typedef int UStringCaseMapper(icu::BreakIterator* iter);\n"),
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If U_ICU_ENTRY_POINT_RENAME is a macro then please configure it.");

ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f() { MACRO(x(), y(), \"abc\", z(); ok = true); }\n"), // #12006
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");

ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("int (*f) MACRO((void *));\n"), // #12010
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");

ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("struct S { int a[2] PACKED; };\n"),
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If PACKED is a macro then please configure it.");

ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("MACRO(a, b,,)\n"),
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");

ASSERT_THROW_INTERNAL(tokenizeAndStringify("{ for (()()) }"), SYNTAX); // #11643

Expand Down Expand Up @@ -7735,9 +7735,9 @@ class TestTokenizer : public TestFixture {
}

void checkConfiguration() {
ASSERT_THROW_EQUALS(checkConfig("void f() { DEBUG(x();y()); }"),
InternalError,
"There is an unknown macro here somewhere. Configuration is required. If DEBUG is a macro then please configure it.");
ASSERT_THROW_INTERNAL_EQUALS(checkConfig("void f() { DEBUG(x();y()); }"),
UNKNOWN_MACRO,
"There is an unknown macro here somewhere. Configuration is required. If DEBUG is a macro then please configure it.");
}

void unknownType() { // #8952
Expand Down

0 comments on commit e2a4b19

Please sign in to comment.