@@ -4504,6 +4504,45 @@ static void include11() // #669 - -include with preprocess()
45044504 ASSERT_EQUALS (" Can not open include file 'missing.h' that is explicitly included." , outputList.begin ()->msg );
45054505}
45064506
4507+ static void include12 () // #769 - No "No newline at end of file" warning in C++ header
4508+ {
4509+ const std::string header = " testrunner_769.h" ;
4510+ {
4511+ std::ofstream f (header, std::ios::binary);
4512+ f << " int x;" ; // <- no newline at end of file
4513+ }
4514+
4515+ const char code_c[] = " #include \" testrunner_769.h\"\n " ;
4516+
4517+ {
4518+ std::vector<std::string> files;
4519+ const simplecpp::TokenList rawtokens = makeTokenList (code_c, files, " 769.cpp" );
4520+ simplecpp::FileDataCache cache;
4521+ simplecpp::TokenList out (files);
4522+ simplecpp::OutputList outputList;
4523+ simplecpp::DUI dui;
4524+ dui.std = " c++11" ;
4525+ simplecpp::preprocess (out, rawtokens, files, cache, dui, &outputList);
4526+ simplecpp::cleanup (cache);
4527+ ASSERT_EQUALS (" " , toString (outputList));
4528+ }
4529+
4530+ {
4531+ std::vector<std::string> files;
4532+ const simplecpp::TokenList rawtokens = makeTokenList (code_c, files, " 769.c" );
4533+ simplecpp::FileDataCache cache;
4534+ simplecpp::TokenList out (files);
4535+ simplecpp::OutputList outputList;
4536+ simplecpp::DUI dui;
4537+ dui.std = " c11" ;
4538+ simplecpp::preprocess (out, rawtokens, files, cache, dui, &outputList);
4539+ simplecpp::cleanup (cache);
4540+ ASSERT_EQUALS (" file1,1,portability_no_eof_newline,No newline at end of file is undefined behavior in C.\n " , toString (outputList));
4541+ }
4542+
4543+ std::remove (header.c_str ());
4544+ }
4545+
45074546static void readfile_nullbyte ()
45084547{
45094548 const char code[] = " ab\0 cd\n " ;
@@ -6104,6 +6143,7 @@ static void runTests(int argc, char **argv, Input input)
61046143 TEST_CASE (include9); // #include MACRO
61056144 TEST_CASE (include10); // -include with load()
61066145 TEST_CASE (include11); // -include with preprocess()
6146+ TEST_CASE (include12); // #769
61076147
61086148 TEST_CASE (multiline1);
61096149 TEST_CASE (multiline2);
0 commit comments