[clang] e22e277 - [RGT] DistroTest: Separate environment-specific test functions

Paul Robinson via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 4 12:28:47 PST 2022


Author: Paul Robinson
Date: 2022-03-04T12:28:38-08:00
New Revision: e22e2774d93379d6bad41ae20194b076fdb44915

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

LOG: [RGT] DistroTest: Separate environment-specific test functions

This allows using GTEST_SKIP() to identify un-executed tests.

Found by the Rotten Green Tests project.

Added: 
    

Modified: 
    clang/unittests/Driver/DistroTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/unittests/Driver/DistroTest.cpp b/clang/unittests/Driver/DistroTest.cpp
index b6e4ca9be8579..ebf75dc7ce3a6 100644
--- a/clang/unittests/Driver/DistroTest.cpp
+++ b/clang/unittests/Driver/DistroTest.cpp
@@ -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


        


More information about the cfe-commits mailing list