mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-70123 Test Assistant: Make it possible to work with test data for existing test classes that are not properly annotated
Improved test data recognition
This commit is contained in:
+30
-18
@@ -143,8 +143,8 @@ public class TestDataGuessByExistingFilesUtil {
|
||||
}
|
||||
if (cached.second > System.currentTimeMillis()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TestFramework[] frameworks = Extensions.getExtensions(TestFramework.EXTENSION_NAME);
|
||||
TestFramework framework = null;
|
||||
@@ -257,27 +257,39 @@ public class TestDataGuessByExistingFilesUtil {
|
||||
if (!current.isComplete()) {
|
||||
continue;
|
||||
}
|
||||
String pattern = current.filePrefix.toLowerCase();
|
||||
if (!StringUtil.isEmpty(current.filePrefix)) {
|
||||
// Handle situations like the one below:
|
||||
// *) test class has tests with names 'testAlignedParameters' and 'testNonAlignedParameters';
|
||||
// *) test data files with the following names present: 'AlignedParameters.java' and 'NonAlignedParameters.java';
|
||||
// *) we're processing the following (test; test data file) pair - ('testAlignedParameters'; 'NonAlignedParameters.java');
|
||||
// We don't want to store descriptor with file prefix 'Non' here.
|
||||
boolean skip = false;
|
||||
for (String testName : testNamesLowerCase) {
|
||||
if (testName.startsWith(pattern)) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// Handle situations like the one below:
|
||||
// *) test class has tests with names 'testAlignedParameters' and 'testNonAlignedParameters';
|
||||
// *) test data files with the following names present: 'AlignedParameters.java' and 'NonAlignedParameters.java';
|
||||
// *) we're processing the following (test; test data file) pair - ('testAlignedParameters'; 'NonAlignedParameters.java');
|
||||
// We don't want to store descriptor with file prefix 'Non' here.
|
||||
// The same is true for suffixes, e.g. tests like 'testLeaveValidCodeBlock()' and 'testLeaveValidCodeBlockWithEmptyLineAfterIt()'
|
||||
String prefixPattern = current.filePrefix.toLowerCase();
|
||||
boolean checkPrefix = !StringUtil.isEmpty(prefixPattern);
|
||||
String suffixPattern = current.fileSuffix;
|
||||
for (TestLocationDescriptor descriptor : descriptors) {
|
||||
if (suffixPattern.endsWith(descriptor.fileSuffix)) {
|
||||
suffixPattern = suffixPattern.substring(0, suffixPattern.length() - descriptor.fileSuffix.length());
|
||||
}
|
||||
if (skip) {
|
||||
}
|
||||
suffixPattern = suffixPattern.toLowerCase();
|
||||
boolean checkSuffix = !StringUtil.isEmpty(suffixPattern);
|
||||
boolean skip = false;
|
||||
for (String testName : testNamesLowerCase) {
|
||||
if (testName.equals(trinity.second)) {
|
||||
continue;
|
||||
}
|
||||
if ((checkPrefix && testName.startsWith(prefixPattern)) || (checkSuffix && testName.endsWith(suffixPattern))) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (skip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
currentNameProcessed = true;
|
||||
if (descriptors.isEmpty() || descriptors.iterator().next().dir.equals(current.dir)) {
|
||||
if (descriptors.isEmpty() || (descriptors.iterator().next().dir.equals(current.dir) && !descriptors.contains(current))) {
|
||||
descriptors.add(current);
|
||||
continue;
|
||||
}
|
||||
@@ -364,7 +376,7 @@ public class TestDataGuessByExistingFilesUtil {
|
||||
}
|
||||
if (i < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
filePrefix = fileName.substring(0, i);
|
||||
fileSuffix = fileName.substring(i + testName.length());
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ public class TestDataLineMarkerProvider implements LineMarkerProvider {
|
||||
return false;
|
||||
}
|
||||
List<String> fileNames = new TestDataReferenceCollector(testDataPath, name.substring(4)).collectTestDataReferences(method);
|
||||
return !fileNames.isEmpty();
|
||||
return fileNames != null && !fileNames.isEmpty();
|
||||
}
|
||||
|
||||
public void collectSlowLineMarkers(List<PsiElement> elements, Collection<LineMarkerInfo> result) {
|
||||
|
||||
+1
@@ -40,6 +40,7 @@ public class TestDataReferenceCollector {
|
||||
myTestName = testName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
List<String> collectTestDataReferences(@NotNull final PsiMethod method) {
|
||||
myContainingClass = method.getContainingClass();
|
||||
List<String> result = collectTestDataReferences(method, new HashMap<String, Computable<String>>());
|
||||
|
||||
Reference in New Issue
Block a user