From 4c417877648f5f240aecead1c19d7c1fd340423b Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Tue, 10 Jul 2018 14:30:42 -0400 Subject: Adds stacktrace support from Abseil to Google Test This change adds the ability to generate stacktraces in Google Test on both failures of assertions/expectations and on crashes. The stacktrace support is conditionally available only when using Abseil with Google Test. To use this support, run the test under Bazel with a command like this: bazel test --define absl=1 --test_env=GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1 //path/to/your:test The "--define absl=1" part enables stacktraces on assertion/expectation failures. The "--test_env=GTEST_INSTALL_FAILURE_SIGNAL_HANDLER=1" part enables the signal handler that logs a stacktrace in the event of a crash (this also requires the "--define absl=1" part). This is not the default since it may interfere with existing tests. --- BUILD.bazel | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'BUILD.bazel') diff --git a/BUILD.bazel b/BUILD.bazel index 6d828294..2ed3bf62 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -38,7 +38,7 @@ licenses(["notice"]) config_setting( name = "windows", - values = { "cpu": "x64_windows" }, + values = {"cpu": "x64_windows"}, ) config_setting( @@ -51,7 +51,6 @@ config_setting( values = {"define": "absl=1"}, ) - # Google Test including Google Mock cc_library( name = "gtest", @@ -70,7 +69,7 @@ cc_library( "googlemock/src/gmock_main.cc", ], ), - hdrs =glob([ + hdrs = glob([ "googletest/include/gtest/*.h", "googlemock/include/gmock/*.h", ]), @@ -81,6 +80,14 @@ cc_library( "//conditions:default": ["-pthread"], }, ), + defines = select( + { + ":has_absl": [ + "GTEST_HAS_ABSL=1", + ], + "//conditions:default": [], + }, + ), includes = [ "googlemock", "googlemock/include", @@ -94,21 +101,18 @@ cc_library( "-pthread", ], }), - defines = select ({ - ":has_absl": [ - "GTEST_HAS_ABSL=1", - ], - "//conditions:default": [], - } + deps = select( + { + ":has_absl": [ + "@com_google_absl//absl/debugging:failure_signal_handler", + "@com_google_absl//absl/debugging:stacktrace", + "@com_google_absl//absl/debugging:symbolize", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/types:optional", + ], + "//conditions:default": [], + }, ), - deps = select ({ - ":has_absl": [ - "@com_google_absl//absl/types:optional", - "@com_google_absl//absl/strings" - ], - "//conditions:default": [], - } - ) ) cc_library( -- cgit v1.2.3