Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class TestPreprocessor : public TestFixture {
if (inlineSuppression)
preprocessor.inlineSuppressions(*inlineSuppression);
preprocessor.removeComments();
preprocessor.reportSimplecppPortability(outputList);
preprocessor.simplifyPragmaAsm();

std::map<std::string, std::string> cfgcode;
Expand Down Expand Up @@ -391,6 +392,8 @@ class TestPreprocessor : public TestFixture {
TEST_CASE(pragmaAsm);

TEST_CASE(dumpPreprocessor);
TEST_CASE(dumpMacroUsageArg);
TEST_CASE(portabilityReports);
}

template<size_t size>
Expand Down Expand Up @@ -3300,6 +3303,39 @@ class TestPreprocessor : public TestFixture {
" </simplecpp-if-cond>\n",
ostr.str());
}
void dumpMacroUsageArg() {
const char code[] = "#define INT64_C(x) x ## LL\n"
"#define F(x) x\n"
"INT64_C(5) + F(1);\n";
std::vector<std::string> files;
simplecpp::OutputList outputList;
simplecpp::TokenList tokens1(code, files, "test.cpp", {}, &outputList);
Preprocessor preprocessor(tokens1, settingsDefault, *this, Standards::Language::CPP);
(void)preprocessor.preprocess("", files, outputList);
(void)preprocessor.reportOutput(outputList, true);

std::ostringstream ostr;
preprocessor.dump(ostr);
ASSERT_EQUALS(
" <macro-usage>\n"
" <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"
" <macro name=\"F\" file=\"test.cpp\" line=\"2\" column=\"9\" usefile=\"test.cpp\" useline=\"3\" usecolumn=\"14\" is-known-value=\"true\"/>\n"
" </macro-usage>\n",
ostr.str());
}

void portabilityReports() {
const char code[] = "#define A 1 \\ \n"
"+ 2\n"
"int x = A;";
const Settings settings = settingsBuilder().severity(Severity::portability).build();
(void)getcode(settings, *this, code);
ASSERT_EQUALS("[file.c:1:13]: (portability) Combination 'backslash space newline' is not portable. [simplecppPortabilityBackslash]\n"
"[file.c:3:11]: (portability) No newline at end of file is undefined behavior in C. [simplecppPortabilityNoEofNewline]\n", errout_str());

(void)getcode(settingsDefault, *this, code);
ASSERT_EQUALS("", errout_str());
}
};

REGISTER_TEST(TestPreprocessor)