From fe89cd1fb534a76b24d73018eb184757d126c216 Mon Sep 17 00:00:00 2001 From: Jay Beavers Date: Sat, 21 Nov 2026 05:57:34 -0800 Subject: [PATCH] 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 , 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. getcode() now calls reportSimplecppPortability() after removeComments(), as CppCheck::checkInternal does, so the main file's portability messages reach the test logger. --- test/testpreprocessor.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 16cd2b59aa4..f9df3f42c2c 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -136,6 +136,7 @@ class TestPreprocessor : public TestFixture { if (inlineSuppression) preprocessor.inlineSuppressions(*inlineSuppression); preprocessor.removeComments(); + preprocessor.reportSimplecppPortability(outputList); preprocessor.simplifyPragmaAsm(); std::map cfgcode; @@ -391,6 +392,8 @@ class TestPreprocessor : public TestFixture { TEST_CASE(pragmaAsm); TEST_CASE(dumpPreprocessor); + TEST_CASE(dumpMacroUsageArg); + TEST_CASE(portabilityReports); } template @@ -3300,6 +3303,39 @@ class TestPreprocessor : public TestFixture { " \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 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( + " \n" + " \n" + " \n" + " \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)