aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/tempfile_ut.cpp
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
commit918e8a1574070d0ec733f0b76cfad8f8892ad2e5 (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/system/tempfile_ut.cpp
parent7b1cfa32681104c8468c5824c79fd80d9a88a579 (diff)
downloadydb-918e8a1574070d0ec733f0b76cfad8f8892ad2e5.tar.gz
Restoring authorship annotation for <gleb-kov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system/tempfile_ut.cpp')
-rw-r--r--util/system/tempfile_ut.cpp262
1 files changed, 131 insertions, 131 deletions
diff --git a/util/system/tempfile_ut.cpp b/util/system/tempfile_ut.cpp
index 3b9ad5fc50..e4a0923d0b 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(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_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));
- }
-}