use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class BlazeJavaAbstractTestCaseConfigurationProducerTest method testConfigurationCreatedFromAbstractClass.
@Test
public void testConfigurationCreatedFromAbstractClass() throws Throwable {
workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
PsiFile abstractClassFile = createAndIndexFile(new WorkspacePath("java/com/google/test/AbstractTestCase.java"), "package com.google.test;", "public abstract class AbstractTestCase {}");
createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass.java"), "package com.google.test;", "import com.google.test.AbstractTestCase;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass extends AbstractTestCase {", " @org.junit.Test", " public void testMethod1() {}", " @org.junit.Test", " public void testMethod2() {}", "}");
PsiClass javaClass = ((PsiClassOwner) abstractClassFile).getClasses()[0];
assertThat(javaClass).isNotNull();
ConfigurationContext context = createContextFromPsi(abstractClassFile);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(BlazeJavaAbstractTestCaseConfigurationProducer.class)).isTrue();
assertThat(fromContext.getSourceElement()).isEqualTo(javaClass);
RunConfiguration config = fromContext.getConfiguration();
assertThat(config).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration blazeConfig = (BlazeCommandRunConfiguration) config;
assertThat(blazeConfig.getTargets()).isEmpty();
assertThat(blazeConfig.getName()).isEqualTo("Choose subclass for AbstractTestCase");
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:TestClass").addSource(sourceRoot("java/com/google/test/TestClass.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
BlazeJavaAbstractTestCaseConfigurationProducer.chooseSubclass(fromContext, context, EmptyRunnable.INSTANCE);
assertThat(blazeConfig.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:TestClass"));
assertThat(getTestFilterContents(blazeConfig)).isEqualTo(BlazeFlags.TEST_FILTER + "=com.google.test.TestClass#");
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class JavascriptTestContextProviderTest method testClosureTestSuite.
@Test
public void testClosureTestSuite() throws Throwable {
PsiFile jsTestFile = configure(ImmutableList.of("chrome-linux"), "goog.module('foo.bar.fooTest');", "goog.setTestOnly();", "const testSuite = goog.require('goog.testing.testSuite');", "testSuite({", " testFoo() {},", "});");
ConfigurationContext context = createContextFromPsi(jsTestFile);
ConfigurationFromContext configurationFromContext = getConfigurationFromContext(context);
BlazeCommandRunConfiguration configuration = getBlazeRunConfiguration(configurationFromContext);
assertThat(configuration.getTargetKind()).isEqualTo(Kind.fromRuleName("js_web_test"));
assertThat(configuration.getTargets()).containsExactly(TargetExpression.fromStringSafe("//foo/bar:foo_test_chrome-linux"));
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class JavascriptTestContextProviderTest method testOldStyleClosureTestSuite.
@Test
public void testOldStyleClosureTestSuite() throws Throwable {
createAndIndexFile(WorkspacePath.createIfValid("javascript/closure/testing/testsuite.js"), "goog.provide('goog.testing.testSuite');", "goog.setTestOnly('goog.testing.testSuite');", "goog.testing.testSuite = function(obj, opt_options) {}");
PsiFile jsTestFile = configure(ImmutableList.of("chrome-linux"), "goog.require('goog.testing.testSuite');", "goog.testing.testSuite({", " testFoo() {},", "});");
ConfigurationContext context = createContextFromPsi(jsTestFile);
ConfigurationFromContext configurationFromContext = getConfigurationFromContext(context);
BlazeCommandRunConfiguration configuration = getBlazeRunConfiguration(configurationFromContext);
assertThat(configuration.getTargetKind()).isEqualTo(Kind.fromRuleName("js_web_test"));
assertThat(configuration.getTargets()).containsExactly(TargetExpression.fromStringSafe("//foo/bar:foo_test_chrome-linux"));
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class JavascriptTestContextProviderTest method testTopLevelFunctions.
@Test
public void testTopLevelFunctions() throws Throwable {
PsiFile jsTestFile = configure(ImmutableList.of("chrome-linux"), "function testFoo() {}");
ConfigurationContext context = createContextFromPsi(jsTestFile);
ConfigurationFromContext configurationFromContext = getConfigurationFromContext(context);
BlazeCommandRunConfiguration configuration = getBlazeRunConfiguration(configurationFromContext);
assertThat(configuration.getTargetKind()).isEqualTo(Kind.fromRuleName("js_web_test"));
assertThat(configuration.getTargets()).containsExactly(TargetExpression.fromStringSafe("//foo/bar:foo_test_chrome-linux"));
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class PyBinaryContextProviderTest method testProducedFromPyFile.
@Test
public void testProducedFromPyFile() throws Throwable {
PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/bin/main.py"), "def main():", " return", "if __name__ == '__main__':", " main()");
workspace.createFile(new WorkspacePath("py/bin/BUILD"), "py_binary(name = 'main')");
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_binary").setLabel("//py/bin:main").addSource(sourceRoot("py/bin/main.py")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
ConfigurationContext context = createContextFromPsi(pyFile);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(BinaryContextRunConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//py/bin:main"));
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.RUN);
}
Aggregations