Skip to content

Commit

Permalink
[DAP] Improve test assertions to provide more information on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
agarciadom committed Sep 2, 2024
1 parent f1f5981 commit f36172b
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,26 @@ public void teardown() {
adapter.disconnect(new DisconnectArguments());
}

protected void assertStoppedBecauseOf(final String reason) throws InterruptedException {
protected void assertStoppedBecauseOf(final String expectedReason) throws InterruptedException {
client.isStopped.tryAcquire(5, TimeUnit.SECONDS);
assertNotNull("The script should have stopped within 5s", client.stoppedArgs);
assertEquals("The debugger should say it stopped because of " + reason, reason, client.stoppedArgs.getReason());
if (!expectedReason.equals(client.stoppedArgs.getReason())) {
fail(String.format("The debugger should say it stopped because of %s, but it actually stopped because of %s. Current stack trace:\n\n%s",
expectedReason,
client.stoppedArgs.getReason(),
this.module.getContext().getExecutorFactory().getStackTraceManager().getStackTraceAsString()));
}
client.stoppedArgs.setReason("");
}

protected void assertProgramCompletedSuccessfully() throws InterruptedException {
client.isExited.tryAcquire(5, TimeUnit.SECONDS);
assertNotNull("The script should have exited within 5s", client.exitedArgs);
assertEquals("The script should have completed its execution successfully", 0, client.exitedArgs.getExitCode());
if (client.exitedArgs == null) {
fail(String.format("The script should have exited within 5s, but it did not exit. Current stack trace:\n\n%s",
this.module.getContext().getExecutorFactory().getStackTraceManager().getStackTraceAsString()));
} else {
assertEquals("The script should have completed its execution successfully", 0, client.exitedArgs.getExitCode());
}
}

protected void assertProgramFailed() throws InterruptedException {
Expand Down

0 comments on commit f36172b

Please sign in to comment.