blob: 421de85da5ba606d5cc2a5b60852a496e86c97b9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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();
}
|