[unittests] Use GTEST_SKIP() instead of return when appropriate
authorPaul Robinson <paul.robinson@sony.com>
Thu, 26 Jan 2023 15:47:37 +0000 (07:47 -0800)
committerPaul Robinson <paul.robinson@sony.com>
Thu, 26 Jan 2023 16:40:38 +0000 (08:40 -0800)
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()).

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

index 03616d7..5060301 100644 (file)
@@ -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);
index 068c583..4ddeada 100644 (file)
@@ -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());
index f54c655..6983a53 100644 (file)
@@ -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();