Author: amaiorano Date: Wed Dec 21 23:10:07 2016 New Revision: 290319 URL: http://llvm.org/viewvc/llvm-project?rev=290319&view=rev Log: Make FormatStyle.GetStyleOfFile test work on MSVC
Modify getStyle to use vfs::FileSystem::makeAbsolute just like FS.addFile does, rather than sys::fs::make_absolute. The latter gets the CWD from the platform, while the former expects it to be set by the client, causing a mismatch when converting relative paths to absolute. Differential Revision: https://reviews.llvm.org/D27971 Modified: cfe/trunk/lib/Format/Format.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=290319&r1=290318&r2=290319&view=diff ============================================================================== --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Wed Dec 21 23:10:07 2016 @@ -1917,7 +1917,11 @@ FormatStyle getStyle(StringRef StyleName // Look for .clang-format/_clang-format file in the file's parent directories. SmallString<128> UnsuitableConfigFiles; SmallString<128> Path(FileName); - llvm::sys::fs::make_absolute(Path); + if (std::error_code EC = FS->makeAbsolute(Path)) { + llvm::errs() << EC.message() << "\n"; + return Style; + } + for (StringRef Directory = Path; !Directory.empty(); Directory = llvm::sys::path::parent_path(Directory)) { Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=290319&r1=290318&r2=290319&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Dec 21 23:10:07 2016 @@ -10936,10 +10936,6 @@ TEST_F(FormatTest, ArrayAsTemplateType) format("auto a = unique_ptr < Foo < Bar>[10]> ;", Spaces)); } -// Since this test case uses UNIX-style file path. We disable it for MS -// compiler. -#if !defined(_MSC_VER) && !defined(__MINGW32__) - TEST(FormatStyle, GetStyleOfFile) { vfs::InMemoryFileSystem FS; // Test 1: format file in the same directory. @@ -10967,8 +10963,6 @@ TEST(FormatStyle, GetStyleOfFile) { ASSERT_EQ(Style3, getGoogleStyle()); } -#endif // _MSC_VER - TEST_F(ReplacementTest, FormatCodeAfterReplacements) { // Column limit is 20. std::string Code = "Type *a =\n" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits