From c25a2b23d2b44dd57bc94d173e4bc2a0b84d11ab Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Thu, 15 Sep 2022 08:19:52 -0700 Subject: [PATCH] Switch gtest to re2, adjust related tests (#2183) See https://github.com/google/googletest/blob/main/docs/advanced.md#regular-expression-syntax for gtest regex notes. Add framework suffix handling for includes because of a dep being triggered on macos. --- WORKSPACE | 20 +++++++++++++++++--- bazel/cc_toolchains/clang_configuration.bzl | 4 +++- common/check_test.cpp | 5 ++--- toolchain/lexer/token_kind_test.cpp | 3 ++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index ab3111529fd0..b91cd2e5b6a2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -54,16 +54,30 @@ http_archive( urls = ["https://github.com/abseil/abseil-cpp/archive/%s.tar.gz" % abseil_version], ) +############################################################################### +# RE2 libraries +############################################################################### + +# Head as of 2022-09-14. +re2_version = "cc1c9db8bf5155d89d10d65998cdb226f676492c" + +http_archive( + name = "com_googlesource_code_re2", + sha256 = "8ef976c79a300f8c5e880535665bd4ba146fb09fb6d2342f8f1a02d9af29f365", + strip_prefix = "re2-%s" % re2_version, + urls = ["https://github.com/google/re2/archive/%s.tar.gz" % re2_version], +) + ############################################################################### # GoogleTest libraries ############################################################################### -# Version as of 2021-12-07. Not a major release, but gets a clang-tidy fix. -googletest_version = "4c5650f68866e3c2e60361d5c4c95c6f335fb64b" +# Head as of 2022-09-14. +googletest_version = "1336c4b6d1a6f4bc6beebccb920e5ff858889292" http_archive( name = "com_google_googletest", - sha256 = "770e61fa13d51320736c2881ff6279212e4eab8a9100709fff8c44759f61d126", + sha256 = "d701aaeb9a258afba27210d746d971042be96c371ddc5a49f1e8914d9ea17e3c", strip_prefix = "googletest-%s" % googletest_version, urls = ["https://github.com/google/googletest/archive/%s.tar.gz" % googletest_version], ) diff --git a/bazel/cc_toolchains/clang_configuration.bzl b/bazel/cc_toolchains/clang_configuration.bzl index fb67a4ebb3c2..00e10615c3db 100644 --- a/bazel/cc_toolchains/clang_configuration.bzl +++ b/bazel/cc_toolchains/clang_configuration.bzl @@ -112,8 +112,10 @@ def _compute_clang_cpp_include_search_paths(repository_ctx, clang, sysroot): include_begin = output.index("#include <...> search starts here:") + 1 include_end = output.index("End of search list.", include_begin) + # Suffix present on framework paths. + framework_suffix = " (framework directory)" return [ - repository_ctx.path(s.lstrip(" ")) + repository_ctx.path(s.lstrip(" ").removesuffix(framework_suffix)) for s in output[include_begin:include_end] ] diff --git a/common/check_test.cpp b/common/check_test.cpp index ed2b824e8f0b..c6853150752c 100644 --- a/common/check_test.cpp +++ b/common/check_test.cpp @@ -12,11 +12,10 @@ namespace { TEST(CheckTest, CheckTrue) { CARBON_CHECK(true); } TEST(CheckTest, CheckFalse) { - // TODO: figure out why we can't use \\d+ instead of .+ in these patterns. ASSERT_DEATH({ CARBON_CHECK(false); }, "Stack trace:\n" - ".+\n" - "CHECK failure at common/check_test.cpp:.+: false\n"); + "(.|\n)+\n" + "CHECK failure at common/check_test.cpp:\\d+: false\n"); } TEST(CheckTest, CheckTrueCallbackNotUsed) { diff --git a/toolchain/lexer/token_kind_test.cpp b/toolchain/lexer/token_kind_test.cpp index c079a0d284cb..590551bde472 100644 --- a/toolchain/lexer/token_kind_test.cpp +++ b/toolchain/lexer/token_kind_test.cpp @@ -18,7 +18,8 @@ using ::testing::MatchesRegex; // We restrict symbols to punctuation characters that are expected to be widely // available on modern keyboards used for programming. -constexpr llvm::StringLiteral SymbolRegex = "[][{}!@#%^&*()/?\\|;:.,<>=+~-]+"; +constexpr llvm::StringLiteral SymbolRegex = + "[\\[\\]{}!@#%^&*()/?\\\\|;:.,<>=+~-]+"; // We restrict keywords to be lowercase ASCII letters and underscores. constexpr llvm::StringLiteral KeywordRegex = "[a-z_]+";