Skip to content

Commit 20ec65b

Browse files
committed
TestFixture: immediately bail out when library could not be loaded
1 parent 7ce82e4 commit 20ec65b

2 files changed

Lines changed: 1 addition & 20 deletions

File tree

test/fixture.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ unsigned int TestFixture::countTests;
7575
std::size_t TestFixture::fails_counter = 0;
7676
std::size_t TestFixture::todos_counter = 0;
7777
std::size_t TestFixture::succeeded_todos_counter = 0;
78-
std::set<std::string> TestFixture::missingLibs;
7978

8079
TestFixture::TestFixture(const char * const _name)
8180
: mVerbose(false),
@@ -285,11 +284,6 @@ void TestFixture::assertNoThrowFail(const char * const filename, const unsigned
285284

286285
}
287286

288-
void TestFixture::complainMissingLib(const char * const libname)
289-
{
290-
missingLibs.insert(libname);
291-
}
292-
293287
void TestFixture::printHelp()
294288
{
295289
std::cout << "Testrunner - run Cppcheck tests\n"
@@ -373,12 +367,6 @@ std::size_t TestFixture::runTests(const options& args)
373367
std::cerr << "Tests failed: " << fails_counter << std::endl << std::endl;
374368
std::cerr << errmsg.str();
375369

376-
if (!missingLibs.empty()) {
377-
std::cerr << "Missing libraries: ";
378-
for (const std::string & missingLib : missingLibs)
379-
std::cerr << missingLib << " ";
380-
std::cerr << std::endl << std::endl;
381-
}
382370
std::cerr.flush();
383371
return fails_counter;
384372
}

test/fixture.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class TestFixture : public ErrorLogger {
4343
static std::size_t fails_counter;
4444
static std::size_t todos_counter;
4545
static std::size_t succeeded_todos_counter;
46-
static std::set<std::string> missingLibs;
4746
bool mVerbose;
4847
std::string mTemplateFormat;
4948
std::string mTemplateLocation;
@@ -95,7 +94,6 @@ class TestFixture : public ErrorLogger {
9594
void assertThrow(const char * const filename, const unsigned int linenr) const;
9695
void assertThrowFail(const char * const filename, const unsigned int linenr) const;
9796
void assertNoThrowFail(const char * const filename, const unsigned int linenr) const;
98-
static void complainMissingLib(const char * const libname);
9997
static std::string deleteLineNumber(const std::string &message);
10098

10199
void setVerbose(bool v) {
@@ -164,12 +162,7 @@ extern std::ostringstream output;
164162
#define EXPECT_EQ( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
165163
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance_ ## CLASSNAME; }
166164

167-
#define LOAD_LIB_2( LIB, NAME ) do { \
168-
if (((LIB).load(exename.c_str(), NAME).errorcode != Library::ErrorCode::OK)) { \
169-
complainMissingLib(NAME); \
170-
return; \
171-
} \
172-
} while (false)
165+
#define LOAD_LIB_2( LIB, NAME ) do { if (((LIB).load(exename.c_str(), NAME).errorcode != Library::ErrorCode::OK)) throw std::runtime_error("library '" + std::string(NAME) + "' not found"); } while (false)
173166

174167
#define PLATFORM( P, T ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, P.set(cppcheck::Platform::toString(T), errstr, {exename}), errstr); } while (false)
175168

0 commit comments

Comments
 (0)