From 08b15e72392b72c6d5b05c8f23ce7bf8090f31cd Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Mon, 12 Jun 2023 13:12:58 +0000 Subject: [PATCH] make 'loading' diag messages conditional --- test/tap/tap/Makefile | 2 ++ test/tap/tap/command_line.cpp | 34 +++++++++++++++--------- test/tap/tap/cpp-dotenv/dotenv.cpp.patch | 18 +++++++++++++ test/tap/tap/cpp-dotenv/dotenv.h.patch | 10 +++++++ 4 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 test/tap/tap/cpp-dotenv/dotenv.cpp.patch create mode 100644 test/tap/tap/cpp-dotenv/dotenv.h.patch diff --git a/test/tap/tap/Makefile b/test/tap/tap/Makefile index 6ca93576e..bcedad12a 100644 --- a/test/tap/tap/Makefile +++ b/test/tap/tap/Makefile @@ -44,6 +44,8 @@ libtap.a: tap.cpp tap.h command_line.cpp command_line.h utils.cpp utils.h cpp-do cpp-dotenv/cpp-dotenv/libcpp_dotenv.a: cd cpp-dotenv && rm -rf cpp-dotenv-*/ || true cd cpp-dotenv && tar -zxf cpp-dotenv-*.tar.gz + cd cpp-dotenv/cpp-dotenv && patch src/dotenv.cpp < ../dotenv.cpp.patch + cd cpp-dotenv/cpp-dotenv && patch include/dotenv.h < ../dotenv.h.patch cd cpp-dotenv/cpp-dotenv && cmake . -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug cd cpp-dotenv/cpp-dotenv && CC=${CC} CXX=${CXX} ${MAKE} cpp-dotenv: cpp-dotenv/cpp-dotenv/libcpp_dotenv.a diff --git a/test/tap/tap/command_line.cpp b/test/tap/tap/command_line.cpp index a667bb9bb..92a0c0592 100644 --- a/test/tap/tap/command_line.cpp +++ b/test/tap/tap/command_line.cpp @@ -15,7 +15,7 @@ using nlohmann::json; using dotenv::env; -//using namespace dotenv; + CommandLine::CommandLine() {} @@ -112,56 +112,64 @@ int CommandLine::getEnv() { std::string dir_path = exe_path.substr(0, exe_path.find_last_of('/')); std::string dir_name = dir_path.substr(dir_path.find_last_of('/') + 1); - diag("loading: %s", (dir_path + "/.env").c_str()); env.load_dotenv((dir_path + "/.env").c_str(), true); + bool loaded1 = env.loaded; - diag("loading: %s", (dir_path + "/" + dir_name + ".env").c_str()); env.load_dotenv((dir_path + "/" + dir_name + ".env").c_str(), true); + bool loaded2 = env.loaded; - diag("loading: %s", (exe_path + ".env").c_str()); env.load_dotenv((exe_path + ".env").c_str(), true); + bool loaded3 = env.loaded; + + bool quiet = (bool) getenv("TAP_QUIET_ENVLOAD"); + if (loaded1 && ! quiet) + diag("loaded: %s", (dir_path + "/.env").c_str()); + if (loaded2 && ! quiet) + diag("loaded: %s", (dir_path + "/" + dir_name + ".env").c_str()); + if (loaded3 && ! quiet) + diag("loaded: %s", (exe_path + ".env").c_str()); } - value=getenv("TAP_HOST"); + value = getenv("TAP_HOST"); if (value) replace_str_field(&this->host, value); - value=getenv("TAP_USERNAME"); + value = getenv("TAP_USERNAME"); if (value) replace_str_field(&this->username, value); - value=getenv("TAP_PASSWORD"); + value = getenv("TAP_PASSWORD"); if (value) replace_str_field(&this->password, value); - value=getenv("TAP_ADMINUSERNAME"); + value = getenv("TAP_ADMINUSERNAME"); if (value) replace_str_field(&this->admin_username, value); - value=getenv("TAP_ADMINPASSWORD"); + value = getenv("TAP_ADMINPASSWORD"); if (value) replace_str_field(&this->admin_password, value); int env_port = 0; - value=getenv("TAP_PORT"); + value = getenv("TAP_PORT"); if (value) { env_port = strtol(value, NULL, 10); if (env_port>0 && env_port<65536) port = env_port; } - value=getenv("TAP_ADMINPORT"); + value = getenv("TAP_ADMINPORT"); if (value) { env_port = strtol(value, NULL, 10); if (env_port>0 && env_port<65536) admin_port = env_port; } - value=getenv("TAP_WORKDIR"); + value = getenv("TAP_WORKDIR"); if (value) replace_str_field(&this->workdir, value); - value=getenv("TAP_CLIENT_FLAGS"); + value = getenv("TAP_CLIENT_FLAGS"); if (value) { char* end = NULL; uint64_t env_c_flags = strtoul(value, &end, 10); diff --git a/test/tap/tap/cpp-dotenv/dotenv.cpp.patch b/test/tap/tap/cpp-dotenv/dotenv.cpp.patch new file mode 100644 index 000000000..1f652caab --- /dev/null +++ b/test/tap/tap/cpp-dotenv/dotenv.cpp.patch @@ -0,0 +1,18 @@ +--- cpp-dotenv.old/src/dotenv.cpp 2023-06-12 10:09:44.621343972 +0000 ++++ cpp-dotenv.new/src/dotenv.cpp 2020-08-09 16:19:56.000000000 +0000 +@@ -13,6 +13,7 @@ + + dotenv::dotenv& dotenv::dotenv::load_dotenv(const string& dotenv_path, const bool overwrite, const bool interpolate) + { ++ loaded = false; + ifstream env_file; + env_file.open(dotenv_path); + +@@ -21,6 +22,7 @@ + Parser parser; + parser.parse(env_file, overwrite, interpolate); + env_file.close(); ++ loaded = true; + } + + return *this; diff --git a/test/tap/tap/cpp-dotenv/dotenv.h.patch b/test/tap/tap/cpp-dotenv/dotenv.h.patch new file mode 100644 index 000000000..0bfb8d6b6 --- /dev/null +++ b/test/tap/tap/cpp-dotenv/dotenv.h.patch @@ -0,0 +1,10 @@ +--- cpp-dotenv.old/include/dotenv.h 2023-06-12 10:11:58.748360147 +0000 ++++ cpp-dotenv.new/include/dotenv.h 2020-08-09 16:19:56.000000000 +0000 +@@ -28,6 +28,7 @@ + void operator=(const dotenv&) = delete; + + static dotenv& instance(); ++ bool loaded = false; + + private: +