[unittests] [DWARF] Generalize path separator expectations
authorMartin Storsjö <martin@martin.st>
Thu, 7 Oct 2021 11:31:32 +0000 (11:31 +0000)
committerMartin Storsjö <martin@martin.st>
Fri, 5 Nov 2021 19:50:43 +0000 (21:50 +0200)
This fixes unit tests if running on Windows with a build configured
to prefer forward slashes.

Differential Revision: https://reviews.llvm.org/D113257

llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp

index d40bf64..82aaa45 100644 (file)
@@ -183,11 +183,9 @@ TEST(DWARFDie, getDeclFile) {
   std::string DeclFile = MainDie.getDeclFile(
       DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath);
 
-#if defined(_WIN32)
-  EXPECT_EQ(DeclFile, "/tmp\\main.cpp");
-#else
-  EXPECT_EQ(DeclFile, "/tmp/main.cpp");
-#endif
+  std::string Ref =
+      ("/tmp" + llvm::sys::path::get_separator() + "main.cpp").str();
+  EXPECT_EQ(DeclFile, Ref);
 }
 
 TEST(DWARFDie, getDeclFileAbstractOrigin) {
@@ -291,11 +289,9 @@ TEST(DWARFDie, getDeclFileAbstractOrigin) {
   std::string DeclFile = MainDie.getDeclFile(
       DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath);
 
-#if defined(_WIN32)
-  EXPECT_EQ(DeclFile, "/tmp\\main.cpp");
-#else
-  EXPECT_EQ(DeclFile, "/tmp/main.cpp");
-#endif
+  std::string Ref =
+      ("/tmp" + llvm::sys::path::get_separator() + "main.cpp").str();
+  EXPECT_EQ(DeclFile, Ref);
 }
 
 TEST(DWARFDie, getDeclFileSpecification) {
@@ -398,11 +394,9 @@ TEST(DWARFDie, getDeclFileSpecification) {
   std::string DeclFile = MainDie.getDeclFile(
       DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath);
 
-#if defined(_WIN32)
-  EXPECT_EQ(DeclFile, "/tmp\\main.cpp");
-#else
-  EXPECT_EQ(DeclFile, "/tmp/main.cpp");
-#endif
+  std::string Ref =
+      ("/tmp" + llvm::sys::path::get_separator() + "main.cpp").str();
+  EXPECT_EQ(DeclFile, Ref);
 }
 
 TEST(DWARFDie, getDeclFileAbstractOriginAcrossCUBoundary) {
@@ -522,11 +516,9 @@ TEST(DWARFDie, getDeclFileAbstractOriginAcrossCUBoundary) {
   std::string DeclFile = MainDie.getDeclFile(
       DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath);
 
-#if defined(_WIN32)
-  EXPECT_EQ(DeclFile, "/tmp\\main.cpp");
-#else
-  EXPECT_EQ(DeclFile, "/tmp/main.cpp");
-#endif
+  std::string Ref =
+      ("/tmp" + llvm::sys::path::get_separator() + "main.cpp").str();
+  EXPECT_EQ(DeclFile, Ref);
 }
 
 TEST(DWARFDie, getDeclFileSpecificationAcrossCUBoundary) {
@@ -646,11 +638,9 @@ TEST(DWARFDie, getDeclFileSpecificationAcrossCUBoundary) {
   std::string DeclFile = MainDie.getDeclFile(
       DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath);
 
-#if defined(_WIN32)
-  EXPECT_EQ(DeclFile, "/tmp\\main.cpp");
-#else
-  EXPECT_EQ(DeclFile, "/tmp/main.cpp");
-#endif
+  std::string Ref =
+      ("/tmp" + llvm::sys::path::get_separator() + "main.cpp").str();
+  EXPECT_EQ(DeclFile, Ref);
 }
 
 } // end anonymous namespace