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.
This commit is contained in:
Jack Grigg 2022-03-28 19:35:59 +00:00
parent 0daa540128
commit 8b68d73802
2 changed files with 22 additions and 1 deletions

View File

@ -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 <sodium.h>
#include <tracing.h>
const std::function<std::string(const char*)> 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

View File

@ -27,6 +27,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/thread.hpp>
#include <sodium.h>
#include <tracing.h>
#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();