Skip to content

Commit 4cbbca3

Browse files
orbitcowboyPKEuS
authored andcommitted
Refactoring: Avoid to load posix.cfg multiple times while testing (testother.cpp) (cppcheck-opensource#6336)
1 parent a1537e1 commit 4cbbca3

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

‎test/testother.cpp‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ class TestOther : public TestFixture {
3434

3535
private:
3636
Settings settings_std;
37+
Settings settings_posix;
3738

3839
void run() {
3940
LOAD_LIB_2(settings_std.library, "std.cfg");
41+
LOAD_LIB_2(settings_posix.library, "posix.cfg");
4042

4143
TEST_CASE(emptyBrackets);
4244

@@ -183,6 +185,9 @@ class TestOther : public TestFixture {
183185
static Settings _settings;
184186
settings = &_settings;
185187
}
188+
if (posix) {
189+
settings = &settings_posix;
190+
}
186191
settings->addEnabled("style");
187192
settings->addEnabled("warning");
188193
settings->addEnabled("portability");
@@ -191,16 +196,6 @@ class TestOther : public TestFixture {
191196
settings->experimental = experimental;
192197
settings->standards.posix = posix;
193198

194-
if (posix) {
195-
const char cfg[] = "<?xml version=\"1.0\"?>\n"
196-
"<def>\n"
197-
" <function name=\"usleep\"> <arg nr=\"1\"><valid>0:999999</valid></arg> </function>\n"
198-
"</def>";
199-
tinyxml2::XMLDocument xmldoc;
200-
xmldoc.Parse(cfg, sizeof(cfg));
201-
settings->library.load(xmldoc);
202-
}
203-
204199
// Tokenize..
205200
Tokenizer tokenizer(settings, this);
206201
std::istringstream istr(code);
@@ -6369,18 +6364,14 @@ class TestOther : public TestFixture {
63696364
}
63706365

63716366
void testReturnIgnoredReturnValuePosix() {
6372-
Settings settings_posix;
6373-
LOAD_LIB_2(settings_posix.library, "posix.cfg");
6374-
63756367
check("void f() {\n"
63766368
" strdupa(\"test\");\n"
63776369
"}",
63786370
"test.cpp",
63796371
false, // experimental
63806372
false, // inconclusive
63816373
true, // posix
6382-
false, // runSimpleChecks
6383-
&settings_posix
6374+
false // runSimpleChecks
63846375
);
63856376
ASSERT_EQUALS("[test.cpp:2]: (warning) Return value of function strdupa() is not used.\n", errout.str());
63866377

@@ -6394,8 +6385,7 @@ class TestOther : public TestFixture {
63946385
false, // experimental
63956386
false, // inconclusive
63966387
true, // posix
6397-
false, // runSimpleChecks
6398-
&settings_posix
6388+
false // runSimpleChecks
63996389
);
64006390
ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function mmap() is not used.\n", errout.str());
64016391
}

0 commit comments

Comments
 (0)