Skip to content

Commit

Permalink
unit-testsuites.cpp: fix hangup if file not found
Browse files Browse the repository at this point in the history
If run from the wrong directory, std::ifstream f("test/data/big-list-of-naughty-strings/blns.json"); will not find the file and thus f.eof() will never return true.
Use canonical C++ file reading loop from https://gehrcke.de/2011/06/reading-files-in-c-using-ifstream-dealing-correctly-with-badbit-failbit-eofbit-and-perror/ instead.
  • Loading branch information
knilch0r authored Sep 28, 2018
1 parent 680a4ab commit 8c1387c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions test/src/unit-testsuites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,13 +1346,11 @@ TEST_CASE("Big List of Naughty Strings")
SECTION("roundtripping")
{
std::ifstream f("test/data/big-list-of-naughty-strings/blns.json");
std::string line;

while (not f.eof())
// read lines one by one, bail out on error or eof
while (getline(f, line))
{
// read line
std::string line;
getline(f, line);

// trim whitespace
line = trim(line);

Expand Down

0 comments on commit 8c1387c

Please sign in to comment.