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

Fix clicking on a ParametrizedTest #1735

Merged
merged 5 commits into from
Nov 27, 2024
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
2 changes: 1 addition & 1 deletion org.eclipse.jdt.junit.core/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.core
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.junit.core;singleton:=true
Bundle-Version: 3.13.400.qualifier
Bundle-Version: 3.13.500.qualifier
Bundle-Activator: org.eclipse.jdt.internal.junit.JUnitCorePlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Expand Down
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
Loading