Skip to content

Commit 59a60fa

Browse files
committed
Add test
1 parent a4bd260 commit 59a60fa

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

test/testpreprocessor.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ class TestPreprocessor : public TestFixture {
281281

282282
// inline suppression, missingInclude/missingIncludeSystem
283283
TEST_CASE(inline_suppressions);
284+
TEST_CASE(inline_suppressions_not_next_line);
284285

285286
// remark comment
286287
TEST_CASE(remarkComment1);
@@ -2030,6 +2031,38 @@ class TestPreprocessor : public TestFixture {
20302031
ignore_errout(); // we are not interested in the output
20312032
}
20322033

2034+
void inline_suppressions_not_next_line() {
2035+
const auto settings = dinit(Settings,
2036+
$.inlineSuppressions = true,
2037+
$.checks.enable (Checks::missingInclude));
2038+
2039+
const char code[] = "// cppcheck-suppress missingInclude\n"
2040+
"// some other comment\n"
2041+
"#include \"missing.h\"\n"
2042+
"// cppcheck-suppress missingIncludeSystem\n"
2043+
"\n" // Empty line
2044+
"#include <missing2.h>\n";
2045+
SuppressionList inlineSuppr;
2046+
(void)getcodeforcfg(settings, *this, code, "", "test.c", &inlineSuppr);
2047+
2048+
auto suppressions = inlineSuppr.getSuppressions();
2049+
ASSERT_EQUALS(2, suppressions.size());
2050+
2051+
auto suppr = suppressions.front();
2052+
suppressions.pop_front();
2053+
ASSERT_EQUALS("missingInclude", suppr.errorId);
2054+
ASSERT_EQUALS("test.c", suppr.fileName);
2055+
ASSERT_EQUALS(3, suppr.lineNumber);
2056+
2057+
suppr = suppressions.front();
2058+
suppressions.pop_front();
2059+
ASSERT_EQUALS("missingIncludeSystem", suppr.errorId);
2060+
ASSERT_EQUALS("test.c", suppr.fileName);
2061+
ASSERT_EQUALS(6, suppr.lineNumber);
2062+
2063+
ignore_errout();
2064+
}
2065+
20332066
void remarkComment1() {
20342067
const char code[] = "// REMARK: assignment with 1\n"
20352068
"x=1;\n";

0 commit comments

Comments
 (0)