From 1d6751d8d740abe949e5a3adaade809960f6f5d4 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Sat, 27 Sep 2008 12:59:50 +0400 Subject: [PATCH] SM Test runner: location url was added to TextProxy --- .../runner/GeneralToSMTRunnerEventsConvertor.java | 6 ++-- .../ruby/testing/sm/runner/SMTestProxy.java | 19 +++++++++++- .../sm/runner/ui/SMTestRunnerResultsForm.java | 2 +- .../testing/sm/runner/BaseSMTRunnerTestCase.java | 4 +-- .../GeneralToSMTRunnerEventsConvertorTest.java | 34 ++++++++++++++++++++-- 5 files changed, 55 insertions(+), 10 deletions(-) diff --git a/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/GeneralToSMTRunnerEventsConvertor.java b/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/GeneralToSMTRunnerEventsConvertor.java index bf19d83aad..a28f0cd84a 100644 --- a/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/GeneralToSMTRunnerEventsConvertor.java +++ b/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/GeneralToSMTRunnerEventsConvertor.java @@ -76,7 +76,6 @@ public class GeneralToSMTRunnerEventsConvertor implements GeneralTestEventsProce } public void onTestStarted(final String testName, final String locationUrl) { - //TODO[romeo] : location info UIUtil.addToInvokeLater(new Runnable() { public void run() { final String fullName = getFullTestName(testName); @@ -90,7 +89,7 @@ public class GeneralToSMTRunnerEventsConvertor implements GeneralTestEventsProce final SMTestProxy parentSuite = getCurrentSuite(); // creates test - final SMTestProxy testProxy = new SMTestProxy(testName, false); + final SMTestProxy testProxy = new SMTestProxy(testName, false, locationUrl); parentSuite.addChild(testProxy); // adds to running tests map myRunningTestsFullNameToProxy.put(fullName, testProxy); @@ -105,12 +104,11 @@ public class GeneralToSMTRunnerEventsConvertor implements GeneralTestEventsProce } public void onSuiteStarted(final String suiteName, final String locationUrl) { - //TODO[romeo] : location info UIUtil.addToInvokeLater(new Runnable() { public void run() { final SMTestProxy parentSuite = getCurrentSuite(); //new suite - final SMTestProxy newSuite = new SMTestProxy(suiteName, true); + final SMTestProxy newSuite = new SMTestProxy(suiteName, true, locationUrl); parentSuite.addChild(newSuite); mySuitesStack.pushSuite(newSuite); diff --git a/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/SMTestProxy.java b/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/SMTestProxy.java index 0ca61d6fa2..4e975f377b 100644 --- a/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/SMTestProxy.java +++ b/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/SMTestProxy.java @@ -28,6 +28,7 @@ public class SMTestProxy extends CompositePrintable implements PrintableTestProx private AbstractState myState = NotRunState.getInstance(); private String myName; private Integer myDuration = null; // duration is unknown + @Nullable private String myLocationUrl; private boolean myDurationIsCached = false; // is used for separating unknown and unset duration @@ -35,9 +36,11 @@ public class SMTestProxy extends CompositePrintable implements PrintableTestProx private final boolean myIsSuite; - public SMTestProxy(final String testName, final boolean isSuite) { + public SMTestProxy(final String testName, final boolean isSuite, + @Nullable final String locationUrl) { myName = testName; myIsSuite = isSuite; + myLocationUrl = locationUrl; } public boolean isInProgress() { @@ -89,6 +92,12 @@ public class SMTestProxy extends CompositePrintable implements PrintableTestProx @Nullable public Location getLocation(final Project project) { + //final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(myMethod.replace( + // File.separatorChar, '/')); + //if (virtualFile != null) + // return PsiLocation.fromPsiElement(project, PsiManager.getInstance(project).findFile(virtualFile)); + //return null; + //TODO //determines location of test proxy return null; @@ -96,6 +105,9 @@ public class SMTestProxy extends CompositePrintable implements PrintableTestProx @Nullable public Navigatable getDescriptor(final Location location) { + //if (location != null) return EditSourceUtil.getDescriptor(location.getPsiElement()); + //return null; + //TODO // by location gets navigatable element. // It can be file or place in file (e.g. when OPEN_FAILURE_LINE is enabled) @@ -327,6 +339,11 @@ public class SMTestProxy extends CompositePrintable implements PrintableTestProx return myState.wasTerminated(); } + @Nullable + protected String getLocationUrl() { + return myLocationUrl; + } + /** * Check if suite contains error tests or suites * @return True if contains diff --git a/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/ui/SMTestRunnerResultsForm.java b/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/ui/SMTestRunnerResultsForm.java index 4a005183cd..1322ae5570 100644 --- a/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/ui/SMTestRunnerResultsForm.java +++ b/plugins/ruby/src/org/jetbrains/plugins/ruby/testing/sm/runner/ui/SMTestRunnerResultsForm.java @@ -119,7 +119,7 @@ public class SMTestRunnerResultsForm implements TestFrameworkRunningModel, LogCo //Create tests common suite root //noinspection HardCodedStringLiteral - myTestsRootNode = new SMTestProxy("[root]", true); + myTestsRootNode = new SMTestProxy("[root]", true, null); //Adds tabs view component myTabs = new JBTabsImpl(project, diff --git a/plugins/ruby/testSrc/org/jetbrains/plugins/ruby/testing/sm/runner/BaseSMTRunnerTestCase.java b/plugins/ruby/testSrc/org/jetbrains/plugins/ruby/testing/sm/runner/BaseSMTRunnerTestCase.java index 71b3c0cd7e..475381e765 100644 --- a/plugins/ruby/testSrc/org/jetbrains/plugins/ruby/testing/sm/runner/BaseSMTRunnerTestCase.java +++ b/plugins/ruby/testSrc/org/jetbrains/plugins/ruby/testing/sm/runner/BaseSMTRunnerTestCase.java @@ -38,7 +38,7 @@ public abstract class BaseSMTRunnerTestCase extends LightIdeaTestCase { } protected SMTestProxy createTestProxy(final String name, final SMTestProxy parentSuite) { - final SMTestProxy proxy = new SMTestProxy(name, false); + final SMTestProxy proxy = new SMTestProxy(name, false, null); if (parentSuite != null) { parentSuite.addChild(proxy); } @@ -50,7 +50,7 @@ public abstract class BaseSMTRunnerTestCase extends LightIdeaTestCase { } protected SMTestProxy createSuiteProxy(final String name, final SMTestProxy parentSuite) { - final SMTestProxy suite = new SMTestProxy(name, true); + final SMTestProxy suite = new SMTestProxy(name, true, null); if (parentSuite != null) { parentSuite.addChild(suite); } diff --git a/plugins/ruby/testSrc/org/jetbrains/plugins/ruby/testing/sm/runner/GeneralToSMTRunnerEventsConvertorTest.java b/plugins/ruby/testSrc/org/jetbrains/plugins/ruby/testing/sm/runner/GeneralToSMTRunnerEventsConvertorTest.java index 8dec24b295..0b48c5382a 100644 --- a/plugins/ruby/testSrc/org/jetbrains/plugins/ruby/testing/sm/runner/GeneralToSMTRunnerEventsConvertorTest.java +++ b/plugins/ruby/testSrc/org/jetbrains/plugins/ruby/testing/sm/runner/GeneralToSMTRunnerEventsConvertorTest.java @@ -2,6 +2,7 @@ package org.jetbrains.plugins.ruby.testing.sm.runner; import com.intellij.execution.testframework.TestConsoleProperties; import com.intellij.openapi.util.Disposer; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.ruby.Marker; import org.jetbrains.plugins.ruby.testing.sm.runner.ui.SMTRunnerConsoleView; import org.jetbrains.plugins.ruby.testing.sm.runner.ui.SMTRunnerTestTreeView; @@ -96,6 +97,15 @@ public class GeneralToSMTRunnerEventsConvertorTest extends BaseSMTRunnerTestCase assertEquals(1, myEventsProcessor.getRunningTestsQuantity()); } + public void testOnTestStarted_WithLocation() throws InterruptedException { + onTestStarted("some_test", "file://some/file.rb:1"); + final String fullName = myEventsProcessor.getFullTestName("some_test"); + final SMTestProxy proxy = myEventsProcessor.getProxyByFullTestName(fullName); + + assertNotNull(proxy); + assertEquals("file://some/file.rb:1", proxy.getLocationUrl()); + } + public void testOnTestFailure() { onTestStarted("some_test"); myEventsProcessor.onTestFailure("some_test", "", "", false); @@ -278,6 +288,18 @@ public class GeneralToSMTRunnerEventsConvertorTest extends BaseSMTRunnerTestCase myEventsProcessor.onSuiteFinished("suite1"); } + public void testOnSuiteStarted_WithLocation() { + onTestSuiteStarted("suite1", "file://some/file.rb:1"); + + //lets check that new tests have right parent + onTestStarted("test1", "file://some/file.rb:4"); + final SMTestProxy test1 = + myEventsProcessor.getProxyByFullTestName(myEventsProcessor.getFullTestName("test1")); + + assertEquals("file://some/file.rb:1", test1.getParent().getLocationUrl()); + assertEquals("file://some/file.rb:4", test1.getLocationUrl()); + } + public void testGetCurrentTestSuite() { assertEquals(myResultsViewer.getTestsRootNode(), myEventsProcessor.getCurrentSuite()); @@ -310,12 +332,20 @@ public class GeneralToSMTRunnerEventsConvertorTest extends BaseSMTRunnerTestCase } private void onTestStarted(final String testName) { - myEventsProcessor.onTestStarted(testName, null); + onTestStarted(testName, null); + } + + private void onTestStarted(final String testName, @Nullable final String locationUrl) { + myEventsProcessor.onTestStarted(testName, locationUrl); myResultsViewer.performUpdate(); } private void onTestSuiteStarted(final String suiteName) { - myEventsProcessor.onSuiteStarted(suiteName, null); + onTestSuiteStarted(suiteName, null); + } + + private void onTestSuiteStarted(final String suiteName, @Nullable final String locationUrl) { + myEventsProcessor.onSuiteStarted(suiteName, locationUrl); myResultsViewer.performUpdate(); } } -- 2.11.4.GIT