Skip to content

Commit

Permalink
[RGT] DistroTest: Separate environment-specific test functions
Browse files Browse the repository at this point in the history
This allows using GTEST_SKIP() to identify un-executed tests.

Found by the Rotten Green Tests project.
  • Loading branch information
pogo59 committed Mar 4, 2022
1 parent 6fc11d4 commit e22e277
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions clang/unittests/Driver/DistroTest.cpp
Expand Up @@ -360,37 +360,43 @@ 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);
ASSERT_GT(CFileSystem.Count, 0U);

// 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

0 comments on commit e22e277

Please sign in to comment.