diff options
| author | n-khamraev <[email protected]> | 2026-03-03 10:23:41 +0300 |
|---|---|---|
| committer | n-khamraev <[email protected]> | 2026-03-03 10:42:22 +0300 |
| commit | 3e610a450fe3ab97500c04bfdb9ca86e892e37b0 (patch) | |
| tree | 3828c485967457078d5e1cdee2a19ab32fc3effc /library/cpp/testing | |
| parent | e03d1bdddd44a80bddb7aaeaa173a1efabdd55fe (diff) | |
Activate json tests list logic and add tests
```
Listing of tests information into json file (--list-verbose) now uses json with extended meta data instead of :: separated string
* Changelog entry
Type: feature
Component: cpp-sdk
--list-verbose commands in Gtest and unittest are now using json with extended meta data instead of plain "::"-separated string
```
commit_hash:096b575c80989be0166f54b214e595dc58977fe0
Diffstat (limited to 'library/cpp/testing')
| -rw-r--r-- | library/cpp/testing/gtest/main.cpp | 25 | ||||
| -rw-r--r-- | library/cpp/testing/unittest/utmain.cpp | 36 |
2 files changed, 30 insertions, 31 deletions
diff --git a/library/cpp/testing/gtest/main.cpp b/library/cpp/testing/gtest/main.cpp index 05cca1b71a7..ab2ee4a688c 100644 --- a/library/cpp/testing/gtest/main.cpp +++ b/library/cpp/testing/gtest/main.cpp @@ -408,23 +408,18 @@ void NGTest::ListTests(int listLevel, const std::string& listPath) { if (listLevel > 1) { for (int j = 0; j < suite->total_test_count(); ++j) { auto test = suite->GetTestInfo(j); - if (false) { - // TODO: YA-3943 будет открыто в следующем PR, активироввать функционал нужно в два шага - NJson::TJsonValue testObj(NJson::JSON_MAP); + NJson::TJsonValue testObj(NJson::JSON_MAP); - testObj["test_suite_name"] = test->test_suite_name(); - testObj["name"] = test->name(); - testObj["file"] = test->file() ? test->file() : ""; - testObj["line"] = test->line(); - testObj["nodeid"] = std::string(test->test_suite_name()) + "::" + test->name(); - if (test->value_param()) { - testObj["params"] = test->value_param(); - } - - (*listOut) << NJson::WriteJson(&testObj) << "\n"; - } else { - (*listOut) << suite->name() << "::" << test->name() << "\n"; + testObj["test_suite_name"] = test->test_suite_name(); + testObj["name"] = test->name(); + testObj["file"] = test->file() ? test->file() : ""; + testObj["line"] = test->line(); + testObj["nodeid"] = std::string(test->test_suite_name()) + "::" + test->name(); + if (test->value_param()) { + testObj["params"] = test->value_param(); } + + (*listOut) << NJson::WriteJson(&testObj, false) << "\n"; } } else { (*listOut) << suite->name() << "\n"; diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp index 9bb43051d97..63c2875fbae 100644 --- a/library/cpp/testing/unittest/utmain.cpp +++ b/library/cpp/testing/unittest/utmain.cpp @@ -603,9 +603,10 @@ const char* const TColoredProcessor::ForkCorrectExitMsg = "--END--"; class TEnumeratingProcessor: public ITestSuiteProcessor { public: - TEnumeratingProcessor(bool verbose, IOutputStream& stream) noexcept + TEnumeratingProcessor(bool verbose, IOutputStream& stream, bool isFileOutput = false) noexcept : Verbose_(verbose) , Stream_(stream) + , IsFileOutput_(isFileOutput) { } @@ -627,18 +628,20 @@ public: } bool CheckAccessTest(TString suite, const char* name, const char* file, int line) override { - if (false) { - // TODO: YA-3943 будет открыто в следующем PR, активироввать функционал нужно в два шага - // if (Verbose_) { - NJson::TJsonValue testObj; - testObj["test_suite_name"] = suite; - testObj["name"] = name; - testObj["file"] = file ? file : ""; - testObj["line"] = line; - testObj["nodeid"] = suite + "::" + name; - - NJson::WriteJson(&Stream_, &testObj); - Stream_.Write("\n"); + if (Verbose_) { + // If we processing output to file (list-path), we would use JSON, else old plain text format + if (IsFileOutput_) { + NJson::TJsonValue testObj; + testObj["test_suite_name"] = suite; + testObj["name"] = name; + testObj["file"] = file ? file : ""; + testObj["line"] = line; + testObj["nodeid"] = suite + "::" + name; + NJson::WriteJson(&Stream_, &testObj); + Stream_.Write("\n"); + } else { + Stream_ << suite << "::" << name << "\n"; + } } else { Stream_ << suite << "::" << name << "\n"; } @@ -648,6 +651,7 @@ public: private: bool Verbose_; IOutputStream& Stream_; + bool IsFileOutput_; }; #ifdef _win_ @@ -683,8 +687,8 @@ private: static const TWinEnvironment Instance; #endif // _win_ -static int DoList(bool verbose, IOutputStream& stream) { - TEnumeratingProcessor eproc(verbose, stream); +static int DoList(bool verbose, IOutputStream& stream, bool isFileOutput = false) { + TEnumeratingProcessor eproc(verbose, stream, isFileOutput); TTestFactory::Instance().SetProcessor(&eproc); TTestFactory::Instance().Execute(); return 0; @@ -871,7 +875,7 @@ int NUnitTest::RunMain(int argc, char** argv) { } } if (listTests != DONT_LIST) { - return DoList(listTests == LIST_VERBOSE, *listStream); + return DoList(listTests == LIST_VERBOSE, *listStream, listFile.Get() != nullptr); } if (!hasJUnitProcessor) { |
