mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Recent tests: changed tests order - passed tests is added only if it is suite; first comes failed test group, last comes passed test group
This commit is contained in:
@@ -37,6 +37,8 @@ public interface RecentTestRunner {
|
||||
void run(Location location);
|
||||
|
||||
Location getLocation(String url);
|
||||
|
||||
boolean isSuite(String url);
|
||||
}
|
||||
|
||||
class RecentTestRunnerImpl implements RecentTestRunner {
|
||||
@@ -75,6 +77,12 @@ class RecentTestRunnerImpl implements RecentTestRunner {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuite(String url) {
|
||||
String protocol = VirtualFileManager.extractProtocol(url);
|
||||
return JavaTestLocator.SUITE_PROTOCOL.equals(protocol);
|
||||
}
|
||||
|
||||
public void run(final Location location) {
|
||||
DataContext data = new DataContext() {
|
||||
@Nullable
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.intellij.execution.Location;
|
||||
import com.intellij.execution.TestStateStorage;
|
||||
import com.intellij.execution.testframework.TestIconMapper;
|
||||
import com.intellij.execution.testframework.sm.runner.states.TestStateInfo;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.PopupStep;
|
||||
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
@@ -27,32 +26,81 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class SelectTestStep extends BaseListPopupStep<String> {
|
||||
private static Comparator<String> TEST_BY_PATH_COMPARATOR = new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
String path1 = VirtualFileManager.extractPath(o1);
|
||||
String path2 = VirtualFileManager.extractPath(o2);
|
||||
return path1.compareTo(path2);
|
||||
}
|
||||
};
|
||||
|
||||
private final Map<String, TestStateStorage.Record> myRecords;
|
||||
private final RecentTestRunner myRunner;
|
||||
|
||||
|
||||
public SelectTestStep(Map<String, TestStateStorage.Record> records, RecentTestRunner runner) {
|
||||
super("Debug Recent Tests", getUrls(records));
|
||||
super("Debug Recent Tests", getUrls(records, runner));
|
||||
myRunner = runner;
|
||||
myRecords = records;
|
||||
}
|
||||
|
||||
private static List<String> getUrls(Map<String, TestStateStorage.Record> records) {
|
||||
List<String> list = ContainerUtil.newArrayList(records.keySet());
|
||||
Collections.sort(list, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
String path1 = VirtualFileManager.extractPath(o1);
|
||||
String path2 = VirtualFileManager.extractPath(o2);
|
||||
return path1.compareTo(path2);
|
||||
private static List<String> getUrls(Map<String, TestStateStorage.Record> records, RecentTestRunner runner) {
|
||||
TestGroup groups = toTestGroups(records, runner);
|
||||
|
||||
List<String> failed = ContainerUtil.newArrayList(groups.failedTests);
|
||||
Collections.sort(failed, TEST_BY_PATH_COMPARATOR);
|
||||
List<String> other = ContainerUtil.newArrayList(groups.otherTests);
|
||||
Collections.sort(other, TEST_BY_PATH_COMPARATOR);
|
||||
List<String> passed = ContainerUtil.newArrayList(groups.passedTests);
|
||||
Collections.sort(passed, TEST_BY_PATH_COMPARATOR);
|
||||
|
||||
failed.addAll(other);
|
||||
failed.addAll(passed);
|
||||
return failed;
|
||||
}
|
||||
|
||||
private static TestGroup toTestGroups(Map<String, TestStateStorage.Record> records, RecentTestRunner runner) {
|
||||
Set<String> failedTests = ContainerUtil.newHashSet();
|
||||
Set<String> passedSuites = ContainerUtil.newHashSet();
|
||||
Set<String> otherSuites = ContainerUtil.newHashSet();
|
||||
|
||||
for (Map.Entry<String, TestStateStorage.Record> item : records.entrySet()) {
|
||||
String url = item.getKey();
|
||||
TestStateInfo.Magnitude magnitude = getMagnitude(item.getValue().magnitude);
|
||||
if (magnitude == null) continue;
|
||||
switch (magnitude) {
|
||||
case COMPLETE_INDEX:
|
||||
if (runner.isSuite(url)) {
|
||||
passedSuites.add(url);
|
||||
}
|
||||
break;
|
||||
case PASSED_INDEX:
|
||||
if (runner.isSuite(url)) {
|
||||
passedSuites.add(url);
|
||||
}
|
||||
break;
|
||||
case ERROR_INDEX:
|
||||
failedTests.add(url);
|
||||
break;
|
||||
default:
|
||||
otherSuites.add(url);
|
||||
break;
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
return new TestGroup(failedTests, passedSuites, otherSuites);
|
||||
}
|
||||
|
||||
private static TestStateInfo.Magnitude getMagnitude(int magnitude) {
|
||||
for (TestStateInfo.Magnitude m : TestStateInfo.Magnitude.values()) {
|
||||
if (m.getValue() == magnitude) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -79,4 +127,16 @@ public class SelectTestStep extends BaseListPopupStep<String> {
|
||||
myRunner.run(location);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class TestGroup {
|
||||
public Set<String> failedTests;
|
||||
public Set<String> passedTests;
|
||||
public Set<String> otherTests;
|
||||
|
||||
public TestGroup(Set<String> failedTests, Set<String> passedTests, Set<String> otherTests) {
|
||||
this.failedTests = failedTests;
|
||||
this.passedTests = passedTests;
|
||||
this.otherTests = otherTests;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.ListPopupStep;
|
||||
import com.intellij.ui.popup.list.ListPopupImpl;
|
||||
import com.intellij.util.PsiNavigateUtil;
|
||||
import com.intellij.util.Time;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -33,10 +32,10 @@ import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class ShowRecentTests extends AnAction {
|
||||
private static final int TEST_LIMIT = 20;
|
||||
private static final int TEST_LIMIT = Integer.MAX_VALUE;
|
||||
|
||||
private static Date getSinceDate() {
|
||||
return new Date(System.currentTimeMillis() - 2 * Time.HOUR);
|
||||
return new Date(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user