diff options
author | Dennis van der Schagt <dennisschagt@gmail.com> | 2024-07-15 21:30:43 +0200 |
---|---|---|
committer | Alexander Batischev <eual.jp@gmail.com> | 2024-10-01 19:15:18 +0300 |
commit | d0306662f210bc38ebc8ecf1d701dad291a4bc06 (patch) | |
tree | 902db3278f75b7ef22e5b4fda0c933f43cbe1068 | |
parent | 342a75f3c1a57c9488a0c34aae3b81873d389d6d (diff) |
Remove implicit Filepath conversions from a few miscelaneous files
-rw-r--r-- | src/configcontainer.cpp | 4 | ||||
-rw-r--r-- | test/colormanager.cpp | 4 | ||||
-rw-r--r-- | test/configcontainer.cpp | 7 | ||||
-rw-r--r-- | test/configparser.cpp | 36 | ||||
-rw-r--r-- | test/opmlurlreader.cpp | 16 | ||||
-rw-r--r-- | test/rssfeed.cpp | 2 | ||||
-rw-r--r-- | test/scopemeasure.cpp | 10 | ||||
-rw-r--r-- | test/test_helpers/loggerresetter.cpp | 2 |
8 files changed, 37 insertions, 44 deletions
diff --git a/src/configcontainer.cpp b/src/configcontainer.cpp index 3b460d8e..0c2a6c42 100644 --- a/src/configcontainer.cpp +++ b/src/configcontainer.cpp @@ -1,5 +1,3 @@ -#define ENABLE_IMPLICIT_FILEPATH_CONVERSIONS - #include "configcontainer.h" #include <algorithm> @@ -422,7 +420,7 @@ std::string ConfigContainer::get_configvalue(const std::string& key) const const auto& entry = it->second; std::string value = entry.value(); if (entry.type() == ConfigDataType::PATH) { - value = utils::resolve_tilde(value); + value = utils::resolve_tilde(Filepath::from_locale_string(value)).to_locale_string(); } return value; } diff --git a/test/colormanager.cpp b/test/colormanager.cpp index f6c47f5c..8e769db7 100644 --- a/test/colormanager.cpp +++ b/test/colormanager.cpp @@ -1,5 +1,3 @@ -#define ENABLE_IMPLICIT_FILEPATH_CONVERSIONS - #include "colormanager.h" #include <string> @@ -110,7 +108,7 @@ TEST_CASE("register_commands() registers ColorManager with ConfigParser", clr.apply_colors(collector.setter()); REQUIRE(collector.styles_count() == 0); - cfg.parse_file("data/config-with-colors"); + cfg.parse_file(Filepath::from_locale_string("data/config-with-colors")); clr.apply_colors(collector.setter()); REQUIRE(collector.styles_count() == 2); diff --git a/test/configcontainer.cpp b/test/configcontainer.cpp index c1015fbc..70734692 100644 --- a/test/configcontainer.cpp +++ b/test/configcontainer.cpp @@ -1,5 +1,3 @@ -#define ENABLE_IMPLICIT_FILEPATH_CONVERSIONS - #include "configcontainer.h" #include <unordered_set> @@ -20,7 +18,8 @@ TEST_CASE("Parses test config without exceptions", "[ConfigContainer]") KeyMap k(KM_NEWSBOAT); cfgparser.register_handler("macro", k); - REQUIRE_NOTHROW(cfgparser.parse_file("data/test-config.txt")); + REQUIRE_NOTHROW(cfgparser.parse_file( + Filepath::from_locale_string("data/test-config.txt"))); SECTION("bool value") { REQUIRE(cfg.get_configvalue("show-read-feeds") == "no"); @@ -54,7 +53,7 @@ TEST_CASE( cfg.register_commands(cfgparser); REQUIRE_NOTHROW(cfgparser.parse_file( - "data/test-config-without-newline-at-the-end.txt")); + Filepath::from_locale_string("data/test-config-without-newline-at-the-end.txt"))); SECTION("first line") { REQUIRE(cfg.get_configvalue("browser") == "firefox"); diff --git a/test/configparser.cpp b/test/configparser.cpp index 65efbd63..78faac58 100644 --- a/test/configparser.cpp +++ b/test/configparser.cpp @@ -1,5 +1,3 @@ -#define ENABLE_IMPLICIT_FILEPATH_CONVERSIONS - #include "configparser.h" #include <fstream> @@ -184,7 +182,8 @@ TEST_CASE("evaluate_backticks replaces command in backticks with its output", ConfigParser cfgparser; KeyMap keys(KM_NEWSBOAT); cfgparser.register_handler("bind-key", keys); - REQUIRE_NOTHROW(cfgparser.parse_file("data/config-space-backticks")); + REQUIRE_NOTHROW(cfgparser.parse_file( + Filepath::from_locale_string("data/config-space-backticks"))); REQUIRE(keys.get_operation(KeyCombination("s"), "feedlist") == OP_SORT); } @@ -222,7 +221,7 @@ TEST_CASE("\"unbind-key -a\" removes all key bindings", "[ConfigParser]") SECTION("In all contexts by default") { KeyMap keys(KM_NEWSBOAT); cfgparser.register_handler("unbind-key", keys); - cfgparser.parse_file("data/config-unbind-all"); + cfgparser.parse_file(Filepath::from_locale_string("data/config-unbind-all")); for (int i = OP_QUIT; i < OP_NB_MAX; ++i) { REQUIRE(keys.get_keys(static_cast<Operation>(i), @@ -235,7 +234,7 @@ TEST_CASE("\"unbind-key -a\" removes all key bindings", "[ConfigParser]") SECTION("For a specific context") { KeyMap keys(KM_NEWSBOAT); cfgparser.register_handler("unbind-key", keys); - cfgparser.parse_file("data/config-unbind-all-context"); + cfgparser.parse_file(Filepath::from_locale_string("data/config-unbind-all-context")); INFO("it doesn't affect the help dialog"); KeyMap default_keys(KM_NEWSBOAT); @@ -256,7 +255,8 @@ TEST_CASE("Concatenates lines that end with a backslash", "[ConfigParser]") ConfigParser cfgparser; KeyMap k(KM_NEWSBOAT); cfgparser.register_handler("macro", k); - REQUIRE_NOTHROW(cfgparser.parse_file("data/config-multi-line")); + REQUIRE_NOTHROW(cfgparser.parse_file( + Filepath::from_locale_string("data/config-multi-line"))); auto p_macro = k.get_macro(KeyCombination("p")); REQUIRE(!p_macro.empty()); REQUIRE(p_macro[0].op == newsboat::OP_OPEN); @@ -277,40 +277,46 @@ TEST_CASE("`include` directive includes other config files", "[ConfigParser]") // TODO: error messages should be more descriptive than "file couldn't be opened" ConfigParser cfgparser; SECTION("Errors if file is not found") { - REQUIRE_THROWS_AS(cfgparser.parse_file("data/config-missing-include"), + REQUIRE_THROWS_AS(cfgparser.parse_file( + Filepath::from_locale_string("data/config-missing-include")), ConfigException); } SECTION("Errors on invalid UTF-8 in file") { - REQUIRE_THROWS_AS(cfgparser.parse_file("data/config-invalid-utf-8"), + REQUIRE_THROWS_AS(cfgparser.parse_file( + Filepath::from_locale_string("data/config-invalid-utf-8")), ConfigException); } SECTION("Terminates on recursive include") { - REQUIRE_THROWS_AS(cfgparser.parse_file("data/config-recursive-include"), + REQUIRE_THROWS_AS(cfgparser.parse_file( + Filepath::from_locale_string("data/config-recursive-include")), ConfigException); } SECTION("Successfully includes existing file") { - REQUIRE_NOTHROW(cfgparser.parse_file("data/config-absolute-include")); + REQUIRE_NOTHROW(cfgparser.parse_file( + Filepath::from_locale_string("data/config-absolute-include"))); } SECTION("Success on relative includes") { - REQUIRE_NOTHROW(cfgparser.parse_file("data/config-relative-include")); + REQUIRE_NOTHROW(cfgparser.parse_file( + Filepath::from_locale_string("data/config-relative-include"))); } SECTION("Diamond of death includes pass") { - REQUIRE_NOTHROW(cfgparser.parse_file("data/diamond-of-death/A")); + REQUIRE_NOTHROW(cfgparser.parse_file( + Filepath::from_locale_string("data/diamond-of-death/A"))); } SECTION("File including itself only gets evaluated once") { test_helpers::TempFile testfile; test_helpers::EnvVar tmpfile("TMPFILE"); // $TMPFILE used in conf file - tmpfile.set(testfile.get_path()); + tmpfile.set(testfile.get_path().to_locale_string()); // recursive includes don't fail REQUIRE_NOTHROW( - cfgparser.parse_file("data/recursive-include-side-effect")); + cfgparser.parse_file(Filepath::from_locale_string("data/recursive-include-side-effect"))); // I think it will never get below here and fail? If it recurses, the above fails int line_count = 0; { // from https://stackoverflow.com/a/19140230 - std::ifstream in(testfile.get_path()); + std::ifstream in(testfile.get_path().to_locale_string()); std::string line; while (std::getline(in, line)) { line_count++; diff --git a/test/opmlurlreader.cpp b/test/opmlurlreader.cpp index bc60d323..e73c66ce 100644 --- a/test/opmlurlreader.cpp +++ b/test/opmlurlreader.cpp @@ -1,5 +1,3 @@ -#define ENABLE_IMPLICIT_FILEPATH_CONVERSIONS - #include "opmlurlreader.h" #include <map> @@ -79,13 +77,13 @@ TEST_CASE("OpmlUrlReader::reload() reads URLs and tags from an OPML file", TEST_CASE("OpmlUrlReader::reload() loads URLs from multiple sources", "[OpmlUrlReader]") { - const std::string cwd = utils::getcwd(); + const auto cwd = utils::getcwd(); ConfigContainer cfg; cfg.set_configvalue("opml-url", - "file://" + cwd + "/data/example.opml" + "file://" + cwd.to_locale_string() + "/data/example.opml" + " " - + "file://" + cwd + "/data/example2.opml"); + + "file://" + cwd.to_locale_string() + "/data/example2.opml"); OpmlUrlReader reader(cfg); @@ -138,17 +136,17 @@ TEST_CASE("OpmlUrlReader::reload() loads URLs from multiple sources", TEST_CASE("OpmlUrlReader::reload() skips things that can't be parsed", "[OpmlUrlReader]") { - const std::string cwd = utils::getcwd(); + const auto cwd = utils::getcwd(); ConfigContainer cfg; cfg.set_configvalue("opml-url", - "file://" + cwd + "/data/example.opml" + "file://" + cwd.to_locale_string() + "/data/example.opml" + " " + "file:///dev/null" // empty file + " " - + "file://" + cwd + "/data/guaranteed-not-to-exist.xml" + + "file://" + cwd.to_locale_string() + "/data/guaranteed-not-to-exist.xml" + " " - + "file://" + cwd + "/data/example2.opml"); + + "file://" + cwd.to_locale_string() + "/data/example2.opml"); OpmlUrlReader reader(cfg); diff --git a/test/rssfeed.cpp b/test/rssfeed.cpp index 4577dc9e..9e7f453e 100644 --- a/test/rssfeed.cpp +++ b/test/rssfeed.cpp @@ -1,5 +1,3 @@ -#define ENABLE_IMPLICIT_FILEPATH_CONVERSIONS - #include "rssfeed.h" #include "3rd-party/catch.hpp" diff --git a/test/scopemeasure.cpp b/test/scopemeasure.cpp index 24aa5c16..b66716b2 100644 --- a/test/scopemeasure.cpp +++ b/test/scopemeasure.cpp @@ -1,5 +1,3 @@ -#define ENABLE_IMPLICIT_FILEPATH_CONVERSIONS - #include "scopemeasure.h" #include "3rd-party/catch.hpp" @@ -13,10 +11,10 @@ using namespace newsboat; -unsigned int file_lines_count(const std::string& filepath) +unsigned int file_lines_count(const Filepath& filepath) { unsigned int line_count = 0; - std::ifstream in(filepath); + std::ifstream in(filepath.to_locale_string()); std::string line; while (std::getline(in, line)) { line_count++; @@ -32,7 +30,7 @@ TEST_CASE("Destroying a ScopeMeasure object writes a line to the log", { test_helpers::LoggerResetter logReset; - const auto filepath = Filepath::from_locale_string(tmp.get_path()); + const auto filepath = tmp.get_path(); logger::set_logfile(filepath); logger::set_loglevel(Level::DEBUG); @@ -53,7 +51,7 @@ TEST_CASE("stopover() adds an extra line to the log upon each call", { test_helpers::LoggerResetter logReset; - const auto filepath = Filepath::from_locale_string(tmp.get_path()); + const auto filepath = tmp.get_path(); logger::set_logfile(filepath); logger::set_loglevel(Level::DEBUG); diff --git a/test/test_helpers/loggerresetter.cpp b/test/test_helpers/loggerresetter.cpp index 9d4d1c60..cbc01751 100644 --- a/test/test_helpers/loggerresetter.cpp +++ b/test/test_helpers/loggerresetter.cpp @@ -1,5 +1,3 @@ -#define ENABLE_IMPLICIT_FILEPATH_CONVERSIONS - #include "loggerresetter.h" #include "logger.h" |