Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
fix: Cannot navigate to the source location for <TestError> items (mi…
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Mar 16, 2020
1 parent 9f06799 commit 3fc68be
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './src/codelens/TestCodeLensProvider';
export * from './src/runners/models';
export * from './src/testResultManager';
export * from './src/protocols';
export * from './src/utils/commandUtils';
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,13 @@ public static List<Location> searchLocation(List<Object> arguments, IProgressMon
if (arguments == null || arguments.size() == 0) {
throw new IllegalArgumentException("Invalid aruguments to search the location.");
}
// For now, input will only be a method.
final String methodFullName = ((String) arguments.get(0)).replaceAll("[$#]", ".");
final SearchPattern pattern = SearchPattern.createPattern(methodFullName, IJavaSearchConstants.METHOD,
String searchString = ((String) arguments.get(0)).replaceAll("[$#]", ".");
int searchFor = IJavaSearchConstants.METHOD;
if (searchString.endsWith("<TestError>")) {
searchString = searchString.substring(0, searchString.indexOf("<TestError>") - 1);
searchFor = IJavaSearchConstants.CLASS;
}
final SearchPattern pattern = SearchPattern.createPattern(searchString, searchFor,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
final IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot())
.getJavaProjects();
Expand All @@ -251,10 +255,10 @@ public static List<Location> searchLocation(List<Object> arguments, IProgressMon
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
final Object element = match.getElement();
if (element instanceof IMethod) {
final IMethod method = (IMethod) element;
searchResult.add(new Location(JDTUtils.getFileURI(method.getResource()),
TestItemUtils.parseTestItemRange(method)));
if (element instanceof IMethod || element instanceof IType) {
final IJavaElement javaElement = (IJavaElement) element;
searchResult.add(new Location(JDTUtils.getFileURI(javaElement.getResource()),
TestItemUtils.parseTestItemRange(javaElement)));
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class JUnitRunnerResultAnalyzer extends BaseRunnerResultAnalyzer {
// In case the output is class level, i.e.: `%ERROR 2,a.class.FullyQualifiedName`
const indexOfSpliter: number = message.lastIndexOf(',');
if (indexOfSpliter > -1) {
return `${this.projectName}@${message.slice(indexOfSpliter + 1)}#TestError`;
return `${this.projectName}@${message.slice(indexOfSpliter + 1)}#<TestError>`;
}

logger.error(`Failed to parse the message: ${message}`);
Expand Down
2 changes: 1 addition & 1 deletion test/maven-junit4-suite/codelens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ suite('Code Lens Tests', function() {
await await commands.executeCommand(command!.command, testItem[0]);

const projectName: string = testItem[0].project;
const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.ExceptionInBefore#TestError`);
const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.ExceptionInBefore#<TestError>`);
assert.equal(failedDetail!.status, TestStatus.Fail, 'Should have failed case');
assert.ok(failedDetail!.trace !== undefined, 'Should have error trace');
});
Expand Down
28 changes: 28 additions & 0 deletions test/maven-junit4-suite/commandUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as assert from 'assert';
import { commands, TextDocument, window, workspace, extensions } from 'vscode';
import { searchTestLocation, ILocation } from '../../extension.bundle';
import { Uris } from '../shared';

suite('Command Utils Tests', function() {

suiteSetup(async function() {
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
});

test("Can search location for <TestError> items", async function() {
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT4_TEST);
await window.showTextDocument(document);

const location: ILocation[] = await searchTestLocation('junit4.ExceptionInBefore#<TestError>');
assert.ok(location);
assert.ok(location.length === 1);
assert.equal(location[0].uri, Uris.JUNIT4_EXCEPTION_BEFORE);
});

teardown(async function() {
await commands.executeCommand('workbench.action.closeActiveEditor');
});
});

0 comments on commit 3fc68be

Please sign in to comment.