llvm.org GIT mirror llvm / 9ecd610
Revert "MemoryBuffer: Add a missing error-check to getOpenFileImpl" This reverts commit r368977 because it broke a couple of tests in lldb. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369027 91177308-0d34-0410-b5e6-96231b3b80d8 Pavel Labath a month ago
2 changed file(s) with 1 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
457457 return make_error_code(errc::not_enough_memory);
458458 }
459459
460 if (std::error_code EC =
461 sys::fs::readNativeFileSlice(FD, Buf->getBuffer(), Offset))
462 return EC;
460 sys::fs::readNativeFileSlice(FD, Buf->getBuffer(), Offset);
463461
464462 return std::move(Buf);
465463 }
1010 //===----------------------------------------------------------------------===//
1111
1212 #include "llvm/Support/MemoryBuffer.h"
13 #include "llvm/ADT/ScopeExit.h"
1413 #include "llvm/Support/FileSystem.h"
1514 #include "llvm/Support/FileUtilities.h"
1615 #include "llvm/Support/raw_ostream.h"
1817 #include "gtest/gtest.h"
1918
2019 using namespace llvm;
21
22 #define ASSERT_NO_ERROR(x) \
23 if (std::error_code ASSERT_NO_ERROR_ec = x) { \
24 SmallString<128> MessageStorage; \
25 raw_svector_ostream Message(MessageStorage); \
26 Message << #x ": did not return errc::success.\n" \
27 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
28 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
29 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
30 } else { \
31 }
32
33 #define ASSERT_ERROR(x) \
34 if (!x) { \
35 SmallString<128> MessageStorage; \
36 raw_svector_ostream Message(MessageStorage); \
37 Message << #x ": did not return a failure error code.\n"; \
38 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
39 }
4020
4121 namespace {
4222
8262 MB2.reset();
8363 MB3.reset();
8464 EXPECT_EQ("this is some data", data);
85 }
86
87 TEST_F(MemoryBufferTest, getOpenFile) {
88 int FD;
89 SmallString<64> TestPath;
90 ASSERT_EQ(sys::fs::createTemporaryFile("MemoryBufferTest_getOpenFile", "temp",
91 FD, TestPath),
92 std::error_code());
93
94 FileRemover Cleanup(TestPath);
95 raw_fd_ostream OF(FD, /*shouldClose*/ true);
96 OF << "12345678";
97 OF.close();
98
99 {
100 Expected File = sys::fs::openNativeFileForRead(TestPath);
101 ASSERT_THAT_EXPECTED(File, Succeeded());
102 auto OnExit =
103 make_scope_exit([&] { ASSERT_NO_ERROR(sys::fs::closeFile(*File)); });
104 ErrorOr MB = MemoryBuffer::getOpenFile(*File, TestPath, 6);
105 ASSERT_NO_ERROR(MB.getError());
106 EXPECT_EQ("123456", MB.get()->getBuffer());
107 }
108 {
109 Expected File = sys::fs::openNativeFileForWrite(
110 TestPath, sys::fs::CD_OpenExisting, sys::fs::OF_None);
111 ASSERT_THAT_EXPECTED(File, Succeeded());
112 auto OnExit =
113 make_scope_exit([&] { ASSERT_NO_ERROR(sys::fs::closeFile(*File)); });
114 ASSERT_ERROR(MemoryBuffer::getOpenFile(*File, TestPath, 6).getError());
115 }
11665 }
11766
11867 TEST_F(MemoryBufferTest, NullTerminator4K) {