[RGT] DistroTest: Separate environment-specific test functions
authorPaul Robinson <paul.robinson@sony.com>
Thu, 17 Feb 2022 18:36:17 +0000 (10:36 -0800)
committerPaul Robinson <paul.robinson@sony.com>
Fri, 4 Mar 2022 20:28:38 +0000 (12:28 -0800)
This allows using GTEST_SKIP() to identify un-executed tests.

Found by the Rotten Green Tests project.

clang/unittests/Driver/DistroTest.cpp

index b6e4ca9..ebf75dc 100644 (file)
@@ -360,16 +360,17 @@ TEST(DistroTest, DetectWindowsAndCrossCompile) {
     unsigned Count{};
   };
 
+  llvm::Triple Host(llvm::sys::getProcessTriple());
+  if (!Host.isOSWindows())
+    GTEST_SKIP();
+
   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> RFS =
       llvm::vfs::getRealFileSystem();
-  llvm::Triple Host(llvm::sys::getProcessTriple());
 
   CountingFileSystem CFileSystem;
   Distro LinuxDistro{CFileSystem, llvm::Triple("unknown-pc-linux")};
-  if (Host.isOSWindows()) {
-    ASSERT_EQ(Distro(Distro::UnknownDistro), LinuxDistro);
-    ASSERT_GT(CFileSystem.Count, 0U);
-  }
+  ASSERT_EQ(Distro(Distro::UnknownDistro), LinuxDistro);
+  ASSERT_GT(CFileSystem.Count, 0U);
 
   Distro WinDistro{CFileSystem, llvm::Triple("unknown-pc-windows")};
   ASSERT_EQ(Distro(Distro::UnknownDistro), WinDistro);
@@ -377,20 +378,25 @@ TEST(DistroTest, DetectWindowsAndCrossCompile) {
 
   // When running on Windows along with a real file system, ensure that no
   // distro is returned if targeting Linux
-  if (Host.isOSWindows()) {
-    Distro LinuxRealDistro{*RFS, llvm::Triple("unknown-pc-linux")};
-    ASSERT_EQ(Distro(Distro::UnknownDistro), LinuxRealDistro);
-  }
-  // When running on Linux, check if the distro is the same as the host when
-  // targeting Linux
-  if (Host.isOSLinux()) {
-    Distro HostDistro{*RFS, Host};
-    Distro LinuxRealDistro{*RFS, llvm::Triple("unknown-pc-linux")};
-    ASSERT_EQ(HostDistro, LinuxRealDistro);
-  }
+  Distro LinuxRealDistro{*RFS, llvm::Triple("unknown-pc-linux")};
+  ASSERT_EQ(Distro(Distro::UnknownDistro), LinuxRealDistro);
 
   Distro WinRealDistro{*RFS, llvm::Triple("unknown-pc-windows")};
   ASSERT_EQ(Distro(Distro::UnknownDistro), WinRealDistro);
 }
 
+TEST(DistroTest, DetectLinux) {
+  llvm::Triple Host(llvm::sys::getProcessTriple());
+  if (!Host.isOSLinux())
+    GTEST_SKIP();
+
+  // When running on Linux, check if the distro is the same as the host when
+  // targeting Linux
+  llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> RFS =
+      llvm::vfs::getRealFileSystem();
+  Distro HostDistro{*RFS, Host};
+  Distro LinuxRealDistro{*RFS, llvm::Triple("unknown-pc-linux")};
+  ASSERT_EQ(HostDistro, LinuxRealDistro);
+}
+
 } // end anonymous namespace