Search in sources :

Example 31 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazePyTestConfigurationProducerTest method testProducedFromTestCaseWithNamedParametersDictList.

@Test
public void testProducedFromTestCaseWithNamedParametersDictList() throws Throwable {
    PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/test/unittest.py"), "class UnitTest(parameterized.TestCase):", "  @parameterized.named_parameters([", "    {'testcase_name': '_First', value: 1},", "    {'testcase_name': '_Second', value: 100},", "  ])", "  def testSomething(self, value):", "    return");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_test").setLabel("//py/test:unittests").addSource(sourceRoot("py/test/unittest.py")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
    assertThat(function).isNotNull();
    ConfigurationContext context = createContextFromPsi(function);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(TestContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//py/test:unittests"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=\"UnitTest.testSomething_First UnitTest.testSomething_Second\"");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
    assertThat(config.getName()).isEqualTo("Blaze test UnitTest.testSomething (unittest.py)");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PyFunction(com.jetbrains.python.psi.PyFunction) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 32 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazePyTestConfigurationProducerTest method testProducedFromTestCaseWithNamedParametersTupleAndUnderscores.

@Test
public void testProducedFromTestCaseWithNamedParametersTupleAndUnderscores() throws Throwable {
    PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/test/unittest.py"), "class UnitTest(parameterized.TestCase):", "  @parameterized.named_parameters(", "    ('First', 1),", // intentional underscore
    "    ('_Second', 100),", "  )", "  def test_something(self, value):", "    return");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_test").setLabel("//py/test:unittests").addSource(sourceRoot("py/test/unittest.py")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
    assertThat(function).isNotNull();
    ConfigurationContext context = createContextFromPsi(function);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(TestContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//py/test:unittests"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=\"UnitTest.test_something_First UnitTest.test_something_Second\"");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
    assertThat(config.getName()).isEqualTo("Blaze test UnitTest.test_something (unittest.py)");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PyFunction(com.jetbrains.python.psi.PyFunction) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 33 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazePyTestConfigurationProducerTest method testProducedFromPyFile.

@Test
public void testProducedFromPyFile() throws Throwable {
    PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/test/unittest.py"), "class UnitTest(googletest.TestCase):", "  def testSomething():", "    return");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_test").setLabel("//py/test:unittests").addSource(sourceRoot("py/test/unittest.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(TestContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//py/test:unittests"));
    assertThat(getTestFilterContents(config)).isNull();
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
    assertThat(config.getName()).isEqualTo("Blaze test unittest.py");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 34 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class ScalaSpecs2TestContextProviderTest method testSpecs2TestProducedFromPsiClass.

@Test
public void testSpecs2TestProducedFromPsiClass() throws Throwable {
    PsiFile file = createTestPsiFile();
    assertThat(file).isInstanceOf(ScalaFile.class);
    ScalaFile scalaFile = (ScalaFile) file;
    PsiClass[] classes = scalaFile.getClasses();
    assertThat(classes).isNotEmpty();
    PsiClass testClass = classes[0];
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_junit_test").setLabel("//scala/com/google/test:TestClass").addSource(sourceRoot("scala/com/google/test/TestClass.scala")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    ConfigurationContext context = createContextFromPsi(testClass);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).isNotNull();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(TestContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//scala/com/google/test:TestClass"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test.TestClass#");
    assertThat(config.getName()).isEqualTo("Blaze test TestClass");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
// TODO: add tests for infix expression run configurations
// TODO: also test BlazeScalaTestEventsHandler
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ScalaFile(org.jetbrains.plugins.scala.lang.psi.api.ScalaFile) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 35 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij-plugins by JetBrains.

the class FlexUnitConfigurationTest method doTest.

private void doTest(String filename) throws Exception {
    configureByFile(BASE_PATH + filename);
    final Map<Integer, String> markers = JSTestUtils.extractPositionMarkers(getProject(), getEditor().getDocument());
    assertFalse("No caret markers found", markers.isEmpty());
    assertFalse("No 'expected' value", markers.containsValue(null));
    final DataContext dataContext = DataManager.getInstance().getDataContext(getEditor().getComponent());
    int i = 1;
    for (Map.Entry<Integer, String> marker : markers.entrySet()) {
        String place = filename + ": marker " + i++ + ": ";
        getEditor().getCaretModel().moveToOffset(marker.getKey());
        final ConfigurationFromContext configurationFromContext = new FlexUnitRuntimeConfigurationProducer().createConfigurationFromContext(ConfigurationContext.getFromContext(dataContext));
        final RunConfiguration configuration = configurationFromContext == null ? null : configurationFromContext.getConfiguration();
        if ("null".equals(marker.getValue())) {
            assertNull(place + "Null configuration expected", configuration);
        } else {
            assertNotNull(place + "Not null configuration expected", configuration);
            assertTrue(place + "Invalid configuration", configuration instanceof FlexUnitRunConfiguration);
            final String[] expected;
            if ("null".equals(marker.getValue())) {
                expected = null;
            } else {
                expected = marker.getValue().split(" ");
                assertEquals(place + "Expected should be in the form: \"Class com.test.Foo\" or \"Method com.test.Foo.testBar()\" or \"Package com.test\"", 2, expected.length);
            }
            final FlexUnitRunnerParameters params = ((FlexUnitRunConfiguration) configuration).getRunnerParameters();
            assertEquals(place + "Invalid scope", expected[0], params.getScope().name());
            final String definition;
            switch(params.getScope()) {
                case Class:
                    definition = params.getClassName();
                    break;
                case Method:
                    definition = params.getClassName() + "." + params.getMethodName() + "()";
                    break;
                case Package:
                    definition = params.getPackageName();
                    break;
                default:
                    fail(place + "Unknown scope: " + params.getScope());
                    definition = null;
            }
            assertEquals(place + "Invalid definition", expected[1], definition);
        }
    }
}
Also used : FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) FlexUnitRuntimeConfigurationProducer(com.intellij.lang.javascript.flex.flexunit.FlexUnitRuntimeConfigurationProducer) DataContext(com.intellij.openapi.actionSystem.DataContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) Map(java.util.Map)

Aggregations

ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)76 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)69 Test (org.junit.Test)61 PsiFile (com.intellij.psi.PsiFile)56 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)54 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)50 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)38 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)38 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)13 PsiClass (com.intellij.psi.PsiClass)13 PsiDirectory (com.intellij.psi.PsiDirectory)10 PyFunction (com.jetbrains.python.psi.PyFunction)8 PsiElement (com.intellij.psi.PsiElement)6 TestContextRunConfigurationProducer (com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer)4 DataContext (com.intellij.openapi.actionSystem.DataContext)4 Project (com.intellij.openapi.project.Project)4 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)3 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)3 BallerinaApplicationConfiguration (org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationConfiguration)3 BallerinaApplicationRunConfigurationProducer (org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationRunConfigurationProducer)3