aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorgleb-kov <gleb-kov@yandex-team.ru>2022-02-10 16:46:22 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:22 +0300
commit7b1cfa32681104c8468c5824c79fd80d9a88a579 (patch)
tree499e0a6e0f35aba718ac262605efb4342996bdca /util
parent89973d10cfeccd97d2f25449a523c93940565edf (diff)
downloadydb-7b1cfa32681104c8468c5824c79fd80d9a88a579.tar.gz
Restoring authorship annotation for <gleb-kov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
-rw-r--r--util/folder/fts_ut.cpp2
-rw-r--r--util/generic/cast.h2
-rw-r--r--util/generic/hash.h2
-rw-r--r--util/generic/typelist_ut.cpp2
-rw-r--r--util/generic/yexception.cpp4
-rw-r--r--util/memory/blob_ut.cpp2
-rw-r--r--util/str_stl.h18
-rw-r--r--util/string/split.h68
-rw-r--r--util/system/file_ut.cpp2
-rw-r--r--util/system/mktemp.cpp64
-rw-r--r--util/system/tempfile.cpp28
-rw-r--r--util/system/tempfile.h30
-rw-r--r--util/system/tempfile_ut.cpp262
-rw-r--r--util/system/type_name.cpp14
-rw-r--r--util/system/type_name.h48
-rw-r--r--util/system/type_name_ut.cpp320
-rw-r--r--util/system/ut/ya.make2
-rw-r--r--util/ya.make2
18 files changed, 436 insertions, 436 deletions
diff --git a/util/folder/fts_ut.cpp b/util/folder/fts_ut.cpp
index c5d59e35f4..e7cb53e549 100644
--- a/util/folder/fts_ut.cpp
+++ b/util/folder/fts_ut.cpp
@@ -6,7 +6,7 @@
#include <library/cpp/threading/future/async.h>
#include <util/system/file.h>
-#include <util/system/tempfile.h>
+#include <util/system/tempfile.h>
#include <util/generic/string.h>
class TFtsTest: public TTestBase {
diff --git a/util/generic/cast.h b/util/generic/cast.h
index 0d4a41f385..d5eab17cfd 100644
--- a/util/generic/cast.h
+++ b/util/generic/cast.h
@@ -4,7 +4,7 @@
#include "yexception.h"
#include <util/system/compat.h>
-#include <util/system/type_name.h>
+#include <util/system/type_name.h>
#include <util/system/unaligned_mem.h>
#include <util/system/yassert.h>
diff --git a/util/generic/hash.h b/util/generic/hash.h
index e46db21fa9..043e8a5142 100644
--- a/util/generic/hash.h
+++ b/util/generic/hash.h
@@ -4,7 +4,7 @@
#include "mapfindptr.h"
#include <util/memory/alloc.h>
-#include <util/system/type_name.h>
+#include <util/system/type_name.h>
#include <util/system/yassert.h>
#include <util/str_stl.h>
#include "yexception.h"
diff --git a/util/generic/typelist_ut.cpp b/util/generic/typelist_ut.cpp
index eeabfa97b1..232ae5ab04 100644
--- a/util/generic/typelist_ut.cpp
+++ b/util/generic/typelist_ut.cpp
@@ -1,5 +1,5 @@
#include <library/cpp/testing/unittest/registar.h>
-#include <util/system/type_name.h>
+#include <util/system/type_name.h>
#include "typelist.h"
#include "vector.h"
diff --git a/util/generic/yexception.cpp b/util/generic/yexception.cpp
index 2ce6c4369d..e7d18cd778 100644
--- a/util/generic/yexception.cpp
+++ b/util/generic/yexception.cpp
@@ -2,7 +2,7 @@
#include "yexception.h"
#include <util/system/backtrace.h>
-#include <util/system/type_name.h>
+#include <util/system/type_name.h>
#include <cxxabi.h>
@@ -11,7 +11,7 @@
#include <cstdio>
TString FormatExc(const std::exception& exception) {
- return TString::Join(TStringBuf("("), TypeName(exception), TStringBuf(") "), exception.what());
+ return TString::Join(TStringBuf("("), TypeName(exception), TStringBuf(") "), exception.what());
}
TString CurrentExceptionMessage() {
diff --git a/util/memory/blob_ut.cpp b/util/memory/blob_ut.cpp
index 023f9a0487..4d908b3906 100644
--- a/util/memory/blob_ut.cpp
+++ b/util/memory/blob_ut.cpp
@@ -2,7 +2,7 @@
#include <library/cpp/testing/unittest/registar.h>
-#include <util/system/tempfile.h>
+#include <util/system/tempfile.h>
#include <util/folder/path.h>
#include <util/stream/output.h>
#include <util/stream/file.h>
diff --git a/util/str_stl.h b/util/str_stl.h
index f1e137181d..dbd6abf67e 100644
--- a/util/str_stl.h
+++ b/util/str_stl.h
@@ -7,8 +7,8 @@
#include <util/generic/strbuf.h>
#include <util/generic/typetraits.h>
-#include <functional>
-#include <typeindex>
+#include <functional>
+#include <typeindex>
#include <utility>
namespace std {
@@ -104,13 +104,13 @@ template <class C, class T, class A>
struct hash<std::basic_string<C, T, A>>: ::NHashPrivate::TStringHash<C> {
};
-template <>
-struct THash<std::type_index> {
- inline size_t operator()(const std::type_index& index) const {
- return index.hash_code();
- }
-};
-
+template <>
+struct THash<std::type_index> {
+ inline size_t operator()(const std::type_index& index) const {
+ return index.hash_code();
+ }
+};
+
namespace NHashPrivate {
template <typename T>
Y_FORCE_INLINE static size_t HashObject(const T& val) {
diff --git a/util/string/split.h b/util/string/split.h
index bc46d9e64c..ca9e1b24e1 100644
--- a/util/string/split.h
+++ b/util/string/split.h
@@ -651,58 +651,58 @@ namespace NStringSplitPrivate {
using TIteratorOf = typename TIteratorOfImpl<String>::type;
template <class String>
- class TStringSplitter;
-
- template <class String>
- struct TIterState: public TStringBufOf<String> {
- public:
+ class TStringSplitter;
+
+ template <class String>
+ struct TIterState: public TStringBufOf<String> {
+ public:
using TStringBufType = TStringBufOf<String>;
using TIterator = TIteratorOf<String>;
- friend class TStringSplitter<String>;
+ friend class TStringSplitter<String>;
TIterState(const String& string) noexcept
- : TStringBufType()
- , DelimiterEnd_(std::begin(string))
- , OriginEnd_(std::end(string))
+ : TStringBufType()
+ , DelimiterEnd_(std::begin(string))
+ , OriginEnd_(std::end(string))
{
}
template <
typename Other,
- typename = std::enable_if_t<
- std::is_convertible<Other, TStringBufType>::value>>
+ typename = std::enable_if_t<
+ std::is_convertible<Other, TStringBufType>::value>>
bool operator==(const Other& toCompare) const {
return TStringBufType(*this) == TStringBufType(toCompare);
}
TIterator TokenStart() const noexcept {
- return this->begin();
+ return this->begin();
}
TIterator TokenDelim() const noexcept {
- return this->end();
+ return this->end();
}
TStringBufType Token() const noexcept {
- return *this;
+ return *this;
}
TStringBufType Delim() const noexcept {
- return MakeStringBuf<TStringBufType>(TokenDelim(), DelimiterEnd_);
+ return MakeStringBuf<TStringBufType>(TokenDelim(), DelimiterEnd_);
}
private:
- void UpdateParentBuf(TIterator tokenStart, TIterator tokenDelim) noexcept {
- *static_cast<TStringBufType*>(this) = MakeStringBuf<TStringBufType>(tokenStart, tokenDelim);
+ void UpdateParentBuf(TIterator tokenStart, TIterator tokenDelim) noexcept {
+ *static_cast<TStringBufType*>(this) = MakeStringBuf<TStringBufType>(tokenStart, tokenDelim);
}
- bool DelimiterIsEmpty() const noexcept {
- return TokenDelim() == DelimiterEnd_;
+ bool DelimiterIsEmpty() const noexcept {
+ return TokenDelim() == DelimiterEnd_;
}
-
- private:
- TIterator DelimiterEnd_;
- const TIterator OriginEnd_;
+
+ private:
+ TIterator DelimiterEnd_;
+ const TIterator OriginEnd_;
};
template <class Base>
@@ -829,8 +829,8 @@ namespace NStringSplitPrivate {
using TStringType = String;
using TChar = typename TStringType::value_type;
using TIteratorState = TIterState<TStringType>;
- using TStringBufType = typename TIteratorState::TStringBufType;
- using TIterator = typename TIteratorState::TIterator;
+ using TStringBufType = typename TIteratorState::TStringBufType;
+ using TIterator = typename TIteratorState::TIterator;
/**
* Base class for all split ranges that actually does the splitting.
@@ -841,18 +841,18 @@ namespace NStringSplitPrivate {
inline TSplitRangeBase(OtherString&& s, Args&&... args)
: String_(std::forward<OtherString>(s))
, State_(String_)
- , Delimiter_(std::forward<Args>(args)...)
+ , Delimiter_(std::forward<Args>(args)...)
{
}
inline TIteratorState* Next() {
- if (State_.DelimiterIsEmpty()) {
+ if (State_.DelimiterIsEmpty()) {
return nullptr;
}
- const auto tokenBegin = State_.DelimiterEnd_;
- const auto tokenEnd = Delimiter_.Ptr()->Find(State_.DelimiterEnd_, State_.OriginEnd_);
- State_.UpdateParentBuf(tokenBegin, tokenEnd);
+ const auto tokenBegin = State_.DelimiterEnd_;
+ const auto tokenEnd = Delimiter_.Ptr()->Find(State_.DelimiterEnd_, State_.OriginEnd_);
+ State_.UpdateParentBuf(tokenBegin, tokenEnd);
return &State_;
}
@@ -860,7 +860,7 @@ namespace NStringSplitPrivate {
private:
TStringType String_;
TIteratorState State_;
- DelimStorage Delimiter_;
+ DelimStorage Delimiter_;
};
template <class Base, class Filter>
@@ -888,7 +888,7 @@ namespace NStringSplitPrivate {
struct TNonEmptyFilter {
template <class TToken>
inline bool Accept(const TToken* token) noexcept {
- return !token->empty();
+ return !token->empty();
}
};
@@ -967,8 +967,8 @@ namespace NStringSplitPrivate {
--Count;
return false;
} else if (Count == 1) {
- token->DelimiterEnd_ = token->OriginEnd_;
- token->UpdateParentBuf(token->TokenStart(), token->DelimiterEnd_);
+ token->DelimiterEnd_ = token->OriginEnd_;
+ token->UpdateParentBuf(token->TokenStart(), token->DelimiterEnd_);
return false;
}
return true;
diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp
index 941e6a50f3..a8ef80b8c0 100644
--- a/util/system/file_ut.cpp
+++ b/util/system/file_ut.cpp
@@ -1,6 +1,6 @@
#include "file.h"
#include "fs.h"
-#include "tempfile.h"
+#include "tempfile.h"
#include <library/cpp/testing/unittest/registar.h>
diff --git a/util/system/mktemp.cpp b/util/system/mktemp.cpp
index 505b7b4a4b..c190bd4fe2 100644
--- a/util/system/mktemp.cpp
+++ b/util/system/mktemp.cpp
@@ -1,4 +1,4 @@
-#include "tempfile.h"
+#include "tempfile.h"
#include <util/folder/dirut.h>
#include <util/generic/yexception.h>
@@ -17,57 +17,57 @@
extern "C" int mkstemps(char* path, int slen);
-TString MakeTempName(const char* wrkDir, const char* prefix, const char* extension) {
+TString MakeTempName(const char* wrkDir, const char* prefix, const char* extension) {
#ifndef _win32_
- TString filePath;
+ TString filePath;
if (wrkDir && *wrkDir) {
- filePath += wrkDir;
+ filePath += wrkDir;
} else {
- filePath += GetSystemTempDir();
+ filePath += GetSystemTempDir();
}
- if (filePath.back() != '/') {
- filePath += '/';
+ if (filePath.back() != '/') {
+ filePath += '/';
}
- if (prefix) {
- filePath += prefix;
+ if (prefix) {
+ filePath += prefix;
}
- filePath += "XXXXXX"; // mkstemps requirement
+ filePath += "XXXXXX"; // mkstemps requirement
- size_t extensionPartLength = 0;
- if (extension && *extension) {
- if (extension[0] != '.') {
- filePath += '.';
- extensionPartLength += 1;
- }
- filePath += extension;
- extensionPartLength += strlen(extension);
+ size_t extensionPartLength = 0;
+ if (extension && *extension) {
+ if (extension[0] != '.') {
+ filePath += '.';
+ extensionPartLength += 1;
+ }
+ filePath += extension;
+ extensionPartLength += strlen(extension);
}
- int fd = mkstemps(const_cast<char*>(filePath.data()), extensionPartLength);
- if (fd >= 0) {
+ int fd = mkstemps(const_cast<char*>(filePath.data()), extensionPartLength);
+ if (fd >= 0) {
close(fd);
- return filePath;
+ return filePath;
}
#else
- char tmpDir[MAX_PATH + 1]; // +1 -- for terminating null character
- char filePath[MAX_PATH];
+ char tmpDir[MAX_PATH + 1]; // +1 -- for terminating null character
+ char filePath[MAX_PATH];
const char* pDir = 0;
- if (wrkDir && *wrkDir) {
+ if (wrkDir && *wrkDir) {
pDir = wrkDir;
- } else if (GetTempPath(MAX_PATH + 1, tmpDir)) {
- pDir = tmpDir;
- }
+ } else if (GetTempPath(MAX_PATH + 1, tmpDir)) {
+ pDir = tmpDir;
+ }
- // it always takes up to 3 characters, no more
- if (GetTempFileName(pDir, (prefix) ? (prefix) : "yan", 0, filePath)) {
- return filePath;
- }
+ // it always takes up to 3 characters, no more
+ if (GetTempFileName(pDir, (prefix) ? (prefix) : "yan", 0, filePath)) {
+ return filePath;
+ }
#endif
- ythrow TSystemError() << "can not create temp name(" << wrkDir << ", " << prefix << ", " << extension << ")";
+ ythrow TSystemError() << "can not create temp name(" << wrkDir << ", " << prefix << ", " << extension << ")";
}
diff --git a/util/system/tempfile.cpp b/util/system/tempfile.cpp
index a2e9f49eb1..534ccf9b26 100644
--- a/util/system/tempfile.cpp
+++ b/util/system/tempfile.cpp
@@ -1,9 +1,9 @@
#include "tempfile.h"
-TTempFileHandle::TTempFileHandle()
- : TTempFile(MakeTempName())
- , TFile(CreateFile())
-{
+TTempFileHandle::TTempFileHandle()
+ : TTempFile(MakeTempName())
+ , TFile(CreateFile())
+{
}
TTempFileHandle::TTempFileHandle(const TString& fname)
@@ -12,14 +12,14 @@ TTempFileHandle::TTempFileHandle(const TString& fname)
{
}
-TTempFileHandle TTempFileHandle::InCurrentDir(const TString& filePrefix, const TString& extension) {
- return TTempFileHandle(MakeTempName(".", filePrefix.c_str(), extension.c_str()));
-}
-
-TTempFileHandle TTempFileHandle::InDir(const TFsPath& dirPath, const TString& filePrefix, const TString& extension) {
- return TTempFileHandle(MakeTempName(dirPath.c_str(), filePrefix.c_str(), extension.c_str()));
-}
-
-TFile TTempFileHandle::CreateFile() const {
- return TFile(Name(), CreateAlways | RdWr);
+TTempFileHandle TTempFileHandle::InCurrentDir(const TString& filePrefix, const TString& extension) {
+ return TTempFileHandle(MakeTempName(".", filePrefix.c_str(), extension.c_str()));
}
+
+TTempFileHandle TTempFileHandle::InDir(const TFsPath& dirPath, const TString& filePrefix, const TString& extension) {
+ return TTempFileHandle(MakeTempName(dirPath.c_str(), filePrefix.c_str(), extension.c_str()));
+}
+
+TFile TTempFileHandle::CreateFile() const {
+ return TFile(Name(), CreateAlways | RdWr);
+}
diff --git a/util/system/tempfile.h b/util/system/tempfile.h
index de249c129d..fb8ec62ec6 100644
--- a/util/system/tempfile.h
+++ b/util/system/tempfile.h
@@ -3,7 +3,7 @@
#include "fs.h"
#include "file.h"
-#include <util/folder/path.h>
+#include <util/folder/path.h>
#include <util/generic/string.h>
class TTempFile {
@@ -30,21 +30,21 @@ public:
TTempFileHandle();
TTempFileHandle(const TString& fname);
- static TTempFileHandle InCurrentDir(const TString& filePrefix = "yandex", const TString& extension = "tmp");
- static TTempFileHandle InDir(const TFsPath& dirPath, const TString& filePrefix = "yandex", const TString& extension = "tmp");
-
+ static TTempFileHandle InCurrentDir(const TString& filePrefix = "yandex", const TString& extension = "tmp");
+ static TTempFileHandle InDir(const TFsPath& dirPath, const TString& filePrefix = "yandex", const TString& extension = "tmp");
+
private:
TFile CreateFile() const;
};
-
-/*
- * Creates a unique temporary filename in specified directory.
- * If specified directory is NULL or empty, then system temporary directory is used.
- *
- * Note, that the function is not race-free, the file is guaranteed to exist at the time the function returns, but not at the time the returned name is first used.
- * Throws TSystemError on error.
+
+/*
+ * Creates a unique temporary filename in specified directory.
+ * If specified directory is NULL or empty, then system temporary directory is used.
*
- * Returned filepath has such format: dir/prefixXXXXXX.extension or dir/prefixXXXXXX
- * But win32: dir/preXXXX.tmp (prefix is up to 3 characters, extension is always tmp).
- */
-TString MakeTempName(const char* wrkDir = nullptr, const char* prefix = "yandex", const char* extension = "tmp");
+ * Note, that the function is not race-free, the file is guaranteed to exist at the time the function returns, but not at the time the returned name is first used.
+ * Throws TSystemError on error.
+ *
+ * Returned filepath has such format: dir/prefixXXXXXX.extension or dir/prefixXXXXXX
+ * But win32: dir/preXXXX.tmp (prefix is up to 3 characters, extension is always tmp).
+ */
+TString MakeTempName(const char* wrkDir = nullptr, const char* prefix = "yandex", const char* extension = "tmp");
diff --git a/util/system/tempfile_ut.cpp b/util/system/tempfile_ut.cpp
index e4a0923d0b..3b9ad5fc50 100644
--- a/util/system/tempfile_ut.cpp
+++ b/util/system/tempfile_ut.cpp
@@ -3,11 +3,11 @@
#include <library/cpp/testing/unittest/registar.h>
#include <util/folder/dirut.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
#include <util/stream/file.h>
-#include <algorithm>
-
+#include <algorithm>
+
Y_UNIT_TEST_SUITE(TTempFileHandle) {
Y_UNIT_TEST(Create) {
TString path;
@@ -20,132 +20,132 @@ Y_UNIT_TEST_SUITE(TTempFileHandle) {
}
UNIT_ASSERT(!NFs::Exists(path));
}
-
- Y_UNIT_TEST(InCurrentDir) {
-#ifndef _win32_
- static const TString TEST_PREFIX = "unique_prefix";
-#else
- static const TString TEST_PREFIX = "uni";
-#endif
-
- TString path;
- {
- TTempFileHandle tmp = TTempFileHandle::InCurrentDir(TEST_PREFIX);
- path = tmp.Name();
- UNIT_ASSERT(NFs::Exists(path));
-
- TVector<TString> names;
- TFsPath(".").ListNames(names);
- bool containsFileWithPrefix = std::any_of(names.begin(), names.end(), [&](const TString& name) {
- return name.Contains(TEST_PREFIX);
- });
- UNIT_ASSERT(containsFileWithPrefix);
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(UseExtensionWithoutDot) {
- TString path;
- {
- TTempFileHandle tmp = TTempFileHandle::InCurrentDir("hello", "world");
- path = tmp.Name();
- UNIT_ASSERT(NFs::Exists(path));
-
-#ifndef _win32_
- UNIT_ASSERT(path.Contains("hello"));
- UNIT_ASSERT(path.EndsWith(".world"));
- UNIT_ASSERT(!path.EndsWith("..world"));
-#else
- UNIT_ASSERT(path.Contains("hel"));
- UNIT_ASSERT(path.EndsWith(".tmp"));
-#endif
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(UseExtensionWithDot) {
- TString path;
- {
- TTempFileHandle tmp = TTempFileHandle::InCurrentDir("lorem", ".ipsum");
- path = tmp.Name();
- UNIT_ASSERT(NFs::Exists(path));
-
-#ifndef _win32_
- UNIT_ASSERT(path.Contains("lorem"));
- UNIT_ASSERT(path.EndsWith(".ipsum"));
- UNIT_ASSERT(!path.EndsWith("..ipsum"));
-#else
- UNIT_ASSERT(path.Contains("lor"));
- UNIT_ASSERT(path.EndsWith(".tmp"));
-#endif
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(SafeDestructor) {
- TString path;
- {
- path = MakeTempName();
- UNIT_ASSERT(NFs::Exists(path));
-
- TTempFileHandle tmp(path);
- Y_UNUSED(tmp);
- UNIT_ASSERT(NFs::Exists(path));
-
- TTempFileHandle anotherTmp(path);
- Y_UNUSED(anotherTmp);
- UNIT_ASSERT(NFs::Exists(path));
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(RemovesOpen) {
- TString path;
- {
- TTempFileHandle tmp;
- path = tmp.Name();
- tmp.Write("hello world\n", 12);
- tmp.FlushData();
- UNIT_ASSERT(NFs::Exists(path));
- UNIT_ASSERT(tmp.IsOpen());
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(NonExistingDirectory) {
- UNIT_ASSERT_EXCEPTION(TTempFileHandle::InDir("nonexsistingdirname"), TSystemError);
- }
-}
-
-Y_UNIT_TEST_SUITE(MakeTempName) {
- Y_UNIT_TEST(Default) {
- TString path;
- {
- TTempFile tmp(MakeTempName());
- path = tmp.Name();
-
- UNIT_ASSERT(!path.Contains('\0'));
- UNIT_ASSERT(NFs::Exists(path));
- UNIT_ASSERT(path.EndsWith(".tmp"));
-
-#ifndef _win32_
- UNIT_ASSERT(path.Contains("yandex"));
-#else
- UNIT_ASSERT(path.Contains("yan"));
-#endif
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
-
- Y_UNIT_TEST(UseNullptr) {
- TString path;
- {
- TTempFile tmp(MakeTempName(nullptr, nullptr, nullptr));
- path = tmp.Name();
-
- UNIT_ASSERT(!path.Contains('\0'));
- UNIT_ASSERT(NFs::Exists(path));
- }
- UNIT_ASSERT(!NFs::Exists(path));
- }
+
+ Y_UNIT_TEST(InCurrentDir) {
+#ifndef _win32_
+ static const TString TEST_PREFIX = "unique_prefix";
+#else
+ static const TString TEST_PREFIX = "uni";
+#endif
+
+ TString path;
+ {
+ TTempFileHandle tmp = TTempFileHandle::InCurrentDir(TEST_PREFIX);
+ path = tmp.Name();
+ UNIT_ASSERT(NFs::Exists(path));
+
+ TVector<TString> names;
+ TFsPath(".").ListNames(names);
+ bool containsFileWithPrefix = std::any_of(names.begin(), names.end(), [&](const TString& name) {
+ return name.Contains(TEST_PREFIX);
+ });
+ UNIT_ASSERT(containsFileWithPrefix);
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(UseExtensionWithoutDot) {
+ TString path;
+ {
+ TTempFileHandle tmp = TTempFileHandle::InCurrentDir("hello", "world");
+ path = tmp.Name();
+ UNIT_ASSERT(NFs::Exists(path));
+
+#ifndef _win32_
+ UNIT_ASSERT(path.Contains("hello"));
+ UNIT_ASSERT(path.EndsWith(".world"));
+ UNIT_ASSERT(!path.EndsWith("..world"));
+#else
+ UNIT_ASSERT(path.Contains("hel"));
+ UNIT_ASSERT(path.EndsWith(".tmp"));
+#endif
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(UseExtensionWithDot) {
+ TString path;
+ {
+ TTempFileHandle tmp = TTempFileHandle::InCurrentDir("lorem", ".ipsum");
+ path = tmp.Name();
+ UNIT_ASSERT(NFs::Exists(path));
+
+#ifndef _win32_
+ UNIT_ASSERT(path.Contains("lorem"));
+ UNIT_ASSERT(path.EndsWith(".ipsum"));
+ UNIT_ASSERT(!path.EndsWith("..ipsum"));
+#else
+ UNIT_ASSERT(path.Contains("lor"));
+ UNIT_ASSERT(path.EndsWith(".tmp"));
+#endif
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(SafeDestructor) {
+ TString path;
+ {
+ path = MakeTempName();
+ UNIT_ASSERT(NFs::Exists(path));
+
+ TTempFileHandle tmp(path);
+ Y_UNUSED(tmp);
+ UNIT_ASSERT(NFs::Exists(path));
+
+ TTempFileHandle anotherTmp(path);
+ Y_UNUSED(anotherTmp);
+ UNIT_ASSERT(NFs::Exists(path));
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(RemovesOpen) {
+ TString path;
+ {
+ TTempFileHandle tmp;
+ path = tmp.Name();
+ tmp.Write("hello world\n", 12);
+ tmp.FlushData();
+ UNIT_ASSERT(NFs::Exists(path));
+ UNIT_ASSERT(tmp.IsOpen());
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(NonExistingDirectory) {
+ UNIT_ASSERT_EXCEPTION(TTempFileHandle::InDir("nonexsistingdirname"), TSystemError);
+ }
}
+
+Y_UNIT_TEST_SUITE(MakeTempName) {
+ Y_UNIT_TEST(Default) {
+ TString path;
+ {
+ TTempFile tmp(MakeTempName());
+ path = tmp.Name();
+
+ UNIT_ASSERT(!path.Contains('\0'));
+ UNIT_ASSERT(NFs::Exists(path));
+ UNIT_ASSERT(path.EndsWith(".tmp"));
+
+#ifndef _win32_
+ UNIT_ASSERT(path.Contains("yandex"));
+#else
+ UNIT_ASSERT(path.Contains("yan"));
+#endif
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+
+ Y_UNIT_TEST(UseNullptr) {
+ TString path;
+ {
+ TTempFile tmp(MakeTempName(nullptr, nullptr, nullptr));
+ path = tmp.Name();
+
+ UNIT_ASSERT(!path.Contains('\0'));
+ UNIT_ASSERT(NFs::Exists(path));
+ }
+ UNIT_ASSERT(!NFs::Exists(path));
+ }
+}
diff --git a/util/system/type_name.cpp b/util/system/type_name.cpp
index 0377da4212..fc578091b3 100644
--- a/util/system/type_name.cpp
+++ b/util/system/type_name.cpp
@@ -6,7 +6,7 @@
#include <cxxabi.h>
#endif
-#include "type_name.h"
+#include "type_name.h"
namespace {
@@ -42,19 +42,19 @@ const char* NPrivate::TCppDemangler::Demangle(const char* name) {
TString CppDemangle(const TString& name) {
return NPrivate::TCppDemangler().Demangle(name.data());
}
-
-TString TypeName(const std::type_info& typeInfo) {
+
+TString TypeName(const std::type_info& typeInfo) {
TString demangled = CppDemangle(typeInfo.name()); // NOLINT(arcadia-typeid-name-restriction)
#if defined(_linux_) || defined(_darwin_)
SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX);
#endif
return demangled;
-}
-
-TString TypeName(const std::type_index& typeIndex) {
+}
+
+TString TypeName(const std::type_index& typeIndex) {
TString demangled = CppDemangle(typeIndex.name());
#if defined(_linux_) || defined(_darwin_)
SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX);
#endif
return demangled;
-}
+}
diff --git a/util/system/type_name.h b/util/system/type_name.h
index b6619aba3f..72196542fe 100644
--- a/util/system/type_name.h
+++ b/util/system/type_name.h
@@ -3,28 +3,28 @@
#include <util/generic/string.h>
#include <util/string/subst.h>
-#include <typeindex>
-#include <typeinfo>
-
-// Consider using TypeName function family.
+#include <typeindex>
+#include <typeinfo>
+
+// Consider using TypeName function family.
TString CppDemangle(const TString& name);
-
-// TypeName function family return human readable type name.
-
-TString TypeName(const std::type_info& typeInfo);
-TString TypeName(const std::type_index& typeInfo);
-
-// Works for types known at compile-time
-// (thus, does not take any inheritance into account)
-template <class T>
-inline TString TypeName() {
- return TypeName(typeid(T));
-}
-
-// Works for dynamic type, including complex class hierarchies.
-// Also, distinguishes between T, T*, T const*, T volatile*, T const volatile*,
-// but not T and T const.
-template <class T>
-inline TString TypeName(const T& t) {
- return TypeName(typeid(t));
-}
+
+// TypeName function family return human readable type name.
+
+TString TypeName(const std::type_info& typeInfo);
+TString TypeName(const std::type_index& typeInfo);
+
+// Works for types known at compile-time
+// (thus, does not take any inheritance into account)
+template <class T>
+inline TString TypeName() {
+ return TypeName(typeid(T));
+}
+
+// Works for dynamic type, including complex class hierarchies.
+// Also, distinguishes between T, T*, T const*, T volatile*, T const volatile*,
+// but not T and T const.
+template <class T>
+inline TString TypeName(const T& t) {
+ return TypeName(typeid(t));
+}
diff --git a/util/system/type_name_ut.cpp b/util/system/type_name_ut.cpp
index 86597f4232..95b5a25428 100644
--- a/util/system/type_name_ut.cpp
+++ b/util/system/type_name_ut.cpp
@@ -1,13 +1,13 @@
-#include "type_name.h"
+#include "type_name.h"
#include <library/cpp/testing/unittest/registar.h>
-#include <util/generic/yexception.h>
-#include <util/generic/fwd.h>
-
-#include <stdexcept>
-#include <string>
-
+#include <util/generic/yexception.h>
+#include <util/generic/fwd.h>
+
+#include <stdexcept>
+#include <string>
+
Y_UNIT_TEST_SUITE(TDemangleTest) {
Y_UNIT_TEST(SimpleTest) {
// just check it does not crash or leak
@@ -16,169 +16,169 @@ Y_UNIT_TEST_SUITE(TDemangleTest) {
CppDemangle("Sfsdf$dfsdfTTSFSDF23234::SDFS:FSDFSDF#$%");
}
}
-
-namespace NUtil::NTypeNameTest {
-
- class TSonde {
- // intentionally left empty
- };
-
- class TRombicHead {
- public:
- virtual ~TRombicHead() = default;
- };
-
+
+namespace NUtil::NTypeNameTest {
+
+ class TSonde {
+ // intentionally left empty
+ };
+
+ class TRombicHead {
+ public:
+ virtual ~TRombicHead() = default;
+ };
+
class TRombicLeftArc: public virtual TRombicHead {
- public:
- int x;
- virtual ~TRombicLeftArc() = default;
- };
-
+ public:
+ int x;
+ virtual ~TRombicLeftArc() = default;
+ };
+
class TRombicRightArc: public virtual TRombicHead {
- public:
- int y;
- virtual ~TRombicRightArc() = default;
- };
-
+ public:
+ int y;
+ virtual ~TRombicRightArc() = default;
+ };
+
class TRombicTail: public virtual TRombicRightArc, TRombicLeftArc {
- public:
- virtual ~TRombicTail() = default;
- };
-
- class TFromThis {
- public:
- TString GetTypeName() const {
- return TypeName(*this);
- }
- };
-}
-
-using namespace NUtil::NTypeNameTest;
-
-Y_UNIT_TEST_SUITE(TypeName) {
- Y_UNIT_TEST(FromWellKnownTypes) {
- UNIT_ASSERT_VALUES_EQUAL(TypeName<void>(), "void");
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName<void*>(), "void * __ptr64");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName<void*>(), "void*");
-#endif
- UNIT_ASSERT_VALUES_EQUAL(TypeName<int>(), "int");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<double>(), "double");
-
-#ifdef _MSC_VER
+ public:
+ virtual ~TRombicTail() = default;
+ };
+
+ class TFromThis {
+ public:
+ TString GetTypeName() const {
+ return TypeName(*this);
+ }
+ };
+}
+
+using namespace NUtil::NTypeNameTest;
+
+Y_UNIT_TEST_SUITE(TypeName) {
+ Y_UNIT_TEST(FromWellKnownTypes) {
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<void>(), "void");
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<void*>(), "void * __ptr64");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<void*>(), "void*");
+#endif
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<int>(), "int");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<double>(), "double");
+
+#ifdef _MSC_VER
UNIT_ASSERT_VALUES_EQUAL(TypeName<std::string>(), "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<std::runtime_error>(), "class std::runtime_error");
-#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<std::runtime_error>(), "class std::runtime_error");
+#else
UNIT_ASSERT_VALUES_EQUAL(TypeName<std::string>(), "std::basic_string<char, std::char_traits<char>, std::allocator<char> >");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<std::runtime_error>(), "std::runtime_error");
-#endif
- }
-
- Y_UNIT_TEST(FromArcadiaTypes) {
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName<yexception>(), "class yexception");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<std::runtime_error>(), "std::runtime_error");
+#endif
+ }
+
+ Y_UNIT_TEST(FromArcadiaTypes) {
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<yexception>(), "class yexception");
UNIT_ASSERT_VALUES_EQUAL(TypeName<TString>(), "class TBasicString<char,struct std::char_traits<char> >");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName<yexception>(), "yexception");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<yexception>(), "yexception");
UNIT_ASSERT_VALUES_EQUAL(TypeName<TString>(), "TBasicString<char, std::char_traits<char> >");
-#endif
- }
-
- Y_UNIT_TEST(FromUserTypes) {
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName<TSonde>(), "class NUtil::NTypeNameTest::TSonde");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<TRombicTail>(), "class NUtil::NTypeNameTest::TRombicTail");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName<TSonde>(), "NUtil::NTypeNameTest::TSonde");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<TRombicTail>(), "NUtil::NTypeNameTest::TRombicTail");
-#endif
- }
-
- Y_UNIT_TEST(FromWellKnownValues) {
- void* value = (void*)"123";
- const void* constValue = (const void*)"456";
-
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName(value), "void * __ptr64");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(&value), "void * __ptr64 * __ptr64");
-
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constValue), "void const * __ptr64");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(&constValue), "void const * __ptr64 * __ptr64");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName(value), "void*");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(&value), "void**");
-
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constValue), "void const*");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(&constValue), "void const**");
-#endif
-
- int zero = 0;
- UNIT_ASSERT_VALUES_EQUAL(TypeName(zero), "int");
-
- double pi = M_PI;
- UNIT_ASSERT_VALUES_EQUAL(TypeName(pi), "double");
-
- std::string string;
- std::runtime_error err("This is awful");
-#ifdef _MSC_VER
+#endif
+ }
+
+ Y_UNIT_TEST(FromUserTypes) {
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<TSonde>(), "class NUtil::NTypeNameTest::TSonde");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<TRombicTail>(), "class NUtil::NTypeNameTest::TRombicTail");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<TSonde>(), "NUtil::NTypeNameTest::TSonde");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<TRombicTail>(), "NUtil::NTypeNameTest::TRombicTail");
+#endif
+ }
+
+ Y_UNIT_TEST(FromWellKnownValues) {
+ void* value = (void*)"123";
+ const void* constValue = (const void*)"456";
+
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(value), "void * __ptr64");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(&value), "void * __ptr64 * __ptr64");
+
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constValue), "void const * __ptr64");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(&constValue), "void const * __ptr64 * __ptr64");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(value), "void*");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(&value), "void**");
+
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constValue), "void const*");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(&constValue), "void const**");
+#endif
+
+ int zero = 0;
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(zero), "int");
+
+ double pi = M_PI;
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(pi), "double");
+
+ std::string string;
+ std::runtime_error err("This is awful");
+#ifdef _MSC_VER
UNIT_ASSERT_VALUES_EQUAL(TypeName(string), "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(err), "class std::runtime_error");
-#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(err), "class std::runtime_error");
+#else
UNIT_ASSERT_VALUES_EQUAL(TypeName(string), "std::basic_string<char, std::char_traits<char>, std::allocator<char> >");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(err), "std::runtime_error");
-#endif
- }
-
- Y_UNIT_TEST(FromUserValues) {
- TSonde sonde;
- const TSonde constSonde;
-
- TRombicTail rombicTail;
- TRombicHead& castedTail = rombicTail;
-
- TFromThis obj;
-
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName(sonde), "class NUtil::NTypeNameTest::TSonde");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constSonde), "class NUtil::NTypeNameTest::TSonde");
-
- UNIT_ASSERT_VALUES_EQUAL(TypeName(rombicTail), "class NUtil::NTypeNameTest::TRombicTail");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(castedTail), "class NUtil::NTypeNameTest::TRombicTail");
-
- UNIT_ASSERT_VALUES_EQUAL(obj.GetTypeName(), "class NUtil::NTypeNameTest::TFromThis");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName(sonde), "NUtil::NTypeNameTest::TSonde");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constSonde), "NUtil::NTypeNameTest::TSonde");
-
- UNIT_ASSERT_VALUES_EQUAL(TypeName(rombicTail), "NUtil::NTypeNameTest::TRombicTail");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(castedTail), "NUtil::NTypeNameTest::TRombicTail");
-
- UNIT_ASSERT_VALUES_EQUAL(obj.GetTypeName(), "NUtil::NTypeNameTest::TFromThis");
-#endif
- }
-
- Y_UNIT_TEST(FromTypeInfo) {
- UNIT_ASSERT_VALUES_EQUAL(TypeName(typeid(int)), "int");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(std::type_index(typeid(int))), "int");
- }
-
- Y_UNIT_TEST(DistinguishPointerQualifiers) {
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(err), "std::runtime_error");
+#endif
+ }
+
+ Y_UNIT_TEST(FromUserValues) {
+ TSonde sonde;
+ const TSonde constSonde;
+
+ TRombicTail rombicTail;
+ TRombicHead& castedTail = rombicTail;
+
+ TFromThis obj;
+
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(sonde), "class NUtil::NTypeNameTest::TSonde");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constSonde), "class NUtil::NTypeNameTest::TSonde");
+
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(rombicTail), "class NUtil::NTypeNameTest::TRombicTail");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(castedTail), "class NUtil::NTypeNameTest::TRombicTail");
+
+ UNIT_ASSERT_VALUES_EQUAL(obj.GetTypeName(), "class NUtil::NTypeNameTest::TFromThis");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(sonde), "NUtil::NTypeNameTest::TSonde");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constSonde), "NUtil::NTypeNameTest::TSonde");
+
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(rombicTail), "NUtil::NTypeNameTest::TRombicTail");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(castedTail), "NUtil::NTypeNameTest::TRombicTail");
+
+ UNIT_ASSERT_VALUES_EQUAL(obj.GetTypeName(), "NUtil::NTypeNameTest::TFromThis");
+#endif
+ }
+
+ Y_UNIT_TEST(FromTypeInfo) {
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(typeid(int)), "int");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(std::type_index(typeid(int))), "int");
+ }
+
+ Y_UNIT_TEST(DistinguishPointerQualifiers) {
char* simplePtr = nullptr;
const char* constPtr = nullptr;
volatile char* volatilePtr = nullptr;
const volatile char* cvPtr = nullptr;
-
-#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName(simplePtr), "char * __ptr64");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constPtr), "char const * __ptr64");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(volatilePtr), "char volatile * __ptr64");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(cvPtr), "char const volatile * __ptr64");
-#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName(simplePtr), "char*");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(constPtr), "char const*");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(volatilePtr), "char volatile*");
- UNIT_ASSERT_VALUES_EQUAL(TypeName(cvPtr), "char const volatile*");
-#endif
- }
-}
+
+#ifdef _MSC_VER
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(simplePtr), "char * __ptr64");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constPtr), "char const * __ptr64");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(volatilePtr), "char volatile * __ptr64");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(cvPtr), "char const volatile * __ptr64");
+#else
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(simplePtr), "char*");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(constPtr), "char const*");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(volatilePtr), "char volatile*");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(cvPtr), "char const volatile*");
+#endif
+ }
+}
diff --git a/util/system/ut/ya.make b/util/system/ut/ya.make
index 127e7c261e..04e9e24721 100644
--- a/util/system/ut/ya.make
+++ b/util/system/ut/ya.make
@@ -71,7 +71,7 @@ SRCS(
system/thread_ut.cpp
system/tls_ut.cpp
system/types_ut.cpp
- system/type_name_ut.cpp
+ system/type_name_ut.cpp
system/user_ut.cpp
system/unaligned_mem_ut.cpp
system/yassert_ut.cpp
diff --git a/util/ya.make b/util/ya.make
index 6ebe7e40cf..b81e175b4e 100644
--- a/util/ya.make
+++ b/util/ya.make
@@ -317,7 +317,7 @@ JOIN_SRCS(
system/thread.cpp
system/tls.cpp
system/types.cpp
- system/type_name.cpp
+ system/type_name.cpp
system/unaligned_mem.cpp
system/user.cpp
system/utime.cpp