Skip to content

Commit

Permalink
Show stacktrace on test error
Browse files Browse the repository at this point in the history
Fixes #424
  • Loading branch information
stephendeyoung committed Oct 18, 2022
1 parent 3dac205 commit 2b70f52
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes to Calva.

## [Unreleased]

- [Test runner does not show stacktrace on error](https://github.com/BetterThanTomorrow/calva/issues/424)

## [2.0.307] - 2022-10-11

- [Support user level `~/.config/calva/config.edn`](https://github.com/BetterThanTomorrow/calva/issues/1887)
Expand Down
18 changes: 18 additions & 0 deletions src/nrepl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,24 @@ export class NReplSession {
});
}

testStacktrace(ns: string, test: string, index: number) {
return new Promise<any>((resolve, reject) => {
let id = this.client.nextId;
this.messageHandlers[id] = (msg) => {
resolve(msg);
return true;
};
this.client.write({
op: 'test-stacktrace',
id,
session: this.sessionId,
ns,
var: test,
index: index,
});
});
}

testNs(ns: string) {
return this.testVarQuery({
'ns-query': {
Expand Down
12 changes: 10 additions & 2 deletions src/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function useTestExplorer(): boolean | undefined {
return vscode.workspace.getConfiguration('calva').get('useTestExplorer');
}

function reportTests(
async function reportTests(
controller: vscode.TestController,
session: NReplSession,
possibleResults: cider.TestResults[]
Expand Down Expand Up @@ -208,7 +208,15 @@ function reportTests(
cider.cleanUpWhiteSpace(a);

const messages = cider.detailedMessage(a);
if (messages) {

if (a.type == 'error') {
const stackTrace = await session.testStacktrace(ns, test, a.index);

outputWindow.saveStacktrace(stackTrace.stacktrace);
outputWindow.append(messages, (_, afterResultLocation) => {
outputWindow.markLastStacktraceRange(afterResultLocation);
});
} else if (messages) {
outputWindow.append(messages);
}

Expand Down

0 comments on commit 2b70f52

Please sign in to comment.