Skip to content

Commit 23552e0

Browse files
committed
Test the simplecpp portability reports and the macro usage arg in the dump
The simplecpp update reports PORTABILITY_BACKSLASH and PORTABILITY_NO_EOF_NEWLINE as portability messages and writes the argument of an integer constant macro call to <macro-usage>, with no test for either. portabilityReports checks both ids are reported with portability enabled and nothing without it. dumpMacroUsageArg checks arg= is written for INT64_C(5) and left out for other macros.
1 parent 69895d9 commit 23552e0

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎test/testpreprocessor.cpp‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ class TestPreprocessor : public TestFixture {
391391
TEST_CASE(pragmaAsm);
392392

393393
TEST_CASE(dumpPreprocessor);
394+
TEST_CASE(dumpMacroUsageArg);
395+
TEST_CASE(portabilityReports);
394396
}
395397

396398
template<size_t size>
@@ -3300,6 +3302,39 @@ class TestPreprocessor : public TestFixture {
33003302
" </simplecpp-if-cond>\n",
33013303
ostr.str());
33023304
}
3305+
void dumpMacroUsageArg() {
3306+
const char code[] = "#define INT64_C(x) x ## LL\n"
3307+
"#define F(x) x\n"
3308+
"INT64_C(5) + F(1);\n";
3309+
std::vector<std::string> files;
3310+
simplecpp::OutputList outputList;
3311+
simplecpp::TokenList tokens1(code, files, "test.cpp", {}, &outputList);
3312+
Preprocessor preprocessor(tokens1, settingsDefault, *this, Standards::Language::CPP);
3313+
(void)preprocessor.preprocess("", files, outputList);
3314+
(void)preprocessor.reportOutput(outputList, true);
3315+
3316+
std::ostringstream ostr;
3317+
preprocessor.dump(ostr);
3318+
ASSERT_EQUALS(
3319+
" <macro-usage>\n"
3320+
" <macro name=\"INT64_C\" file=\"test.cpp\" line=\"1\" column=\"9\" usefile=\"test.cpp\" useline=\"3\" usecolumn=\"1\" is-known-value=\"true\" arg=\"5\"/>\n"
3321+
" <macro name=\"F\" file=\"test.cpp\" line=\"2\" column=\"9\" usefile=\"test.cpp\" useline=\"3\" usecolumn=\"14\" is-known-value=\"true\"/>\n"
3322+
" </macro-usage>\n",
3323+
ostr.str());
3324+
}
3325+
3326+
void portabilityReports() {
3327+
const char code[] = "#define A 1 \\ \n"
3328+
"+ 2\n"
3329+
"int x = A;";
3330+
const Settings settings = settingsBuilder().severity(Severity::portability).build();
3331+
(void)getcode(settings, *this, code);
3332+
ASSERT_EQUALS("[file.c:1:13]: (portability) Combination 'backslash space newline' is not portable. [simplecppPortabilityBackslash]\n"
3333+
"[file.c:3:11]: (portability) No newline at end of file is undefined behavior in C. [simplecppPortabilityNoEofNewline]\n", errout_str());
3334+
3335+
(void)getcode(settingsDefault, *this, code);
3336+
ASSERT_EQUALS("", errout_str());
3337+
}
33033338
};
33043339

33053340
REGISTER_TEST(TestPreprocessor)

0 commit comments

Comments
 (0)