From 8c1387cfb3229634b731f3abb2d746052a62ca50 Mon Sep 17 00:00:00 2001 From: knilch Date: Fri, 28 Sep 2018 11:33:23 +0200 Subject: [PATCH] unit-testsuites.cpp: fix hangup if file not found 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. --- test/src/unit-testsuites.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/src/unit-testsuites.cpp b/test/src/unit-testsuites.cpp index 908901ab31..5767ebce13 100644 --- a/test/src/unit-testsuites.cpp +++ b/test/src/unit-testsuites.cpp @@ -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);