Skip to content
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
9 changes: 8 additions & 1 deletion src/commonRunTestsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,14 @@ export async function commonRunTestsHandler(controller: vscode.TestController, r
if (request.include?.length === 1) {
const idParts = request.include[0].id.split(":");
if (idParts.length === 5) {
testSpec = `${safeUsername}\\${idParts[3].split(".").slice(0, -1).join("\\")}:${idParts[3]}:${idParts[4]}`;
// The suite subpath mirrors where we copied the .cls file (filesystem-based, from idParts[3]).
// The testcase argument must be the real class FQN as compiled on the server — take it from
// the parent class item's ourFqn, falling back to the filesystem-derived id part when no FQN
// was parsed from the .cls file.
const classItem = request.include[0].parent as OurTestItem | undefined;
const classFqn = classItem?.ourFqn ?? idParts[3];
const suiteSubPath = idParts[3].split(".").slice(0, -1).join("\\");
testSpec = `${safeUsername}\\${suiteSubPath}:${classFqn}:${idParts[4]}`;
}
}

Expand Down
24 changes: 22 additions & 2 deletions src/debugTracker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { allTestRuns, loadedTestController, localTestController, OurTestRun } from './extension';
import { allTestRuns, loadedTestController, localTestController, OurTestItem, OurTestRun } from './extension';
import { refreshHistoryRootItem } from './historyExplorer';
import { processCoverage } from './coverage';

Expand All @@ -15,6 +15,11 @@ export class DebugTracker implements vscode.DebugAdapterTracker {
private testMethodName?: string;
private testDuration?: number;
private methodTestMap: Map<string, vscode.TestItem>;
// Maps a class FQN (as written by %UnitTest.Manager in stdout) to the
// corresponding class-level test item. Populated from OurTestItem.ourFqn
// so the lookup works even when the filesystem path under
// `relativeTestRoot` does not mirror the package hierarchy.
private fqnToClassItem: Map<string, vscode.TestItem>;
private methodTest?: vscode.TestItem;
private failureMessages: vscode.TestMessage[] = [];
private skippedMessages: vscode.TestMessage[] = [];
Expand All @@ -30,11 +35,16 @@ export class DebugTracker implements vscode.DebugAdapterTracker {
};
this.testingIdBase = this.session.configuration.testingIdBase;
this.methodTestMap = new Map<string, vscode.TestItem>();
this.fqnToClassItem = new Map<string, vscode.TestItem>();

const addToMethodTestMap = (testItem?: vscode.TestItem) => {
if (!testItem) {
return;
}
const fqn = (testItem as OurTestItem).ourFqn;
if (fqn) {
this.fqnToClassItem.set(fqn, testItem);
}
if (testItem.children.size > 0) {
testItem.children.forEach(addToMethodTestMap);
} else {
Expand Down Expand Up @@ -83,7 +93,17 @@ export class DebugTracker implements vscode.DebugAdapterTracker {
const methodBegin = line.match(/^ Test([\dA-Za-z0-9]+).* begins \.\.\./);
if (methodBegin) {
this.testMethodName = methodBegin[1];
this.methodTest = this.methodTestMap.get(`${this.testingIdBase}:${this.className}:Test${this.testMethodName}`);
// Preferred lookup: locate the class by its real FQN (independent of
// filesystem path under `relativeTestRoot`), then take the method child.
const classItem = this.className ? this.fqnToClassItem.get(this.className) : undefined;
if (classItem) {
this.methodTest = classItem.children.get(`${classItem.id}:Test${this.testMethodName}`);
}
// Fallback for items predating ourFqn (and for the LoadedTests path,
// where class items are addressed by their flat id).
if (!this.methodTest) {
this.methodTest = this.methodTestMap.get(`${this.testingIdBase}:${this.className}:Test${this.testMethodName}`);
}
this.failureMessages = [];
if (this.methodTest) {
this.run.started(this.methodTest)
Expand Down
6 changes: 6 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export interface OurTestRun extends vscode.TestRun {
export interface OurTestItem extends vscode.TestItem {
ourUri?: vscode.Uri;
supportsCoverage?: boolean;
// Full class FQN parsed from the `Class …` line of the .cls file.
// Set on class-level items so the debug tracker can map outcome lines
// (which carry the real FQN written by %UnitTest.Manager) back to the
// test item even when the filesystem path under `relativeTestRoot`
// does not mirror the package hierarchy.
ourFqn?: string;
}

export const allTestRuns: (OurTestRun | undefined)[] = [];
Expand Down
6 changes: 6 additions & 0 deletions src/localTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ async function resolveItemChildren(item: OurTestItem) {
// break;
// }
item.range = new vscode.Range(new vscode.Position(index, 0), new vscode.Position(index + 1, 0))
// Record the real class FQN so the debug tracker can map outcome lines
// back to this item independently of the filesystem path.
const classMatch = lineText.match(/^Class\s+([%\w\.]+)/);
if (classMatch) {
item.ourFqn = classMatch[1];
}
}
const match = lineText.match(/^Method Test(.+)\(/);
if (match) {
Expand Down