Skip to content

Commit 2d0326d

Browse files
authored
testrunner: improved custom preprocessing implementations (danmar#8012)
1 parent e3dacd8 commit 2d0326d

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

test/helpers.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ ScopedFile::~ScopedFile() {
113113

114114
void SimpleTokenizer2::preprocess(const char* code, std::size_t size, std::vector<std::string> &files, const std::string& file0, Tokenizer& tokenizer, ErrorLogger& errorlogger)
115115
{
116-
simplecpp::TokenList tokens1(code, size, files, file0);
116+
simplecpp::OutputList outputList;
117+
simplecpp::TokenList tokens1(code, size, files, file0, &outputList);
117118

118119
Preprocessor preprocessor(tokens1, tokenizer.getSettings(), errorlogger, Path::identify(tokens1.getFiles()[0], false));
119-
simplecpp::OutputList outputList;
120+
(void)preprocessor.loadFiles(files); // TODO: check result
120121
simplecpp::TokenList tokens2 = preprocessor.preprocess("", files, outputList);
121122
(void)preprocessor.reportOutput(outputList, true);
122123

test/testpreprocessor.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

test/testtokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,8 @@ class TestTokenizer : public TestFixture {
599599
std::vector<std::string> files;
600600
simplecpp::TokenList tokens1(code, files, filename, &outputList);
601601
Preprocessor preprocessor(tokens1, settings, *this, Path::identify(tokens1.getFiles()[0], false));
602+
(void)preprocessor.reportOutput(outputList, true);
603+
ASSERT(preprocessor.loadFiles(files));
602604
std::list<Directive> directives = preprocessor.createDirectives();
603605

604606
TokenList tokenlist{settings, Path::identify(filename, false)};

0 commit comments

Comments
 (0)