[tests] Fix running our Cucumber tests from IDEA

* Add a runtime dependency to cucumber-test-runner module to
  ruby-tests and git4idea. Otherwise CucumberMain can't be
  specified as a runner in the run configuration.
* Remove dependency on the Application from CucumberMain,
  just call EventQueue.invokeAndWait.
* Move application initialization to git and ruby hooks - to the place
  where correct platform prefix can be defined.
This commit is contained in:
Kirill Likhodedov
2013-03-27 13:34:40 +04:00
parent e2273baf13
commit b6289ee552
4 changed files with 42 additions and 19 deletions
@@ -16,13 +16,14 @@
package com.intellij.cucumber;
import com.intellij.idea.IdeaTestApplication;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Ref;
import cucumber.io.MultiLoader;
import cucumber.runtime.Runtime;
import cucumber.runtime.RuntimeOptions;
import java.awt.*;
/**
* @author Dennis.Ushakov
*/
@@ -33,25 +34,31 @@ public class CucumberMain {
}
public static void main(final String[] args) {
IdeaTestApplication.getInstance(null);
final Ref<Throwable> errorRef = new Ref<Throwable>();
final Ref<Runtime> runtimeRef = new Ref<Runtime>();
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
try {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
RuntimeOptions runtimeOptions = new RuntimeOptions(System.getProperties(), args);
cucumber.runtime.Runtime runtime = new Runtime(new MultiLoader(classLoader), classLoader, runtimeOptions);
runtimeRef.set(runtime);
runtime.writeStepdefsJson();
runtime.run();
} catch (Throwable throwable) {
errorRef.set(throwable);
Logger.getInstance(CucumberMain.class).error(throwable);
try {
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
RuntimeOptions runtimeOptions = new RuntimeOptions(System.getProperties(), args);
Runtime runtime = new Runtime(new MultiLoader(classLoader), classLoader, runtimeOptions);
runtimeRef.set(runtime);
runtime.writeStepdefsJson();
runtime.run();
} catch (Throwable throwable) {
errorRef.set(throwable);
Logger.getInstance(CucumberMain.class).error(throwable);
}
}
}
}, ApplicationManager.getApplication().getDefaultModalityState());
});
}
catch (Throwable t) {
errorRef.set(t);
Logger.getInstance(CucumberMain.class).error(t);
}
final Throwable throwable = errorRef.get();
if (throwable != null) {
throwable.printStackTrace();
+1
View File
@@ -67,6 +67,7 @@
<orderEntry type="library" scope="TEST" name="cucumber-java" level="project" />
<orderEntry type="library" name="JSch" level="project" />
<orderEntry type="module" module-name="spellchecker" />
<orderEntry type="module" module-name="cucumber-test-runner" scope="RUNTIME" />
</component>
</module>
@@ -1,6 +1,7 @@
package git4idea;
import com.intellij.dvcs.test.MockVcsHelper;
import com.intellij.idea.IdeaTestApplication;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.components.ServiceManager;
@@ -82,6 +83,7 @@ public class GitCucumberWorld {
@Order(0)
public void setUp() throws Throwable {
System.setProperty(PlatformUtils.PLATFORM_PREFIX_KEY, "PlatformLangXml");
IdeaTestApplication.getInstance(null);
String tempFileName = getClass().getName() + "-" + new Random().nextInt();
myProjectFixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(tempFileName).getFixture();
@@ -64,9 +64,22 @@ public class HgRepositorySelectorComponent {
return repo.getPresentableUrl();
}
@Override
public boolean equals(Object obj) {
return obj instanceof RepositoryDisplay && this.repo.equals(((RepositoryDisplay)obj).repo);
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RepositoryDisplay display = (RepositoryDisplay)o;
if (repo != null ? !repo.equals(display.repo) : display.repo != null) return false;
return true;
}
@Override
public int hashCode() {
return repo != null ? repo.hashCode() : 0;
}
@Override