Skip to content

Commit fb35756

Browse files
TestLeakAutoVar: Split recursiveCountLimit test to separate class (#2995)
This test is by far the slowest one to run. Split it to a separate class to make it easy to select if it should be run during development.
1 parent e7bdf5f commit fb35756

2 files changed

Lines changed: 62 additions & 48 deletions

File tree

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ if (BUILD_TESTS)
172172
fixture_cost(TestIO 20)
173173
fixture_cost(cfg-std_c 8)
174174
fixture_cost(TestThreadExecutor 5)
175-
fixture_cost(TestLeakAutoVar 4)
175+
fixture_cost(TestLeakAutoVarRecursiveCountLimit 4)
176176
fixture_cost(TestTokenizer 4)
177177
endif()
178178
endif()

test/testleakautovar.cpp

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ class TestLeakAutoVar : public TestFixture {
188188

189189
TEST_CASE(smartPtrInContainer); // #8262
190190

191-
TEST_CASE(recursiveCountLimit); // #5872 #6157 #9097
192-
193191
TEST_CASE(functionCallCastConfig); // #9652
194192
}
195193

@@ -225,32 +223,6 @@ class TestLeakAutoVar : public TestFixture {
225223
c.runChecks(&tokenizer, &settings, this);
226224
}
227225

228-
void checkP(const char code[], bool cpp = false) {
229-
// Clear the error buffer..
230-
errout.str("");
231-
232-
// Raw tokens..
233-
std::vector<std::string> files(1, cpp?"test.cpp":"test.c");
234-
std::istringstream istr(code);
235-
const simplecpp::TokenList tokens1(istr, files, files[0]);
236-
237-
// Preprocess..
238-
simplecpp::TokenList tokens2(files);
239-
std::map<std::string, simplecpp::TokenList*> filedata;
240-
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
241-
242-
// Tokenizer..
243-
Tokenizer tokenizer(&settings, this);
244-
tokenizer.createTokens(std::move(tokens2));
245-
tokenizer.simplifyTokens1("");
246-
247-
// Check for leaks..
248-
CheckLeakAutoVar c;
249-
settings.checkLibrary = true;
250-
settings.addEnabled("information");
251-
c.runChecks(&tokenizer, &settings, this);
252-
}
253-
254226
void assign1() {
255227
check("void f() {\n"
256228
" char *p = malloc(10);\n"
@@ -2074,25 +2046,6 @@ class TestLeakAutoVar : public TestFixture {
20742046
ASSERT_EQUALS("", errout.str());
20752047
}
20762048

2077-
void recursiveCountLimit() { // #5872 #6157 #9097
2078-
ASSERT_THROW(checkP("#define ONE else if (0) { }\n"
2079-
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
2080-
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
2081-
"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n"
2082-
"void foo() {\n"
2083-
" if (0) { }\n"
2084-
" THOU THOU\n"
2085-
"}"), InternalError);
2086-
ASSERT_NO_THROW(checkP("#define ONE if (0) { }\n"
2087-
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
2088-
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
2089-
"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n"
2090-
"void foo() {\n"
2091-
" if (0) { }\n"
2092-
" THOU THOU\n"
2093-
"}"));
2094-
}
2095-
20962049
void functionCallCastConfig() { // #9652
20972050
Settings settingsFunctionCall = settings;
20982051

@@ -2122,6 +2075,67 @@ class TestLeakAutoVar : public TestFixture {
21222075

21232076
REGISTER_TEST(TestLeakAutoVar)
21242077

2078+
class TestLeakAutoVarRecursiveCountLimit : public TestFixture {
2079+
public:
2080+
TestLeakAutoVarRecursiveCountLimit() : TestFixture("TestLeakAutoVarRecursiveCountLimit") {
2081+
}
2082+
2083+
private:
2084+
Settings settings;
2085+
2086+
void checkP(const char code[], bool cpp = false) {
2087+
// Clear the error buffer..
2088+
errout.str("");
2089+
2090+
// Raw tokens..
2091+
std::vector<std::string> files(1, cpp?"test.cpp":"test.c");
2092+
std::istringstream istr(code);
2093+
const simplecpp::TokenList tokens1(istr, files, files[0]);
2094+
2095+
// Preprocess..
2096+
simplecpp::TokenList tokens2(files);
2097+
std::map<std::string, simplecpp::TokenList*> filedata;
2098+
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
2099+
2100+
// Tokenizer..
2101+
Tokenizer tokenizer(&settings, this);
2102+
tokenizer.createTokens(std::move(tokens2));
2103+
tokenizer.simplifyTokens1("");
2104+
2105+
// Check for leaks..
2106+
CheckLeakAutoVar c;
2107+
settings.checkLibrary = true;
2108+
settings.addEnabled("information");
2109+
c.runChecks(&tokenizer, &settings, this);
2110+
}
2111+
2112+
void run() OVERRIDE {
2113+
LOAD_LIB_2(settings.library, "std.cfg");
2114+
2115+
TEST_CASE(recursiveCountLimit); // #5872 #6157 #9097
2116+
}
2117+
2118+
void recursiveCountLimit() { // #5872 #6157 #9097
2119+
ASSERT_THROW(checkP("#define ONE else if (0) { }\n"
2120+
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
2121+
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
2122+
"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n"
2123+
"void foo() {\n"
2124+
" if (0) { }\n"
2125+
" THOU THOU\n"
2126+
"}"), InternalError);
2127+
ASSERT_NO_THROW(checkP("#define ONE if (0) { }\n"
2128+
"#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n"
2129+
"#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n"
2130+
"#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n"
2131+
"void foo() {\n"
2132+
" if (0) { }\n"
2133+
" THOU THOU\n"
2134+
"}"));
2135+
}
2136+
};
2137+
2138+
REGISTER_TEST(TestLeakAutoVarRecursiveCountLimit)
21252139

21262140
class TestLeakAutoVarStrcpy: public TestFixture {
21272141
public:

0 commit comments

Comments
 (0)