[sanitizer] Fix test on Windows
authorVitaly Buka <vitalybuka@google.com>
Tue, 12 Oct 2021 22:33:21 +0000 (15:33 -0700)
committerVitaly Buka <vitalybuka@google.com>
Tue, 12 Oct 2021 22:38:37 +0000 (15:38 -0700)
compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp

index 9f6b134..4185285 100644 (file)
@@ -11,6 +11,8 @@
 //===----------------------------------------------------------------------===//
 #include "sanitizer_common/sanitizer_stackdepot.h"
 
+#include <regex>
+
 #include "gtest/gtest.h"
 #include "sanitizer_common/sanitizer_internal_defs.h"
 #include "sanitizer_common/sanitizer_libc.h"
@@ -73,11 +75,19 @@ TEST(SanitizerCommon, StackDepotPrint) {
   StackTrace s2(array2, ARRAY_SIZE(array2));
   u32 i2 = StackDepotPut(s2);
   EXPECT_NE(i1, i2);
-  EXPECT_EXIT((StackDepotPrintAll(), exit(0)), ::testing::ExitedWithCode(0),
-              "Stack for id .*#0 0x1.*#1 0x2.*#2 0x3.*#3 0x4.*#4 0x7.*");
+
+  auto fix_regex = [](const std::string& s) -> std::string {
+    if (!SANITIZER_WINDOWS)
+      return s;
+    return std::regex_replace(s, std::regex("\\.\\*"), ".*\\n.*");
+  };
+  EXPECT_EXIT(
+      (StackDepotPrintAll(), exit(0)), ::testing::ExitedWithCode(0),
+      fix_regex("Stack for id .*#0 0x1.*#1 0x2.*#2 0x3.*#3 0x4.*#4 0x7.*"));
   EXPECT_EXIT(
       (StackDepotPrintAll(), exit(0)), ::testing::ExitedWithCode(0),
-      "Stack for id .*#0 0x1.*#1 0x2.*#2 0x3.*#3 0x4.*#4 0x8.*#5 0x9.*");
+      fix_regex(
+          "Stack for id .*#0 0x1.*#1 0x2.*#2 0x3.*#3 0x4.*#4 0x8.*#5 0x9.*"));
 }
 
 TEST(SanitizerCommon, StackDepotPrintNoLock) {