mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
sm runner: support multiple comparison failures in one test (IDEA-145997)
This commit is contained in:
+11
-28
@@ -16,7 +16,6 @@
|
||||
package com.intellij.execution.testframework.sm.runner;
|
||||
|
||||
import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.execution.testframework.AbstractTestProxy;
|
||||
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil;
|
||||
import com.intellij.execution.testframework.sm.runner.events.*;
|
||||
import com.intellij.openapi.application.Application;
|
||||
@@ -38,7 +37,6 @@ import java.util.*;
|
||||
public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcessor {
|
||||
|
||||
private final Map<String, SMTestProxy> myRunningTestsFullNameToProxy = new HashMap<String, SMTestProxy>();
|
||||
private final Set<AbstractTestProxy> myFailedTestsSet = new HashSet<AbstractTestProxy>();
|
||||
private final TestSuiteStack mySuitesStack;
|
||||
private final Set<SMTestProxy> myCurrentChildren = new LinkedHashSet<SMTestProxy>();
|
||||
private boolean myGetChildren = true;
|
||||
@@ -393,15 +391,13 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso
|
||||
cannotFindFullTestNameMsg(fullTestName));
|
||||
if (inDebugMode) {
|
||||
return;
|
||||
} else {
|
||||
// try to fix the problem:
|
||||
if (!myFailedTestsSet.contains(testProxy)) {
|
||||
// if hasn't been already reported
|
||||
// 1. report
|
||||
onTestStarted(new TestStartedEvent(testName, null));
|
||||
// 2. add failure
|
||||
testProxy = getProxyByFullTestName(fullTestName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if hasn't been already reported
|
||||
// 1. report
|
||||
onTestStarted(new TestStartedEvent(testName, null));
|
||||
// 2. add failure
|
||||
testProxy = getProxyByFullTestName(fullTestName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,21 +406,14 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso
|
||||
}
|
||||
|
||||
if (comparisionFailureActualText != null && comparisionFailureExpectedText != null) {
|
||||
if (myFailedTestsSet.contains(testProxy)) {
|
||||
// duplicate message
|
||||
logProblem("Duplicate failure for test [" + fullTestName + "]: msg = " + localizedMessage + ", stacktrace = " + stackTrace);
|
||||
|
||||
if (inDebugMode) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
testProxy.setTestComparisonFailed(localizedMessage, stackTrace,
|
||||
comparisionFailureActualText, comparisionFailureExpectedText,
|
||||
testFailedEvent.getFilePath(), testFailedEvent.getActualFilePath());
|
||||
} else if (comparisionFailureActualText == null && comparisionFailureExpectedText == null) {
|
||||
}
|
||||
else if (comparisionFailureActualText == null && comparisionFailureExpectedText == null) {
|
||||
testProxy.setTestFailed(localizedMessage, stackTrace, isTestError);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
logProblem("Comparison failure actual and expected texts should be both null or not null.\n"
|
||||
+ "Expected:\n"
|
||||
+ comparisionFailureExpectedText + "\n"
|
||||
@@ -432,8 +421,6 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso
|
||||
+ comparisionFailureActualText);
|
||||
}
|
||||
|
||||
myFailedTestsSet.add(testProxy);
|
||||
|
||||
// fire event
|
||||
fireOnTestFailed(testProxy);
|
||||
}
|
||||
@@ -535,10 +522,6 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso
|
||||
return myRunningTestsFullNameToProxy.size();
|
||||
}
|
||||
|
||||
protected Set<AbstractTestProxy> getFailedTestsSet() {
|
||||
return Collections.unmodifiableSet(myFailedTestsSet);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected SMTestProxy getProxyByFullTestName(final String fullTestName) {
|
||||
return myRunningTestsFullNameToProxy.get(fullTestName);
|
||||
|
||||
+27
-2
@@ -480,8 +480,20 @@ public class SMTestProxy extends AbstractTestProxy {
|
||||
@Nullable final String expectedFilePath,
|
||||
@Nullable final String actualFilePath) {
|
||||
setStacktraceIfNotSet(stackTrace);
|
||||
myState = new TestComparisionFailedState(localizedMessage, stackTrace, actualText, expectedText, expectedFilePath, actualFilePath);
|
||||
fireOnNewPrintable(myState);
|
||||
final TestComparisionFailedState comparisionFailedState = new TestComparisionFailedState(localizedMessage, stackTrace, actualText, expectedText, expectedFilePath, actualFilePath);
|
||||
if (myState instanceof TestComparisionFailedState) {
|
||||
final TestComparisonFailedStates states = new TestComparisonFailedStates(localizedMessage, stackTrace);
|
||||
states.addComparisonFailure((TestComparisionFailedState)myState);
|
||||
states.addComparisonFailure(comparisionFailedState);
|
||||
myState = states;
|
||||
}
|
||||
else if (myState instanceof TestComparisonFailedStates) {
|
||||
((TestComparisonFailedStates)myState).addComparisonFailure(comparisionFailedState);
|
||||
}
|
||||
else {
|
||||
myState = comparisionFailedState;
|
||||
}
|
||||
fireOnNewPrintable(comparisionFailedState);
|
||||
}
|
||||
|
||||
public void setTestIgnored(@Nullable String ignoreComment, @Nullable String stackTrace) {
|
||||
@@ -627,6 +639,10 @@ public class SMTestProxy extends AbstractTestProxy {
|
||||
return ((TestComparisionFailedState)myState).getHyperlink();
|
||||
}
|
||||
|
||||
if (myState instanceof TestComparisonFailedStates) {
|
||||
return ((TestComparisonFailedStates)myState).getHyperlinks().get(0);
|
||||
}
|
||||
|
||||
if (myChildren != null) {
|
||||
for (SMTestProxy child : myChildren) {
|
||||
if (!child.isDefect()) continue;
|
||||
@@ -639,6 +655,15 @@ public class SMTestProxy extends AbstractTestProxy {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<DiffHyperlink> getDiffViewerProviders() {
|
||||
if (myState instanceof TestComparisonFailedStates) {
|
||||
return ((TestComparisonFailedStates)myState).getHyperlinks();
|
||||
}
|
||||
return super.getDiffViewerProviders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getPresentableName();
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.execution.testframework.sm.runner.states;
|
||||
|
||||
|
||||
import com.intellij.execution.testframework.Printer;
|
||||
import com.intellij.execution.testframework.stacktrace.DiffHyperlink;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestComparisonFailedStates extends TestFailedState {
|
||||
|
||||
final List<TestComparisionFailedState> myStates = new ArrayList<TestComparisionFailedState>();
|
||||
|
||||
public TestComparisonFailedStates(@Nullable String localizedMessage, @Nullable String stackTrace) {
|
||||
super(localizedMessage, stackTrace);
|
||||
}
|
||||
|
||||
public void addComparisonFailure(TestComparisionFailedState state) {
|
||||
myStates.add(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printOn(Printer printer) {
|
||||
|
||||
for (TestComparisionFailedState state : myStates) {
|
||||
state.printOn(printer);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<DiffHyperlink> getHyperlinks() {
|
||||
return ContainerUtil.map(myStates, new Function<TestComparisionFailedState, DiffHyperlink>() {
|
||||
@Override
|
||||
public DiffHyperlink fun(TestComparisionFailedState state) {
|
||||
return state.getHyperlink();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+1
-9
@@ -16,11 +16,10 @@
|
||||
package com.intellij.execution.testframework.sm.runner;
|
||||
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.testframework.AbstractTestProxy;
|
||||
import com.intellij.execution.testframework.TestConsoleProperties;
|
||||
import com.intellij.execution.testframework.sm.runner.history.ImportedToGeneralTestEventsConverter;
|
||||
import com.intellij.execution.testframework.sm.Marker;
|
||||
import com.intellij.execution.testframework.sm.runner.events.*;
|
||||
import com.intellij.execution.testframework.sm.runner.history.ImportedToGeneralTestEventsConverter;
|
||||
import com.intellij.execution.testframework.sm.runner.ui.MockPrinter;
|
||||
import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView;
|
||||
import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerTestTreeView;
|
||||
@@ -35,7 +34,6 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeModel;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Roman Chernyatchik
|
||||
@@ -184,11 +182,6 @@ public class GeneralToSMTRunnerEventsConvertorTest extends BaseSMTRunnerTestCase
|
||||
myEventsProcessor.onTestFailure(new TestFailedEvent("some_test", "msg 2", "trace 2", false, null, null));
|
||||
|
||||
assertEquals(1, myEventsProcessor.getRunningTestsQuantity());
|
||||
final Set<AbstractTestProxy> failedTests = myEventsProcessor.getFailedTestsSet();
|
||||
assertEquals(1, failedTests.size());
|
||||
for (final AbstractTestProxy test : failedTests) {
|
||||
assertEquals("some_test", test.getName());
|
||||
}
|
||||
assertEquals("\nmsg 1\ntrace 1\n\nmsg 2\ntrace 2\n", myMockResettablePrinter.getStdErr());
|
||||
}
|
||||
|
||||
@@ -223,7 +216,6 @@ public class GeneralToSMTRunnerEventsConvertorTest extends BaseSMTRunnerTestCase
|
||||
myEventsProcessor.onTestFinished(new TestFinishedEvent("some_test", 10l));
|
||||
|
||||
assertEquals(0, myEventsProcessor.getRunningTestsQuantity());
|
||||
assertEquals(0, myEventsProcessor.getFailedTestsSet().size());
|
||||
|
||||
assertNotNull(proxy);
|
||||
assertFalse(proxy.isDefect());
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -142,6 +143,12 @@ public abstract class AbstractTestProxy extends CompositePrintable {
|
||||
return myExceptionMark;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<DiffHyperlink> getDiffViewerProviders() {
|
||||
final DiffHyperlink provider = getDiffViewerProvider();
|
||||
return provider == null ? null : Collections.singletonList(provider);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DiffHyperlink getDiffViewerProvider() {
|
||||
return null;
|
||||
|
||||
+2
-2
@@ -75,9 +75,9 @@ public class ViewAssertEqualsDiffAction extends AnAction implements TestTreeView
|
||||
final List<? extends AbstractTestProxy> allTests = root.getAllTests();
|
||||
for (AbstractTestProxy test : allTests) {
|
||||
if (test.isLeaf()) {
|
||||
final DiffHyperlink provider = test.getDiffViewerProvider();
|
||||
final List<DiffHyperlink> provider = test.getDiffViewerProviders();
|
||||
if (provider != null) {
|
||||
providers.add(provider);
|
||||
providers.addAll(provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user