From 8b68d7380209c7bd69e87511b8915d2e3ee72134 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 28 Mar 2022 19:35:59 +0000 Subject: [PATCH] test: Print all logged errors to stdout during gtests This makes it easier to figure out test failures caused by errors on the Rust side, for which we generally log the error and then return a simple failure condition (`false` or `nullptr`) which obscures the error on the C++ side. We add similar logic to the Boost test framework, but commented out by default because it results in very verbose test output. --- src/gtest/main.cpp | 9 +++++++++ src/test/test_bitcoin.cpp | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gtest/main.cpp b/src/gtest/main.cpp index 3caecf851..851b110ac 100644 --- a/src/gtest/main.cpp +++ b/src/gtest/main.cpp @@ -1,4 +1,5 @@ #include "gmock/gmock.h" +#include "init.h" #include "key.h" #include "pubkey.h" #include "util.h" @@ -6,6 +7,7 @@ #include "librustzcash.h" #include +#include const std::function G_TRANSLATION_FUN = nullptr; @@ -20,6 +22,13 @@ int main(int argc, char **argv) { assert(sodium_init() != -1); ECC_Start(); + // Log all errors to stdout so we see them in test output. + std::string initialFilter = "error"; + pTracingHandle = tracing_init( + nullptr, 0, + initialFilter.c_str(), + false); + testing::InitGoogleMock(&argc, argv); // The "threadsafe" style is necessary for correct operation of death/exit diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index f3360fe19..a1fb0f2d7 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "librustzcash.h" @@ -74,7 +75,18 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName) ECC_Start(); SetupEnvironment(); SetupNetworking(); - fPrintToDebugLog = false; // don't want to write to debug.log file + + // Uncomment this to log all errors to stdout so we see them in test output. + // We don't enable this by default because several tests intentionally cause + // verbose error output (while exercising failure cases). + // if (pTracingHandle == nullptr) { + // std::string initialFilter = "error"; + // pTracingHandle = tracing_init( + // nullptr, 0, + // initialFilter.c_str(), + // false); + // } + fCheckBlockIndex = true; SelectParams(chainName); noui_connect();