[lld] r332114 - [MachO] Don't write test files to /tmp, remove them afterwards.

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Fri May 11 11:19:03 PDT 2018


Author: mstorsjo
Date: Fri May 11 11:19:02 2018
New Revision: 332114

URL: http://llvm.org/viewvc/llvm-project?rev=332114&view=rev
Log:
[MachO] Don't write test files to /tmp, remove them afterwards.

This matches what is done in MachONormalizedFileBinaryWriterTests.cpp
already.

Differential Revision: https://reviews.llvm.org/D46743

Modified:
    lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp

Modified: lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp?rev=332114&r1=332113&r2=332114&view=diff
==============================================================================
--- lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp (original)
+++ lld/trunk/unittests/MachOTests/MachONormalizedFileBinaryReaderTests.cpp Fri May 11 11:19:02 2018
@@ -12,14 +12,17 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "gtest/gtest.h"
 #include <cstdint>
 #include <memory>
 
+using llvm::SmallString;
 using llvm::StringRef;
 using llvm::MemoryBuffer;
+using llvm::Twine;
 
 using namespace lld::mach_o::normalized;
 using namespace llvm::MachO;
@@ -741,9 +744,11 @@ TEST(BinaryReaderTest, hello_obj_ppc) {
   EXPECT_EQ(printfLabel.type, N_UNDF);
   EXPECT_EQ(printfLabel.scope, SymbolScope(N_EXT));
 
-  auto ec = writeBinary(*f, "/tmp/foo.o");
-  // FIXME: We want to do EXPECT_FALSE(ec) but that fails on some Windows bots,
-  // probably due to /tmp not being available.
-  // For now just consume the error without checking it.
-  consumeError(std::move(ec));
+  SmallString<128> tmpFl;
+  std::error_code ec =
+      llvm::sys::fs::createTemporaryFile(Twine("xx"), "o", tmpFl);
+  EXPECT_FALSE(ec);
+  llvm::Error ec2 = writeBinary(*f, tmpFl);
+  EXPECT_FALSE(ec2);
+  llvm::sys::fs::remove(tmpFl);
 }




More information about the llvm-commits mailing list