Skip to content

Commit

Permalink
7903232: RunTestsCommand should also print Total/Setup/Cleanup times …
Browse files Browse the repository at this point in the history
…converted to seconds

Follow-up polishing of how message templates are organized
  • Loading branch information
dbessono committed Jul 29, 2022
1 parent b007d31 commit 36fb0b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
32 changes: 22 additions & 10 deletions src/com/sun/javatest/batch/RunTestsCommand.java
Expand Up @@ -135,16 +135,9 @@ public void run(CommandContext ctx) throws Fault {
h.notifyOfTheFinalStats(stats != null ? Collections.unmodifiableMap(stats) : Collections.emptyMap(), boStats);

if (!ctx.isVerboseQuiet()) {
long totalTimeSec = h.getElapsedTime() / 1000L;
long setupTimeSec = h.getTotalSetupTime() / 1000L;
long cleanupTimeSec = h.getTotalCleanupTime() / 1000L;
ctx.printMessage(i18n, "runTests.totalTime", formattedDuration(totalTimeSec),
totalTimeSec <= 60 ? "" : " (" + totalTimeSec + " seconds)");
ctx.printMessage(i18n, "runTests.setupTime", formattedDuration(setupTimeSec),
setupTimeSec <= 60 ? "" : " (" + setupTimeSec + " seconds)");
ctx.printMessage(i18n, "runTests.cleanupTime", formattedDuration(cleanupTimeSec),
cleanupTimeSec <= 60 ? "" : " (" + cleanupTimeSec + " seconds)");

printTime("runTests.totalTime", h.getElapsedTime() / 1000L);
printTime("runTests.setupTime", h.getTotalSetupTime() / 1000L);
printTime("runTests.cleanupTime", h.getTotalCleanupTime() / 1000L);
showResultStats(skipped, boStats);
}

Expand All @@ -170,6 +163,25 @@ public void run(CommandContext ctx) throws Fault {
}
}

/**
* Writes a message to the log stream printing given time in seconds
* using message template with the given key,
* or printing additionally the absolute time as-is in seconds
* using a different template name
* constructed as the given message key plus ".withSecondsTotal" suffix
*
* @param messageKey the key for the required message template
* @param timeSeconds time value in seconds to be printed
*/
private void printTime(String messageKey, long timeSeconds) {
if (timeSeconds <= 60) {
ctx.printMessage(i18n, messageKey, formattedDuration(timeSeconds));
} else {
ctx.printMessage(i18n, messageKey + ".withSecondsTotal",
formattedDuration(timeSeconds), timeSeconds);
}
}

private void showResultStats(int skipped, int... stats) {

int passed = stats[Status.PASSED];
Expand Down
9 changes: 6 additions & 3 deletions src/com/sun/javatest/batch/i18n.properties
Expand Up @@ -53,17 +53,20 @@ observer.noClassName=No class name given
observer.badArg=Bad option: {0}
observer.badClassPath=Bad class path ({0}): {1}

runTests.cleanupTime=Cleanup time: {0}{1}
runTests.cleanupTime=Cleanup time: {0}
runTests.cleanupTime.withSecondsTotal=Cleanup time: {0} ({1} seconds)
runTests.error=Error: {0}
runTests.harnessError=An error occurred while running the tests:\n{0}
runTests.interrupted=The test run was interrupted.
runTests.noTests=Test results: no tests selected
runTests.resultsDone=Results written to {0}
runTests.setupTime=Setup time: {0}{1}
runTests.setupTime=Setup time: {0}
runTests.setupTime.withSecondsTotal=Setup time: {0} ({1} seconds)
runTests.tests=Test results: {0,choice,0#|0<passed: {0,number}}{1,choice,0#|1#; }{2,choice,0#|0<failed: {2,number}}{3,choice,0#|1#; }{4,choice,0#|0<error: {4,number}}{5,choice,0#|1#; }{6,choice,0#|0<not run: {6,number}}{7,choice,0#|1#; }{8,choice,0#|0<skipped: {8,number}}
runTests.testsInTheSuite=Tests found in the suite: {0,number}
runTests.testsFailed=Error: Some tests did not pass
runTests.totalTime=Total time: {0}{1}
runTests.totalTime=Total time: {0}
runTests.totalTime.withSecondsTotal=Total time: {0} ({1} seconds)
runTests.warnError=Warning: Test run completed, but problem(s) were detected in the test suite\nduring the run.


Expand Down

0 comments on commit 36fb0b9

Please sign in to comment.