Skip to content

Commit cba5120

Browse files
authored
refactor: Clean up test logging to make it easier to search (#5396)
This PR replaces the word `failed` with `failure` in any test names and renames some test files to fix MSVC warnings, so that it is easier to search through the test output to find tests that failed.
1 parent 1c99ea2 commit cba5120

File tree

9 files changed

+33
-12
lines changed

9 files changed

+33
-12
lines changed

src/test/app/AMM_test.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <test/jtx.h>
2121
#include <test/jtx/AMM.h>
2222
#include <test/jtx/AMMTest.h>
23+
#include <test/jtx/CaptureLogs.h>
2324
#include <test/jtx/amount.h>
2425
#include <test/jtx/sendmax.h>
2526

@@ -6079,6 +6080,8 @@ struct AMM_test : public jtx::AMMTest
60796080
testcase("Fix changeSpotPriceQuality");
60806081
using namespace jtx;
60816082

6083+
std::string logs;
6084+
60826085
enum class Status {
60836086
SucceedShouldSucceedResize, // Succeed in pre-fix because
60846087
// error allowance, succeed post-fix
@@ -6161,7 +6164,7 @@ struct AMM_test : public jtx::AMMTest
61616164
boost::smatch match;
61626165
// tests that succeed should have the same amounts pre-fix and post-fix
61636166
std::vector<std::pair<STAmount, STAmount>> successAmounts;
6164-
Env env(*this, features);
6167+
Env env(*this, features, std::make_unique<CaptureLogs>(&logs));
61656168
auto rules = env.current()->rules();
61666169
CurrentTransactionRulesGuard rg(rules);
61676170
for (auto const& t : tests)
@@ -6355,6 +6358,8 @@ struct AMM_test : public jtx::AMMTest
63556358
using namespace std::chrono;
63566359
FeatureBitset const all{features};
63576360

6361+
std::string logs;
6362+
63586363
Account const gatehub{"gatehub"};
63596364
Account const bitstamp{"bitstamp"};
63606365
Account const trader{"trader"};
@@ -6583,7 +6588,7 @@ struct AMM_test : public jtx::AMMTest
65836588
for (auto const& features :
65846589
{all - fixAMMOverflowOffer, all | fixAMMOverflowOffer})
65856590
{
6586-
Env env(*this, features);
6591+
Env env(*this, features, std::make_unique<CaptureLogs>(&logs));
65876592

65886593
env.fund(XRP(5'000), gatehub, bitstamp, trader);
65896594
env.close();

src/test/app/DepositAuth_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ struct DepositPreauth_test : public beast::unit_test::suite
828828
Account const john{"john"};
829829

830830
{
831-
testcase("Payment failed with disabled credentials rule.");
831+
testcase("Payment failure with disabled credentials rule.");
832832

833833
Env env(*this, supported_amendments() - featureCredentials);
834834

@@ -930,7 +930,7 @@ struct DepositPreauth_test : public beast::unit_test::suite
930930
}
931931

932932
{
933-
testcase("Payment failed with invalid credentials.");
933+
testcase("Payment failure with invalid credentials.");
934934

935935
Env env(*this);
936936

@@ -1206,7 +1206,7 @@ struct DepositPreauth_test : public beast::unit_test::suite
12061206
Account const zelda{"zelda"};
12071207

12081208
{
1209-
testcase("Payment failed with expired credentials.");
1209+
testcase("Payment failure with expired credentials.");
12101210

12111211
Env env(*this);
12121212

@@ -1353,7 +1353,7 @@ struct DepositPreauth_test : public beast::unit_test::suite
13531353
{
13541354
using namespace std::chrono;
13551355

1356-
testcase("Escrow failed with expired credentials.");
1356+
testcase("Escrow failure with expired credentials.");
13571357

13581358
Env env(*this);
13591359

src/test/jtx/Env.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ class Env
210210
* @param args collection of features
211211
*
212212
*/
213-
Env(beast::unit_test::suite& suite_, FeatureBitset features)
214-
: Env(suite_, envconfig(), features)
213+
Env(beast::unit_test::suite& suite_,
214+
FeatureBitset features,
215+
std::unique_ptr<Logs> logs = nullptr)
216+
: Env(suite_, envconfig(), features, std::move(logs))
215217
{
216218
}
217219

src/test/rpc/DepositAuthorized_test.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class DepositAuthorized_test : public beast::unit_test::suite
6565
void
6666
testValid()
6767
{
68+
testcase("Valid");
6869
using namespace jtx;
6970
Account const alice{"alice"};
7071
Account const becky{"becky"};
@@ -162,6 +163,7 @@ class DepositAuthorized_test : public beast::unit_test::suite
162163
void
163164
testErrors()
164165
{
166+
testcase("Errors");
165167
using namespace jtx;
166168
Account const alice{"alice"};
167169
Account const becky{"becky"};
@@ -333,6 +335,8 @@ class DepositAuthorized_test : public beast::unit_test::suite
333335
void
334336
testCredentials()
335337
{
338+
testcase("Credentials");
339+
336340
using namespace jtx;
337341

338342
const char credType[] = "abcde";
@@ -363,7 +367,7 @@ class DepositAuthorized_test : public beast::unit_test::suite
363367

364368
{
365369
testcase(
366-
"deposit_authorized with credentials failed: empty array.");
370+
"deposit_authorized with credentials failure: empty array.");
367371

368372
auto args = depositAuthArgs(alice, becky, "validated");
369373
args[jss::credentials] = Json::arrayValue;
@@ -376,7 +380,7 @@ class DepositAuthorized_test : public beast::unit_test::suite
376380

377381
{
378382
testcase(
379-
"deposit_authorized with credentials failed: not a string "
383+
"deposit_authorized with credentials failure: not a string "
380384
"credentials");
381385

382386
auto args = depositAuthArgs(alice, becky, "validated");
@@ -392,7 +396,7 @@ class DepositAuthorized_test : public beast::unit_test::suite
392396

393397
{
394398
testcase(
395-
"deposit_authorized with credentials failed: not a hex string "
399+
"deposit_authorized with credentials failure: not a hex string "
396400
"credentials");
397401

398402
auto args = depositAuthArgs(alice, becky, "validated");
@@ -412,7 +416,7 @@ class DepositAuthorized_test : public beast::unit_test::suite
412416

413417
{
414418
testcase(
415-
"deposit_authorized with credentials failed: not a credential "
419+
"deposit_authorized with credentials failure: not a credential "
416420
"index");
417421

418422
auto args = depositAuthArgs(

src/test/unit_test/multi_runner.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,16 @@ multi_runner_child::on_suite_begin(beast::unit_test::suite_info const& info)
577577
void
578578
multi_runner_child::on_suite_end()
579579
{
580+
if (print_log_ || suite_results_.failed > 0)
581+
{
582+
std::stringstream s;
583+
if (num_jobs_ > 1)
584+
s << job_index_ << "> ";
585+
s << (suite_results_.failed > 0 ? "failed: " : "")
586+
<< suite_results_.name << " had " << suite_results_.failed
587+
<< " failures." << std::endl;
588+
message_queue_send(MessageType::log, s.str());
589+
}
580590
results_.add(suite_results_);
581591
message_queue_send(MessageType::test_end, suite_results_.name);
582592
}

0 commit comments

Comments
 (0)