kadircet updated this revision to Diff 319765. kadircet added a comment. - Add tests.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95538/new/ https://reviews.llvm.org/D95538 Files: clang/lib/Format/Format.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -17861,11 +17861,17 @@ ASSERT_TRUE((bool)Style3); ASSERT_EQ(*Style3, getGoogleStyle()); - // Test 4: error on invalid fallback style + // Test 4.1: error on invalid fallback style auto Style4 = getStyle("file", "a.h", "KungFu", "", &FS); ASSERT_FALSE((bool)Style4); llvm::consumeError(Style4.takeError()); + // Test 4.2: don't error on invalid fallback style, if it is not going to be + // used. + Style4 = getStyle("file", "/a/a.h", "KungFu", "", &FS); + ASSERT_TRUE((bool)Style4); + ASSERT_EQ(*Style4, getLLVMStyle()); + // Test 5: error on invalid yaml on command line auto Style5 = getStyle("{invalid_key=invalid_value}", "a.h", "LLVM", "", &FS); ASSERT_FALSE((bool)Style5); Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -2901,10 +2901,6 @@ } FormatStyle Style = getLLVMStyle(guessLanguage(FileName, Code)); - FormatStyle FallbackStyle = getNoStyle(); - if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle)) - return make_string_error("Invalid fallback style \"" + FallbackStyleName); - if (StyleName.startswith("{")) { // Parse YAML/JSON style from the command line. if (std::error_code ec = parseConfiguration( @@ -2974,6 +2970,10 @@ return make_string_error("Configuration file(s) do(es) not support " + getLanguageName(Style.Language) + ": " + UnsuitableConfigFiles); + + FormatStyle FallbackStyle = getNoStyle(); + if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle)) + return make_string_error("Invalid fallback style \"" + FallbackStyleName); return FallbackStyle; }
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -17861,11 +17861,17 @@ ASSERT_TRUE((bool)Style3); ASSERT_EQ(*Style3, getGoogleStyle()); - // Test 4: error on invalid fallback style + // Test 4.1: error on invalid fallback style auto Style4 = getStyle("file", "a.h", "KungFu", "", &FS); ASSERT_FALSE((bool)Style4); llvm::consumeError(Style4.takeError()); + // Test 4.2: don't error on invalid fallback style, if it is not going to be + // used. + Style4 = getStyle("file", "/a/a.h", "KungFu", "", &FS); + ASSERT_TRUE((bool)Style4); + ASSERT_EQ(*Style4, getLLVMStyle()); + // Test 5: error on invalid yaml on command line auto Style5 = getStyle("{invalid_key=invalid_value}", "a.h", "LLVM", "", &FS); ASSERT_FALSE((bool)Style5); Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -2901,10 +2901,6 @@ } FormatStyle Style = getLLVMStyle(guessLanguage(FileName, Code)); - FormatStyle FallbackStyle = getNoStyle(); - if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle)) - return make_string_error("Invalid fallback style \"" + FallbackStyleName); - if (StyleName.startswith("{")) { // Parse YAML/JSON style from the command line. if (std::error_code ec = parseConfiguration( @@ -2974,6 +2970,10 @@ return make_string_error("Configuration file(s) do(es) not support " + getLanguageName(Style.Language) + ": " + UnsuitableConfigFiles); + + FormatStyle FallbackStyle = getNoStyle(); + if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle)) + return make_string_error("Invalid fallback style \"" + FallbackStyleName); return FallbackStyle; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits