Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show stacktrace on test error in repl #1903

Merged
merged 3 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes to Calva.

- [A more flexible evaluate-to-cursor command](https://github.com/BetterThanTomorrow/calva/
issues/1901)
- [Test runner does not show stacktrace on error](https://github.com/BetterThanTomorrow/calva/issues/424)

## [2.0.307] - 2022-10-11

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) => {
const 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
20 changes: 14 additions & 6 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 Expand Up @@ -237,7 +245,7 @@ async function runAllTests(controller: vscode.TestController, document = {}) {
const session = getSession(util.getFileType(document));
outputWindow.append('; Running all project tests…');
try {
reportTests(controller, session, [await session.testAll()]);
await reportTests(controller, session, [await session.testAll()]);
} catch (e) {
outputWindow.append('; ' + e);
}
Expand Down Expand Up @@ -298,7 +306,7 @@ async function runNamespaceTestsImpl(
return session.testNs(ns);
});
try {
reportTests(controller, session, await Promise.all(resultPromises));
await reportTests(controller, session, await Promise.all(resultPromises));
} catch (e) {
outputWindow.append('; ' + e);
}
Expand Down Expand Up @@ -335,7 +343,7 @@ async function runTestUnderCursor(controller: vscode.TestController) {
if (test) {
outputWindow.append(`; Running test: ${test}…`);
try {
reportTests(controller, session, [await session.test(ns, test)]);
await reportTests(controller, session, [await session.test(ns, test)]);
} catch (e) {
outputWindow.append('; ' + e);
}
Expand Down Expand Up @@ -373,7 +381,7 @@ async function rerunTests(controller: vscode.TestController, document = {}) {
const session = getSession(util.getFileType(document));
outputWindow.append('; Running previously failed tests…');
try {
reportTests(controller, session, [await session.retest()]);
await reportTests(controller, session, [await session.retest()]);
} catch (e) {
outputWindow.append('; ' + e);
}
Expand Down