diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2023-02-13 19:01:57 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2023-02-13 19:01:57 +0300 |
commit | b5b3d520c01646610f376c55455d9cad735e3e0d (patch) | |
tree | 0e113dcc316476655a9457eec509b5a1ebd967ed /library/cpp/testing/gtest/matchers.cpp | |
parent | b4781eb14f1b19ff7bb90d703ebf9ad470aa1e89 (diff) | |
download | ydb-b5b3d520c01646610f376c55455d9cad735e3e0d.tar.gz |
Intermediate changes
Diffstat (limited to 'library/cpp/testing/gtest/matchers.cpp')
-rw-r--r-- | library/cpp/testing/gtest/matchers.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/library/cpp/testing/gtest/matchers.cpp b/library/cpp/testing/gtest/matchers.cpp new file mode 100644 index 0000000000..421de85da5 --- /dev/null +++ b/library/cpp/testing/gtest/matchers.cpp @@ -0,0 +1,23 @@ +#include <library/cpp/testing/gtest/matchers.h> + +#include <library/cpp/testing/common/env.h> + +#include <util/folder/path.h> +#include <util/stream/file.h> +#include <util/system/fs.h> + +bool NGTest::NDetail::MatchOrUpdateGolden(std::string_view actualContent, const TString& goldenFilename) { + if (!GetTestParam("GTEST_UPDATE_GOLDEN").empty()) { + Y_ENSURE(NFs::MakeDirectoryRecursive(TFsPath(goldenFilename).Parent())); + TFile file(goldenFilename, CreateAlways); + file.Write(actualContent.data(), actualContent.size()); + Cerr << "The data[" << actualContent.size() << "] has written to golden file " << goldenFilename << Endl; + return true; + } + + if (!NFs::Exists(goldenFilename)) { + return actualContent.empty(); + } + TFile goldenFile(goldenFilename, RdOnly); + return actualContent == TFileInput(goldenFile).ReadAll(); +} |