matchers.cpp 877 B

1234567891011121314151617181920212223
  1. #include <library/cpp/testing/gtest/matchers.h>
  2. #include <library/cpp/testing/common/env.h>
  3. #include <util/folder/path.h>
  4. #include <util/stream/file.h>
  5. #include <util/system/fs.h>
  6. bool NGTest::NDetail::MatchOrUpdateGolden(std::string_view actualContent, const TString& goldenFilename) {
  7. if (!GetTestParam("GTEST_UPDATE_GOLDEN").empty()) {
  8. Y_ENSURE(NFs::MakeDirectoryRecursive(TFsPath(goldenFilename).Parent()));
  9. TFile file(goldenFilename, CreateAlways);
  10. file.Write(actualContent.data(), actualContent.size());
  11. Cerr << "The data[" << actualContent.size() << "] has written to golden file " << goldenFilename << Endl;
  12. return true;
  13. }
  14. if (!NFs::Exists(goldenFilename)) {
  15. return actualContent.empty();
  16. }
  17. TFile goldenFile(goldenFilename, RdOnly);
  18. return actualContent == TFileInput(goldenFile).ReadAll();
  19. }