@@ -55,29 +55,30 @@ class TestPreprocessor : public TestFixture {
5555 std::vector<std::string> files;
5656 simplecpp::TokenList tokens1 = simplecpp::TokenList (code, files, " file.cpp" , &outputList);
5757 Preprocessor p (tokens1, settingsDefault, errorLogger, Path::identify (tokens1.getFiles ()[0 ], false ));
58+ ASSERT (p.loadFiles (files));
59+ simplecpp::TokenList tokens2 = p.preprocess (" " , files, outputList);
5860 (void )p.reportOutput (outputList, true );
59- simplecpp::OutputList outputList_pp;
60- simplecpp::TokenList tokens2 = p.preprocess (" " , files, outputList_pp);
61- (void )p.reportOutput (outputList_pp, true );
6261 return tokens2.stringify ();
6362 }
6463
6564 template <size_t size>
66- static void preprocess (const char (&code)[size], std::vector<std::string> &files, const std::string& file0, TokenList& tokenlist, const simplecpp::DUI& dui)
65+ void preprocess (const char (&code)[size], std::vector<std::string> &files, const std::string& file0, TokenList& tokenlist, const simplecpp::DUI& dui)
6766 {
6867 if (!files.empty ())
6968 throw std::runtime_error (" file list not empty" );
7069
7170 if (tokenlist.front ())
7271 throw std::runtime_error (" token list not empty" );
7372
74- const simplecpp::TokenList tokens1 (code, files, file0);
73+ simplecpp::OutputList outputList;
74+ const simplecpp::TokenList tokens1 (code, files, file0, &outputList);
7575
7676 // Preprocess..
7777 simplecpp::TokenList tokens2 (files);
7878 simplecpp::FileDataCache cache;
79- // TODO: provide and handle outputList
80- simplecpp::preprocess (tokens2, tokens1, files, cache, dui);
79+ simplecpp::preprocess (tokens2, tokens1, files, cache, dui, &outputList);
80+ Preprocessor preprocessor (tokens2, settingsDefault, *this , Standards::Language::C);
81+ (void )preprocessor.reportOutput (outputList, true );
8182
8283 // Tokenizer..
8384 tokenlist.createTokens (std::move (tokens2));
@@ -370,9 +371,12 @@ class TestPreprocessor : public TestFixture {
370371 if (library)
371372 ASSERT (settings.library .load (" " , library, false ).errorcode == Library::ErrorCode::OK);
372373 std::vector<std::string> files;
374+ simplecpp::OutputList outputList;
373375 // TODO: this adds an empty filename
374- simplecpp::TokenList tokens (code,files);
376+ simplecpp::TokenList tokens (code,files, " " ,&outputList );
375377 Preprocessor preprocessor (tokens, settings, *this , Standards::Language::C); // TODO: do we need to consider #file?
378+ ASSERT (preprocessor.loadFiles (files));
379+ ASSERT (!preprocessor.reportOutput (outputList, true ));
376380 preprocessor.removeComments ();
377381 const std::set<std::string> configs = preprocessor.getConfigs ();
378382 std::string ret;
@@ -385,8 +389,9 @@ class TestPreprocessor : public TestFixture {
385389 std::size_t getHash (const char (&code)[size]) {
386390 std::vector<std::string> files;
387391 // TODO: this adds an empty filename
388- simplecpp::TokenList tokens (code,files);
392+ simplecpp::TokenList tokens (code,files, " " );
389393 Preprocessor preprocessor (tokens, settingsDefault, *this , Standards::Language::C); // TODO: do we need to consider #file?
394+ ASSERT (preprocessor.loadFiles (files));
390395 preprocessor.removeComments ();
391396 return preprocessor.calculateHash (" " );
392397 }
@@ -2687,7 +2692,7 @@ class TestPreprocessor : public TestFixture {
26872692 ASSERT (getHash (code2) != getHash (code3));
26882693 }
26892694
2690- void standard () const {
2695+ void standard () {
26912696
26922697 const char code[] = " int a;" ;
26932698 // TODO: this bypasses the standard determined from the settings - the parameter should not be exposed
@@ -2729,7 +2734,8 @@ class TestPreprocessor : public TestFixture {
27292734 dui.std = " gnu77" ;
27302735 std::vector<std::string> files;
27312736 TokenList tokenlist{settingsDefault, Standards::Language::CPP};
2732- preprocess (code, files, " test.cpp" , tokenlist, dui);
2737+ // TODO: can this happen from application code? if yes we need to turn it into a proper error
2738+ ASSERT_THROW_EQUALS_2 (preprocess (code, files, " test.cpp" , tokenlist, dui), std::runtime_error, " unexpected simplecpp::Output type 9" );
27332739 ASSERT (!tokenlist.front ()); // nothing is tokenized when an unknown standard is provided
27342740 }
27352741 }
0 commit comments