diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 16cd2b59aa4..483e3973e5a 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,41 @@ 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); + // simplecpp emits these from an unordered_map, so their order differs between standard libraries + const std::string dump = ostr.str(); + std::size_t entries = 0; + for (std::string::size_type pos = dump.find("\n") != std::string::npos); + ASSERT(dump.find(" \n") != std::string::npos); + } + + 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)