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)");
}
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)");
}
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");
}
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
}
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);
}
}
}
Aggregations