Skip to content

Commit

Permalink
Fix clicking on a ParametrizedTest (#1735)
Browse files Browse the repository at this point in the history
* Fix clicking on a ParametrizedTest

When we click on the 'grouping' element for a ParametrizedTest, the code
tries to find the method without the parameter types, but the search
actually tries to find a parameter-less method with the same name.

* Fix test result navigation in 'Generic Test view'

* Fix \0 handling in the test parameters

Previously if the variable contained a '\0' the rest of the string
was not displayed, with this fix, the rest of the string shows up too

* Version bump(s) for 4.35 stream

---------

Co-authored-by: Eclipse JDT Bot <[email protected]>
  • Loading branch information
gzsombor and eclipse-jdt-bot authored Nov 27, 2024
1 parent 36e2e89 commit f1dfac5
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ private TestElement addTreeEntry(String treeEntry) {
int index0= treeEntry.indexOf(',');
String id= treeEntry.substring(0, index0);

StringBuffer testNameBuffer= new StringBuffer(100);
StringBuilder testNameBuffer= new StringBuilder(100);
int index1= scanTestName(treeEntry, index0 + 1, testNameBuffer);
String testName= testNameBuffer.toString().trim();

Expand All @@ -493,11 +493,11 @@ private TestElement addTreeEntry(String treeEntry) {
boolean isDynamicTest;
String parentId;
String displayName;
StringBuffer displayNameBuffer= new StringBuffer(100);
StringBuilder displayNameBuffer= new StringBuilder(100);
String[] parameterTypes;
StringBuffer parameterTypesBuffer= new StringBuffer(200);
StringBuilder parameterTypesBuffer= new StringBuilder(200);
String uniqueId;
StringBuffer uniqueIdBuffer= new StringBuffer(200);
StringBuilder uniqueIdBuffer= new StringBuilder(200);
int index3= treeEntry.indexOf(',', index2 + 1);
if (index3 == -1) {
testCount= Integer.parseInt(treeEntry.substring(index2 + 1));
Expand All @@ -519,7 +519,7 @@ private TestElement addTreeEntry(String treeEntry) {
}

int index6= scanTestName(treeEntry, index5 + 1, displayNameBuffer);
displayName= displayNameBuffer.toString().trim();
displayName= displayNameBuffer.toString().replace('\0', ' ').trim();
if (displayName.equals(testName)) {
displayName= null;
}
Expand Down Expand Up @@ -592,7 +592,7 @@ public TestElement createTestElement(TestSuiteElement parent, String id, String
*
* @return the index of the next ','
*/
private int scanTestName(String s, int start, StringBuffer testName) {
private int scanTestName(String s, int start, StringBuilder testName) {
boolean inQuote= false;
int i= start;
for (; i < s.length(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.junit.runtime/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.junit.runtime
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.junit.runtime;singleton:=true
Bundle-Version: 3.7.500.qualifier
Bundle-Version: 3.7.600.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package:
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.junit.runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.junit.runtime</artifactId>
<version>3.7.500-SNAPSHOT</version>
<version>3.7.600-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,19 @@ public void setLoader(ITestLoader newInstance) {
fLoader = newInstance;
}

private void readPackageNames(String pkgNameFile) throws IOException {
try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(pkgNameFile)), StandardCharsets.UTF_8))) {
private String[] readLines(String fileName) throws IOException {
try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(fileName)), StandardCharsets.UTF_8))) {
String line;
Vector<String> list= new Vector<>();
while ((line= br.readLine()) != null) {
list.add(line);
}
fPackageNames= list.toArray(new String[list.size()]);
return list.toArray(new String[list.size()]);
}
}

private void readPackageNames(String pkgNameFile) throws IOException {
fPackageNames= readLines(pkgNameFile);
if (fDebugMode) {
System.out.println("Packages:"); //$NON-NLS-1$
for (String fPackageName : fPackageNames) {
Expand All @@ -404,14 +408,7 @@ private void readPackageNames(String pkgNameFile) throws IOException {
}

private void readTestNames(String testNameFile) throws IOException {
try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(testNameFile)), StandardCharsets.UTF_8))) {
String line;
Vector<String> list= new Vector<>();
while ((line= br.readLine()) != null) {
list.add(line);
}
fTestClassNames= list.toArray(new String[list.size()]);
}
fTestClassNames= readLines(testNameFile);
if (fDebugMode) {
System.out.println("Tests:"); //$NON-NLS-1$
for (String fTestClassName : fTestClassNames) {
Expand All @@ -421,14 +418,7 @@ private void readTestNames(String testNameFile) throws IOException {
}

private void readFailureNames(String testFailureFile) throws IOException {
try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(testFailureFile)), StandardCharsets.UTF_8))) {
String line;
Vector<String> list= new Vector<>();
while ((line= br.readLine()) != null) {
list.add(line);
}
fFailureNames= list.toArray(new String[list.size()]);
}
fFailureNames = readLines(testFailureFile);
if (fDebugMode) {
System.out.println("Failures:"); //$NON-NLS-1$
for (String fFailureName : fFailureNames) {
Expand Down Expand Up @@ -510,7 +500,7 @@ protected void notifyListenersOfTestEnd(TestExecution execution,
* @param testName individual method to be run
* @param execution executor
*/
public void runTests(String[] testClassNames, String testName, TestExecution execution) {
private void runTests(String[] testClassNames, String testName, TestExecution execution) {
ITestReference[] suites= fLoader.loadTests(loadClasses(testClassNames), testName, fFailureNames, fPackageNames, fIncludeExcludeTags, fUniqueId, this);

// count all testMethods and inform ITestRunListeners
Expand Down Expand Up @@ -754,7 +744,7 @@ public void flush() {
fWriter.flush();
}

public void runTests(TestExecution execution) {
private void runTests(TestExecution execution) {
runTests(fTestClassNames, fTestName, execution);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,14 @@ private OpenTestAction getOpenTestAction(TestSuiteElement testSuite) {

if (children.length > 0 && children[0] instanceof TestCaseElement tce && tce.isDynamicTest()) {
// a group of parameterized tests
return new OpenTestAction(fTestRunnerPart, (TestCaseElement) children[0], null);
return new OpenTestAction(fTestRunnerPart, tce, tce.getParameterTypes());
}
if (children.length == 0) {
// check if we have applied the workaround for: https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/945
TestCaseElement child= testSuite.getSingleDynamicChild();
if (child != null) {
// a parameterized test that ran only one test
return new OpenTestAction(fTestRunnerPart, child, null);
return new OpenTestAction(fTestRunnerPart, child, child.getParameterTypes());
}
}

Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ui.unittest.junit.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.jdt.ui.unittest.junit.feature"
label="%featureName"
version="1.1.500.qualifier"
version="1.1.600.qualifier"
provider-name="%provider"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ui.unittest.junit.feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</parent>
<groupId>org.eclipse.jdt.feature</groupId>
<artifactId>org.eclipse.jdt.ui.unittest.junit.feature</artifactId>
<version>1.1.500-SNAPSHOT</version>
<version>1.1.600-SNAPSHOT</version>
<packaging>eclipse-feature</packaging>
<build>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ui.unittest.junit/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.ui.unittest.junit
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.ui.unittest.junit;singleton:=true
Bundle-Version: 1.1.500.qualifier
Bundle-Version: 1.1.600.qualifier
Bundle-Activator: org.eclipse.jdt.ui.unittest.junit.JUnitTestPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ui.unittest.junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.ui.unittest.junit</artifactId>
<version>1.1.500-SNAPSHOT</version>
<version>1.1.600-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private void notifyTestTreeEntry(final String treeEntry) {
}

int index6 = scanTestName(fixedTreeEntry, index5 + 1, displayNameBuffer);
displayName = displayNameBuffer.toString().trim();
displayName = displayNameBuffer.toString().replace('\0', ' ').trim();
if (displayName.equals(testName)) {
displayName = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public IAction getOpenTestAction(Shell shell, ITestSuiteElement testSuite) {
int index = testName.indexOf('(');
// test factory method
if (index > 0) {
return new OpenTestAction(shell, testSuite.getTestName(), testName.substring(0, index),
return new OpenTestAction(shell, getClassName(testSuite), testName.substring(0, index),
getParameterTypes(testSuite), true, testSuite.getTestRunSession());
}

Expand Down Expand Up @@ -259,20 +259,34 @@ public ITestRunnerClient newTestRunnerClient(ITestRunSession session) {
* @return a parameter type array
*/
private String[] getParameterTypes(ITestElement test) {
String testName = test.getDisplayName();
final String testName = test.getDisplayName();
if (testName != null) {
int index = testName.lastIndexOf("method:"); //$NON-NLS-1$
final int index = testName.lastIndexOf("method:"); //$NON-NLS-1$
if (index != -1) {
index = testName.indexOf('(', index);
if (index > 0) {
int closeIndex = testName.indexOf(')', index);
if (closeIndex > 0) {
String params = testName.substring(index + 1, closeIndex);
return params.split(","); //$NON-NLS-1$
}
String[] result = extractParameters(testName, index);
if (result != null) {
return result;
}
}
}
final String testUniqData = test.getData();
if (testUniqData != null) {
final int testTemplateIdx = testUniqData.indexOf("test-template:"); //$NON-NLS-1$
if (testTemplateIdx >= 0) {
return extractParameters(testUniqData, testTemplateIdx);
}
}
return null;
}

private String[] extractParameters(String testDescription, int startIndex) {
final int index = testDescription.indexOf('(', startIndex);
if (index > 0) {
final int closeIndex = testDescription.indexOf(')', index);
if (closeIndex > 0) {
return testDescription.substring(index + 1, closeIndex).split(","); //$NON-NLS-1$
}
}
return null;
}

Expand Down

0 comments on commit f1dfac5

Please sign in to comment.