Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix abort_test for limited Windows regex. Refs mesonbuild/wrapdb#1611 #2305

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions hwy/abort_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "hwy/abort.h"

#include <stdio.h>

#include <string>

#include "hwy/base.h"
Expand All @@ -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,
Expand All @@ -55,7 +58,9 @@ TEST(AbortTest, AbortOverrideChain) {
fprintf(stderr, "%s from %d of %s", formatted_err, line, file);
};

HWY_ASSERT(SetAbortFunc(FirstHandler) == nullptr);
// Do not check that the first SetAbortFunc returns nullptr, because it is
// not guaranteed to be the first call - other TEST may come first.
(void)SetAbortFunc(FirstHandler);
HWY_ASSERT(GetAbortFunc() == FirstHandler);
HWY_ASSERT(SetAbortFunc(SecondHandler) == FirstHandler);
HWY_ASSERT(GetAbortFunc() == SecondHandler);
Expand Down
Loading