aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhukoff-pavel <zhukoff-pavel@yandex-team.com>2023-05-18 16:08:11 +0300
committerzhukoff-pavel <zhukoff-pavel@yandex-team.com>2023-05-18 16:08:11 +0300
commit609d4c8138a6605de6fbc333e865b36acdb5cee6 (patch)
tree6428629679edb29de98b617ccb2cdb43bc22ec34
parent76f1d9f25a25d001f50b32113a5cc8f488d9d20a (diff)
downloadydb-609d4c8138a6605de6fbc333e865b36acdb5cee6.tar.gz
Setup test env.vars from test.context during test binary initialization cpp
-rw-r--r--library/cpp/testing/common/env.cpp19
-rw-r--r--library/cpp/testing/common/env.h1
-rw-r--r--library/cpp/testing/unittest/utmain.cpp25
3 files changed, 34 insertions, 11 deletions
diff --git a/library/cpp/testing/common/env.cpp b/library/cpp/testing/common/env.cpp
index 77c6b0d90b..6585de8584 100644
--- a/library/cpp/testing/common/env.cpp
+++ b/library/cpp/testing/common/env.cpp
@@ -170,11 +170,12 @@ namespace NPrivate {
TestOutputRamDrivePath = "";
GdbPath = "";
CoreSearchFile = "";
+ EnvFile = "";
TestParameters.clear();
GlobalResources.clear();
const TString contextFilename = GetEnv("YA_TEST_CONTEXT_FILE");
- if (contextFilename) {
+ if (contextFilename && TFsPath(contextFilename).Exists()) {
NJson::TJsonValue context;
NJson::ReadJsonTree(TFileInput(contextFilename).ReadAll(), &context);
@@ -238,6 +239,22 @@ namespace NPrivate {
if (value) {
CoreSearchFile = value->GetStringSafe("");
}
+
+ value = context.GetValueByPath("internal.env_file");
+ if (value) {
+ EnvFile = value->GetStringSafe("");
+ if (TFsPath(EnvFile).Exists()) {
+ TFileInput file(EnvFile);
+ NJson::TJsonValue envVar;
+ TString ljson;
+ while (file.ReadLine(ljson) > 0) {
+ NJson::ReadJsonTree(ljson, &envVar);
+ for (const auto& entry : envVar.GetMap()) {
+ SetEnv(entry.first, entry.second.GetStringSafe(""));
+ }
+ }
+ }
+ }
}
if (!YtHddPath) {
diff --git a/library/cpp/testing/common/env.h b/library/cpp/testing/common/env.h
index 6dbef4959b..6cd840442f 100644
--- a/library/cpp/testing/common/env.h
+++ b/library/cpp/testing/common/env.h
@@ -78,6 +78,7 @@ namespace NPrivate {
TString TestOutputRamDrivePath;
TString GdbPath;
TString CoreSearchFile;
+ TString EnvFile;
std::unordered_map<TString, TString> TestParameters;
std::unordered_map<TString, TString> GlobalResources;
};
diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp
index 40766bf137..9d52b89cd7 100644
--- a/library/cpp/testing/unittest/utmain.cpp
+++ b/library/cpp/testing/unittest/utmain.cpp
@@ -34,20 +34,20 @@
#include <filesystem>
#if defined(_win_)
-#include <fcntl.h>
-#include <io.h>
-#include <windows.h>
-#include <crtdbg.h>
+ #include <fcntl.h>
+ #include <io.h>
+ #include <windows.h>
+ #include <crtdbg.h>
#endif
#if defined(_unix_)
-#include <unistd.h>
+ #include <unistd.h>
#endif
#ifdef WITH_VALGRIND
-#define NOTE_IN_VALGRIND(test) VALGRIND_PRINTF("%s::%s", test->unit->name.data(), test->name)
+ #define NOTE_IN_VALGRIND(test) VALGRIND_PRINTF("%s::%s", test->unit->name.data(), test->name)
#else
-#define NOTE_IN_VALGRIND(test)
+ #define NOTE_IN_VALGRIND(test)
#endif
const size_t MAX_COMMENT_MESSAGE_LENGTH = 1024 * 1024; // 1 MB
@@ -705,6 +705,7 @@ int NUnitTest::RunMain(int argc, char** argv) {
#endif
NTesting::THook::CallBeforeInit();
InitNetworkSubSystem();
+ Singleton<::NPrivate::TTestEnv>();
try {
GetExecPath();
@@ -715,10 +716,14 @@ int NUnitTest::RunMain(int argc, char** argv) {
try {
#endif
NTesting::THook::CallBeforeRun();
- Y_DEFER { NTesting::THook::CallAfterRun(); };
+ Y_DEFER {
+ NTesting::THook::CallAfterRun();
+ };
NPlugin::OnStartMain(argc, argv);
- Y_DEFER { NPlugin::OnStopMain(argc, argv); };
+ Y_DEFER {
+ NPlugin::OnStopMain(argc, argv);
+ };
TColoredProcessor processor(GetExecPath());
IOutputStream* listStream = &Cout;
@@ -824,7 +829,7 @@ int NUnitTest::RunMain(int argc, char** argv) {
fileName = fileName.SubString(4, TStringBuf::npos);
NUnitTest::ShouldColorizeDiff = false;
traceProcessors.push_back(std::make_shared<TJUnitProcessor>(TString(fileName),
- std::filesystem::path(argv[0]).stem().string()));
+ std::filesystem::path(argv[0]).stem().string()));
}
}