[clang] 787876b - [unittests] Use GTEST_SKIP() instead of return when appropriate

Paul Robinson via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 26 08:40:49 PST 2023


Author: Paul Robinson
Date: 2023-01-26T08:40:38-08:00
New Revision: 787876b0d592a6b4e87d00a0adb89ce87dfc11cd

URL: https://github.com/llvm/llvm-project/commit/787876b0d592a6b4e87d00a0adb89ce87dfc11cd
DIFF: https://github.com/llvm/llvm-project/commit/787876b0d592a6b4e87d00a0adb89ce87dfc11cd.diff

LOG: [unittests] Use GTEST_SKIP() instead of return when appropriate

Basically NFC: A TEST/TEST_F/etc that bails out early (usually because
setup failed or some other runtime condition wasn't met) generally
should use GTEST_SKIP() to report its status correctly, unless it
takes steps to report another status (e.g., FAIL()).

Added: 
    

Modified: 
    clang/unittests/AST/StructuralEquivalenceTest.cpp
    clang/unittests/Driver/ToolChainTest.cpp
    clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 03616d7197ea8..5060301527ac7 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -460,7 +460,7 @@ TEST_F(StructuralEquivalenceFunctionTest,
   // These attributes may not be available on certain platforms.
   if (llvm::Triple(llvm::sys::getDefaultTargetTriple()).getArch() !=
       llvm::Triple::x86_64)
-    return;
+    GTEST_SKIP();
   auto t = makeNamedDecls("__attribute__((preserve_all)) void foo();",
                           "__attribute__((ms_abi))   void foo();", Lang_C99);
   EXPECT_FALSE(testStructuralMatch(t));
@@ -469,7 +469,7 @@ TEST_F(StructuralEquivalenceFunctionTest,
 TEST_F(StructuralEquivalenceFunctionTest, FunctionsWithDifferentSavedRegsAttr) {
   if (llvm::Triple(llvm::sys::getDefaultTargetTriple()).getArch() !=
       llvm::Triple::x86_64)
-    return;
+    GTEST_SKIP();
   auto t = makeNamedDecls(
       "__attribute__((no_caller_saved_registers)) void foo();",
       "                                           void foo();", Lang_C99);

diff  --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp
index 068c583eb89b5..4ddeadac2103f 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -243,7 +243,7 @@ TEST(ToolChainTest, GetTargetAndMode) {
   llvm::InitializeAllTargets();
   std::string IgnoredError;
   if (!llvm::TargetRegistry::lookupTarget("x86_64", IgnoredError))
-    return;
+    GTEST_SKIP();
 
   ParsedClangName Res = ToolChain::getTargetAndModeFromProgramName("clang");
   EXPECT_TRUE(Res.TargetPrefix.empty());

diff  --git a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index f54c65568a66c..6983a532c7315 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -57,7 +57,7 @@ TEST(InterpreterTest, CatchException) {
       // Using llvm::consumeError will require typeinfo for ErrorInfoBase, we
       // can avoid that by going via the C interface.
       LLVMConsumeError(llvm::wrap(J.takeError()));
-      return;
+      GTEST_SKIP();
     }
   }
 
@@ -102,16 +102,16 @@ extern "C" int throw_exception() {
 
   // AIX is unsupported.
   if (Triple.isOSAIX())
-    return;
+    GTEST_SKIP();
 
   // FIXME: ARM fails due to `Not implemented relocation type!`
   if (Triple.isARM())
-    return;
+    GTEST_SKIP();
 
   // FIXME: libunwind on darwin is broken, see PR49692.
   if (Triple.isOSDarwin() && (Triple.getArch() == llvm::Triple::aarch64 ||
                               Triple.getArch() == llvm::Triple::aarch64_32))
-    return;
+    GTEST_SKIP();
 
   llvm::cantFail(Interp->ParseAndExecute(ExceptionCode));
   testing::internal::CaptureStdout();


        


More information about the cfe-commits mailing list