Skip to content

Commit 2cf63aa

Browse files
bshastryclaude
andcommitted
Refactor block-test summary output for better maintainability
Address code review feedback by: - Extract separator string into SEPARATOR constant to reduce duplication - Reuse failureReason variable in output statements instead of duplicating formatting logic This improves code maintainability by consolidating the failure message formatting in a single location. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Bhargava Shastry <bhargava.shastry@ethereum.org>
1 parent 227998b commit 2cf63aa

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/BlockchainTestSubCommand.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class BlockchainTestSubCommand implements Runnable {
9696

9797
/** Helper class to track test execution results for summary reporting. */
9898
private static class TestResults {
99+
private static final String SEPARATOR = "\n" + "=".repeat(80);
99100
private final AtomicInteger totalTests = new AtomicInteger(0);
100101
private final AtomicInteger passedTests = new AtomicInteger(0);
101102
private final AtomicInteger failedTests = new AtomicInteger(0);
@@ -113,19 +114,18 @@ void recordFailure(final String testName, final String reason) {
113114
}
114115

115116
void printSummary(final java.io.PrintWriter out) {
116-
out.println("\n" + "=".repeat(80));
117+
out.println(SEPARATOR);
117118
out.println("TEST SUMMARY");
118-
out.println("=".repeat(80));
119+
out.println(SEPARATOR.substring(1)); // Skip leading newline for middle separator
119120
out.printf("Total tests: %d%n", totalTests.get());
120121
out.printf("Passed: %d%n", passedTests.get());
121122
out.printf("Failed: %d%n", failedTests.get());
122123

123124
if (!failures.isEmpty()) {
124125
out.println("\nFailed tests:");
125-
failures.forEach(
126-
(testName, reason) -> out.printf(" - %s: %s%n", testName, reason));
126+
failures.forEach((testName, reason) -> out.printf(" - %s: %s%n", testName, reason));
127127
}
128-
out.println("=".repeat(80));
128+
out.println(SEPARATOR.substring(1)); // Skip leading newline for bottom separator
129129
}
130130
}
131131

@@ -260,11 +260,7 @@ private void traceTestSpecs(
260260
block.getHeader().getNumber(),
261261
block.getHash(),
262262
importResult.isImported() ? "Failed to be rejected" : "Failed to import");
263-
parentCommand.out.printf(
264-
"Block %d (%s) %s%n",
265-
block.getHeader().getNumber(),
266-
block.getHash(),
267-
importResult.isImported() ? "Failed to be rejected" : "Failed to import");
263+
parentCommand.out.println(failureReason);
268264
} else {
269265
if (importResult.isImported()) {
270266
final long gasUsed = block.getHeader().getGasUsed();
@@ -289,11 +285,7 @@ private void traceTestSpecs(
289285
candidateBlock.getBlock().getHeader().getNumber(),
290286
candidateBlock.getBlock().getHash(),
291287
e.getMessage());
292-
parentCommand.out.printf(
293-
"Block %d (%s) should have imported but had an RLP exception %s%n",
294-
candidateBlock.getBlock().getHeader().getNumber(),
295-
candidateBlock.getBlock().getHash(),
296-
e.getMessage());
288+
parentCommand.out.println(failureReason);
297289
}
298290
}
299291
}

0 commit comments

Comments
 (0)