From 949820eabd15a0e61ba9d530ca2fb14bda236b09 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 19 Jul 2013 14:41:25 +0000 Subject: [PATCH] Add a unit test for checking that we respect the F_Binary flag. llvm-svn: 186676 --- unittests/Support/Path.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index 0bbaa2fe274..b6c1dd80c2b 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -10,6 +10,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" @@ -356,6 +357,36 @@ TEST_F(FileSystemTest, Magic) { } } +#ifdef LLVM_ON_WIN32 +TEST_F(FileSystemTest, CarriageReturn) { + SmallString<128> FilePathname(TestDirectory); + std::string ErrMsg; + path::append(FilePathname, "test"); + + { + raw_fd_ostream File(FilePathname.c_str(), ErrMsg); + EXPECT_EQ(ErrMsg, ""); + File << '\n'; + } + { + OwningPtr Buf; + MemoryBuffer::getFile(FilePathname, Buf); + EXPECT_EQ(Buf->getBuffer(), "\r\n"); + } + + { + raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_Binary); + EXPECT_EQ(ErrMsg, ""); + File << '\n'; + } + { + OwningPtr Buf; + MemoryBuffer::getFile(FilePathname, Buf); + EXPECT_EQ(Buf->getBuffer(), "\n"); + } +} +#endif + TEST_F(FileSystemTest, FileMapping) { // Create a temp file. int FileDescriptor;