@@ -140,7 +140,7 @@ class TestPreprocessor : public TestFixture {
140140 cfgs = preprocessor.getConfigs ();
141141 for (const std::string & config : cfgs) {
142142 try {
143- const bool writeLocations = (strstr (code, " #file " ) != nullptr ) || ( strstr (code, " # include" ) != nullptr );
143+ const bool writeLocations = (strstr (code, " #include" ) != nullptr );
144144 cfgcode[config] = preprocessor.getcode (config, files, writeLocations);
145145 } catch (const simplecpp::Output &) {
146146 cfgcode[config] = " " ;
@@ -390,7 +390,7 @@ class TestPreprocessor : public TestFixture {
390390 std::vector<std::string> files;
391391 simplecpp::OutputList outputList;
392392 simplecpp::TokenList tokens (code,files," test.c" ,&outputList);
393- Preprocessor preprocessor (tokens, settings, *this , Standards::Language::C); // TODO: do we need to consider #file?
393+ Preprocessor preprocessor (tokens, settings, *this , Standards::Language::C);
394394 ASSERT (preprocessor.loadFiles (files));
395395 ASSERT (!preprocessor.reportOutput (outputList, true ));
396396 preprocessor.removeComments ();
@@ -405,7 +405,7 @@ class TestPreprocessor : public TestFixture {
405405 std::size_t getHash (const char (&code)[size]) {
406406 std::vector<std::string> files;
407407 simplecpp::TokenList tokens (code,files," test.c" );
408- Preprocessor preprocessor (tokens, settingsDefault, *this , Standards::Language::C); // TODO: do we need to consider #file?
408+ Preprocessor preprocessor (tokens, settingsDefault, *this , Standards::Language::C);
409409 ASSERT (preprocessor.loadFiles (files));
410410 preprocessor.removeComments ();
411411 return preprocessor.calculateHash (" " );
@@ -470,16 +470,19 @@ class TestPreprocessor : public TestFixture {
470470 void error4 () {
471471 // In included file
472472 {
473+ ScopedFile header (" ab.h" , " #error hello world!\n " );
473474 const auto settings = dinit (Settings, $.userDefines = " TEST" );
474- const char code[] = " #file \" ab.h\"\n #error hello world! \n #endfile " ;
475+ const char code[] = " #include \" ab.h\" " ;
475476 (void )getcodeforcfg (settings, *this , code, " TEST" , " test.c" );
476477 ASSERT_EQUALS (" [ab.h:1:2]: (error) #error hello world! [preprocessorErrorDirective]\n " , errout_str ());
477478 }
478479
479480 // After including a file
480481 {
482+ ScopedFile header (" ab.h" , " " );
481483 const auto settings = dinit (Settings, $.userDefines = " TEST" );
482- const char code[] = " #file \" ab.h\"\n\n #endfile\n #error aaa" ;
484+ const char code[] = " #include \" ab.h\"\n "
485+ " #error aaa" ;
483486 (void )getcodeforcfg (settings, *this , code, " TEST" , " test.c" );
484487 ASSERT_EQUALS (" [test.c:2:2]: (error) #error aaa [preprocessorErrorDirective]\n " , errout_str ());
485488 }
@@ -582,35 +585,35 @@ class TestPreprocessor : public TestFixture {
582585 }
583586
584587 void includeguard1 () {
588+ ScopedFile header (" abc.h" ,
589+ " #ifndef abcH\n "
590+ " #define abcH\n "
591+ " #endif\n " );
585592 // Handling include guards..
586- const char filedata[] = " #file \" abc.h\"\n "
587- " #ifndef abcH\n "
588- " #define abcH\n "
589- " #endif\n "
590- " #endfile\n "
593+ const char filedata[] = " #include \" abc.h\"\n "
591594 " #ifdef ABC\n "
592595 " #endif" ;
593596 ASSERT_EQUALS (" \n ABC=ABC\n " , getConfigsStr (filedata));
594597 }
595598
596599 void includeguard2 () {
600+ ScopedFile header (" abc.h" ,
601+ " foo\n "
602+ " #ifdef ABC\n "
603+ " \n "
604+ " #endif\n " );
597605 // Handling include guards..
598- const char filedata[] = " #file \" abc.h\"\n "
599- " foo\n "
600- " #ifdef ABC\n "
601- " \n "
602- " #endif\n "
603- " #endfile\n " ;
606+ const char filedata[] = " #include \" abc.h\"\n " ;
604607 ASSERT_EQUALS (" \n ABC=ABC\n " , getConfigsStr (filedata));
605608 }
606609
607610
608611 void ifdefwithfile () {
612+ ScopedFile header (" abc.h" , " class A{};/*\n\n\n\n\n\n\n */\n " );
613+
609614 // Handling include guards..
610615 const char filedata[] = " #ifdef ABC\n "
611- " #file \" abc.h\"\n "
612- " class A{};/*\n\n\n\n\n\n\n */\n "
613- " #endfile\n "
616+ " #include \" abc.h\"\n "
614617 " #endif\n "
615618 " int main() {}\n " ;
616619
@@ -1574,10 +1577,10 @@ class TestPreprocessor : public TestFixture {
15741577 }
15751578
15761579 {
1577- const char filedata[] = " #file \" abc.h\"\n "
1578- " #define a\n "
1579- " \"\n "
1580- " #endfile \n " ;
1580+ ScopedFile header ( " abc.h" ,
1581+ " #define a\n "
1582+ " \"\n " );
1583+ const char filedata[] = " #include \" abc.h \" " ;
15811584
15821585 // expand macros..
15831586 const std::string actual (expandMacros (filedata, *this ));
@@ -1587,9 +1590,9 @@ class TestPreprocessor : public TestFixture {
15871590 }
15881591
15891592 {
1590- const char filedata[] = " #file \" abc.h\"\n "
1591- " #define a\n "
1592- " #endfile \n "
1593+ ScopedFile header ( " abc.h" ,
1594+ " #define a\n " );
1595+ const char filedata[] = " #include \" abc.h \" \n"
15931596 " \"\n " ;
15941597
15951598 // expand macros..
@@ -2284,14 +2287,14 @@ class TestPreprocessor : public TestFixture {
22842287 }
22852288
22862289 void getConfigs7e () {
2290+ ScopedFile header (" test.h" ,
2291+ " #ifndef test_h\n "
2292+ " #define test_h\n "
2293+ " #ifdef ABC\n "
2294+ " #endif\n "
2295+ " #endif\n " );
22872296 const char filedata[] = " #ifdef ABC\n "
2288- " #file \" test.h\"\n "
2289- " #ifndef test_h\n "
2290- " #define test_h\n "
2291- " #ifdef ABC\n "
2292- " #endif\n "
2293- " #endif\n "
2294- " #endfile\n "
2297+ " #include \" test.h\"\n "
22952298 " #endif\n " ;
22962299 ASSERT_EQUALS (" \n ABC=ABC\n " , getConfigsStr (filedata));
22972300 }
@@ -2313,12 +2316,12 @@ class TestPreprocessor : public TestFixture {
23132316 }
23142317
23152318 void getConfigs11 () { // #9832 - include guards
2316- const char filedata[] = " #file \" test.h\"\n "
2317- " #if !defined(test_h)\n "
2318- " #define test_h\n "
2319- " 123\n "
2320- " #endif\n "
2321- " #endfile \n " ;
2319+ ScopedFile header ( " test.h" ,
2320+ " #if !defined(test_h)\n "
2321+ " #define test_h\n "
2322+ " 123\n "
2323+ " #endif\n " );
2324+ const char filedata[] = " #include \" test.h \" \n" ;
23222325 ASSERT_EQUALS (" \n " , getConfigsStr (filedata));
23232326 }
23242327
0 commit comments