From f0efe647de18ac5c74545a20c13da131bb1fa6b5 Mon Sep 17 00:00:00 2001 From: Jan Wassenberg Date: Tue, 13 Aug 2024 22:52:51 -0700 Subject: [PATCH] fix abort_test for limited Windows regex. Refs mesonbuild/wrapdb#1611 PiperOrigin-RevId: 662785270 --- hwy/abort_test.cc | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/hwy/abort_test.cc b/hwy/abort_test.cc index 38835b52c9..38892a64f8 100644 --- a/hwy/abort_test.cc +++ b/hwy/abort_test.cc @@ -4,6 +4,8 @@ #include "hwy/abort.h" +#include + #include #include "hwy/base.h" @@ -27,23 +29,24 @@ TEST(AbortDeathTest, AbortDefault) { } TEST(AbortDeathTest, AbortOverride) { - std::string expected = - std::string("Test Abort from [0-9]+ of ") + GetBaseName(__FILE__); - - ASSERT_DEATH( - { - AbortFunc CustomAbortHandler = [](const char* file, int line, + const AbortFunc CustomAbortHandler = [](const char* file, int line, const char* formatted_err) -> void { - fprintf(stderr, "%s from %d of %s", formatted_err, line, - GetBaseName(file).data()); - }; + fprintf(stderr, "%s from %02d of %s", formatted_err, line, + GetBaseName(file).data()); + }; + + SetAbortFunc(CustomAbortHandler); - SetAbortFunc(CustomAbortHandler); - HWY_ABORT("Test %s", "Abort"); - }, - expected); + // googletest regex does not support `+` for digits on Windows?! + // https://google.github.io/googletest/advanced.html#regular-expression-syntax + // Hence we insert the expected line number manually. + char buf[100]; + const std::string file = GetBaseName(__FILE__); + const int line = __LINE__ + 2; // from which HWY_ABORT is called + snprintf(buf, sizeof(buf), "Test Abort from %02d of %s", line, file.c_str()); + ASSERT_DEATH({ HWY_ABORT("Test %s", "Abort"); }, buf); } -#endif +#endif // GTEST_HAS_DEATH_TEST TEST(AbortTest, AbortOverrideChain) { AbortFunc FirstHandler = [](const char* file, int line,