Skip to content

Commit

Permalink
test.cpp: run tests with filename input
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Mar 3, 2023
1 parent 16f2269 commit 4acb91b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

enum Input {
Stringstream,
Fstream
Fstream,
File
};

static Input USE_INPUT = Stringstream;
Expand All @@ -51,6 +52,8 @@ static const char* inputString(Input input) {
return "Stringstream";
case Fstream:
return "Fstream";
case File:
return "File";
}
}

Expand Down Expand Up @@ -111,6 +114,14 @@ static simplecpp::TokenList makeTokenListFromFstream(const char code[], std::siz
return tokenList;
}

static simplecpp::TokenList makeTokenListFromFile(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename, simplecpp::OutputList *outputList)
{
const std::string tmpfile = writeFile(code, size, filename);
simplecpp::TokenList tokenList(tmpfile, filenames, outputList);
remove(tmpfile.c_str());
return tokenList;
}

static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
{
switch (USE_INPUT) {
Expand All @@ -120,6 +131,8 @@ static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, s
}
case Fstream:
return makeTokenListFromFstream(code, size, filenames, filename, outputList);
case File:
return makeTokenListFromFile(code, size, filenames, filename, outputList);
}
}

Expand Down Expand Up @@ -2802,5 +2815,6 @@ int main(int argc, char **argv)
{
runTests(argc, argv, Stringstream);
runTests(argc, argv, Fstream);
runTests(argc, argv, File);
return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}

0 comments on commit 4acb91b

Please sign in to comment.