com.intellij.execution.actions.ConfigurationContext Java Examples
The following examples show how to use
com.intellij.execution.actions.ConfigurationContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestMethodSelectionUtil.java From intellij with Apache License 2.0 | 6 votes |
/** * Get all test methods directly or indirectly selected in the given context. This includes * methods selected in the Structure panel, as well as methods the context location is inside of. * * @param context The context to get selected test methods from. * @param allMustMatch If true, will return null if any selected elements are not test methods. * @return A list of test methods (with at least one element), or null if: * <ul> * <li>There are no selected test methods * <li>{@code allMustMatch} is true, but elements other than test methods are selected * </ul> * * @see #getDirectlySelectedMethods(ConfigurationContext, boolean) * @see #getIndirectlySelectedMethod(ConfigurationContext) */ @Nullable public static List<PsiMethod> getSelectedMethods( @NotNull ConfigurationContext context, boolean allMustMatch) { List<PsiMethod> directlySelectedMethods = getDirectlySelectedMethods(context, allMustMatch); if (directlySelectedMethods != null && directlySelectedMethods.size() > 0) { return directlySelectedMethods; } if (allMustMatch && JUnitConfigurationUtil.isMultipleElementsSelected(context)) { return null; } PsiMethod indirectlySelectedMethod = getIndirectlySelectedMethod(context); if (indirectlySelectedMethod != null) { return Collections.singletonList(indirectlySelectedMethod); } return null; }
Example #2
Source File: BlazeBuildFileRunConfigurationProducerTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testProducedFromFuncallExpression() { PsiFile buildFile = workspace.createPsiFile( new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'"); FuncallExpression target = PsiUtils.findFirstChildOfClassRecursive(buildFile, FuncallExpression.class); assertThat(target).isNotNull(); ConfigurationContext context = createContextFromPsi(target); List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext(); assertThat(configurations).hasSize(1); ConfigurationFromContext fromContext = configurations.get(0); assertThat(fromContext.isProducedBy(BlazeBuildFileRunConfigurationProducer.class)).isTrue(); assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class); BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration(); assertThat(config.getTargets()) .containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:unit_tests")); assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST); }
Example #3
Source File: TestContextRunConfigurationProducer.java From intellij with Apache License 2.0 | 6 votes |
@Nullable private RunConfigurationContext findTestContext(ConfigurationContext context) { if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) { // handled by a different producer return null; } ContextWrapper wrapper = new ContextWrapper(context); PsiElement psi = context.getPsiLocation(); return psi == null ? null : CachedValuesManager.getCachedValue( psi, cacheKey, () -> CachedValueProvider.Result.create( doFindTestContext(wrapper.context), PsiModificationTracker.MODIFICATION_COUNT, BlazeSyncModificationTracker.getInstance(wrapper.context.getProject()))); }
Example #4
Source File: BlazeJavaTestMethodConfigurationProducerTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testConfigWithDifferentLabelIsIgnored() { // Arrange PsiMethod method = setupGenericJunitTestClassAndBlazeTarget(); ConfigurationContext context = createContextFromPsi(method); BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration(); // modify the label, and check that is enough for the producer to class it as different. config.setTarget(Label.create("//java/com/google/test:DifferentTestTarget")); // Act boolean isConfigFromContext = new TestContextRunConfigurationProducer().doIsConfigFromContext(config, context); // Assert assertThat(isConfigFromContext).isFalse(); }
Example #5
Source File: BlazeBuildFileRunConfigurationProducerTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testTestSuiteMacroNameRecognized() { PsiFile buildFile = workspace.createPsiFile( new WorkspacePath("java/com/google/test/BUILD"), "random_junit4_test_suites(name='gen_tests'"); FuncallExpression target = PsiUtils.findFirstChildOfClassRecursive(buildFile, FuncallExpression.class); ConfigurationContext context = createContextFromPsi(target); List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext(); assertThat(configurations).hasSize(1); ConfigurationFromContext fromContext = configurations.get(0); assertThat(fromContext.isProducedBy(BlazeBuildFileRunConfigurationProducer.class)).isTrue(); assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class); BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration(); assertThat(config.getTargets()) .containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:gen_tests")); assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST); }
Example #6
Source File: ScenarioExecutionProducer.java From Intellij-Plugin with Apache License 2.0 | 6 votes |
private int getScenarioIdentifier(ConfigurationContext context, PsiFile file) { int count = NO_SCENARIOS; PsiElement selectedElement = context.getPsiLocation(); if (selectedElement == null) return NON_SCENARIO_CONTEXT; String scenarioHeading = (!selectedElement.getClass().equals(SpecScenarioImpl.class)) ? getScenarioHeading(selectedElement) : selectedElement.getText(); if (scenarioHeading.equals("")) return getNumberOfScenarios(file) == 0 ? NO_SCENARIOS : NON_SCENARIO_CONTEXT; for (PsiElement psiElement : file.getChildren()) { if (psiElement.getClass().equals(SpecScenarioImpl.class)) { count++; if (psiElement.getNode().getFirstChildNode().getText().equals(scenarioHeading)) { return StringUtil.offsetToLineNumber(psiElement.getContainingFile().getText(), psiElement.getTextOffset()) + 1; } } } return count == NO_SCENARIOS ? NO_SCENARIOS : NON_SCENARIO_CONTEXT; }
Example #7
Source File: MultipleJavaClassesTestContextProvider.java From intellij with Apache License 2.0 | 6 votes |
@Nullable @Override public RunConfigurationContext getTestContext(ConfigurationContext context) { boolean outsideProject = context.getModule() == null; if (outsideProject) { // TODO(brendandouglas): resolve PSI asynchronously for files outside the project return null; } PsiElement location = context.getPsiLocation(); if (location instanceof PsiDirectory) { PsiDirectory dir = (PsiDirectory) location; ListenableFuture<TargetInfo> future = getTargetContext(dir); return futureEmpty(future) ? null : fromDirectory(future, dir); } Set<PsiClass> testClasses = selectedTestClasses(context); if (testClasses.size() <= 1) { return null; } ListenableFuture<TargetInfo> target = getTestTargetIfUnique(context.getProject(), testClasses); if (futureEmpty(target)) { return null; } testClasses = ProducerUtils.includeInnerTestClasses(testClasses); return fromClasses(target, testClasses); }
Example #8
Source File: TomcatRunConfigurationProducer.java From SmartTomcat with Apache License 2.0 | 6 votes |
@Override public boolean isConfigurationFromContext(@NotNull TomcatRunConfiguration configuration, @NotNull ConfigurationContext context) { boolean result = false; VirtualFile vf = context.getLocation().getVirtualFile(); if (vf != null && vf.isDirectory()) { Module module = context.getModule(); Optional<VirtualFile> webModule = getWebModule(module); boolean isWebModule = webModule.isPresent(); if (isWebModule) { VirtualFile virtualFile = webModule.get(); if (vf.getCanonicalPath().equals(virtualFile.getCanonicalPath())) { result = true; } } } return result; }
Example #9
Source File: ScalaBinaryContextProvider.java From intellij with Apache License 2.0 | 6 votes |
@Nullable static ScObject getMainObject(ConfigurationContext context) { Location location = context.getLocation(); if (location == null) { return null; } location = JavaExecutionUtil.stepIntoSingleClass(context.getLocation()); if (location == null) { return null; } PsiElement element = location.getPsiElement(); if (!(element.getContainingFile() instanceof ScalaFile)) { return null; } if (!element.isPhysical()) { return null; } return getMainObjectFromElement(element); }
Example #10
Source File: BlazeFilterAndroidTestRunConfigurationProducer.java From intellij with Apache License 2.0 | 6 votes |
@Override protected boolean doIsConfigFromContext( BlazeCommandRunConfiguration configuration, ConfigurationContext context) { BlazeAndroidTestRunConfigurationState handlerState = configuration.getHandlerStateIfType(BlazeAndroidTestRunConfigurationState.class); if (handlerState == null) { return false; } TestLocationName locationName = getTestLocationName(context); if (locationName == null) { return false; } if (locationName.methodName.isEmpty()) { return (handlerState.getMethodName().isEmpty() && locationName.className.equals(handlerState.getClassName())); } return locationName.methodName.equals(handlerState.getMethodName()); }
Example #11
Source File: PyTestContextProvider.java From intellij with Apache License 2.0 | 6 votes |
@Nullable @Override public RunConfigurationContext getTestContext(ConfigurationContext context) { PsiElement element = selectedPsiElement(context); if (element == null) { return null; } TestLocation testLocation = testLocation(element); if (testLocation == null) { return null; } ListenableFuture<TargetInfo> testTarget = TestTargetHeuristic.targetFutureForPsiElement(element, /* testSize= */ null); if (testTarget == null) { return null; } PythonTestFilterInfo filterInfo = testLocation.testFilter(); return TestContext.builder(testLocation.sourceElement(), ExecutorType.DEBUG_SUPPORTED_TYPES) .setTarget(testTarget) .setTestFilter(filterInfo.filter) .setDescription(filterInfo.description) .build(); }
Example #12
Source File: ScalaTestContextProvider.java From intellij with Apache License 2.0 | 6 votes |
@Nullable @Override public RunConfigurationContext getTestContext(ConfigurationContext context) { ScClass testClass = getTestClass(context); if (testClass == null) { return null; } ListenableFuture<TargetInfo> target = TestTargetHeuristic.targetFutureForPsiElement( testClass, TestSizeFinder.getTestSize(testClass)); if (target == null) { return null; } return TestContext.builder(testClass, ExecutorType.DEBUG_SUPPORTED_TYPES) .setTarget(target) .setTestFilter(getTestFilter(testClass)) .setDescription(testClass.getName()) .build(); }
Example #13
Source File: OldJavascriptTestContextProviderTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testClosureTestSuite() { 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(RuleTypes.WEB_TEST.getKind()); assertThat(configuration.getTargets()) .containsExactly(TargetExpression.fromStringSafe("//foo/bar:foo_test_chrome-linux")); }
Example #14
Source File: BlazeBuildFileRunConfigurationProducerTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testConfigFromContextRecognizesItsOwnConfig() { PsiFile buildFile = workspace.createPsiFile( new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'"); StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class); ConfigurationContext context = createContextFromPsi(nameString); BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration(); assertThat( new BlazeBuildFileRunConfigurationProducer() .isConfigurationFromContext(config, context)) .isTrue(); }
Example #15
Source File: BlazeJavaAbstractTestCaseConfigurationProducer.java From intellij with Apache License 2.0 | 6 votes |
@VisibleForTesting static void chooseSubclass( ConfigurationFromContext configuration, ConfigurationContext context, Runnable startRunnable) { RunConfiguration config = configuration.getConfiguration(); if (!(config instanceof BlazeCommandRunConfiguration)) { return; } AbstractTestLocation location = locationFromConfiguration(configuration); if (location == null) { return; } SubclassTestChooser.chooseSubclass( context, location.abstractClass, (psiClass) -> { if (psiClass != null) { setupContext((BlazeCommandRunConfiguration) config, psiClass, location.method); } startRunnable.run(); }); }
Example #16
Source File: FlutterTestConfigProducer.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Returns true if a run config was already created for this file. If so we will reuse it. */ @Override public boolean isConfigurationFromContext(TestConfig config, ConfigurationContext context) { final VirtualFile fileOrDir = config.getFields().getFileOrDir(); if (fileOrDir == null) return false; final PsiElement target = context.getPsiLocation(); if (target instanceof PsiDirectory) { return ((PsiDirectory)target).getVirtualFile().equals(fileOrDir); } if (!FlutterRunConfigurationProducer.hasDartFile(context, fileOrDir.getPath())) return false; final String testName = testConfigUtils.findTestName(context.getPsiLocation()); if (config.getFields().getScope() == TestFields.Scope.NAME) { return testName != null && testName.equals(config.getFields().getTestName()); } else { return testName == null; } }
Example #17
Source File: Utils.java From MavenHelper with Apache License 2.0 | 6 votes |
public static String getTestArgument(@Nullable PsiFile psiFile, ConfigurationContext context) { RunnerAndConfigurationSettings configuration = context.getConfiguration(); String classAndMethod = null; if (configuration != null) { classAndMethod = configuration.getName().replace(".", "#"); } String result; String packageName = null; if (psiFile instanceof PsiClassOwner) { packageName = ((PsiClassOwner) psiFile).getPackageName(); } if (isNotBlank(packageName) && isNotBlank(classAndMethod)) { result = packageName + "." + classAndMethod; } else if (isNotBlank(classAndMethod)) { result = classAndMethod; } else { result = NOT_RESOLVED; } return result; }
Example #18
Source File: FlutterRunConfigurationProducer.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * If the current file contains the main method for a Flutter app, updates the FutterRunConfiguration * and sets its corresponding source location. * <p> * Returns false if it wasn't a match. */ @Override protected boolean setupConfigurationFromContext(final @NotNull SdkRunConfig config, final @NotNull ConfigurationContext context, final @NotNull Ref<PsiElement> sourceElement) { final VirtualFile main = getFlutterEntryFile(context, true, true); if (main == null) return false; config.setFields(new SdkFields(main)); config.setGeneratedName(); final PsiElement elt = sourceElement.get(); if (elt != null) { sourceElement.set(elt.getContainingFile()); } return true; }
Example #19
Source File: AllInPackageTestContextProviderTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testProducedFromPsiDirectory() { setProjectView( "directories:", " java/com/google/test", "targets:", " //java/com/google/test:lib"); PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java/com/google/test")); workspace.createPsiFile( new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'"); ConfigurationContext context = createContextFromPsi(directory); 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("//java/com/google/test:all")); assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST); }
Example #20
Source File: JavascriptTestContextProviderTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testMultipleBrowsers() { PsiFile jsTestFile = configure(ImmutableList.of("chrome-linux", "firefox-linux"), "function testFoo() {}"); ConfigurationContext context = createContextFromPsi(jsTestFile); ConfigurationFromContext configurationFromContext = getConfigurationFromContext(context); BlazeCommandRunConfiguration configuration = getBlazeRunConfiguration(configurationFromContext); assertThat(configuration.getPendingContext()).isNotNull(); assertThat(configuration.getPendingContext()).isInstanceOf(PendingWebTestContext.class); PendingWebTestContext testContext = (PendingWebTestContext) configuration.getPendingContext(); testContext.updateContextAndRerun( configuration, TargetInfo.builder(Label.create("//foo/bar:foo_test_firefox-linux"), "js_web_test").build(), () -> {}); assertThat(configuration.getTargetKind()).isEqualTo(Kind.fromRuleName("js_web_test")); assertThat(configuration.getTargets()) .containsExactly(TargetExpression.fromStringSafe("//foo/bar:foo_test_firefox-linux")); }
Example #21
Source File: OldJavascriptTestContextProviderTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testOldStyleClosureTestSuite() { 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(RuleTypes.WEB_TEST.getKind()); assertThat(configuration.getTargets()) .containsExactly(TargetExpression.fromStringSafe("//foo/bar:foo_test_chrome-linux")); }
Example #22
Source File: MongoScriptRunConfigurationProducer.java From nosql4idea with Apache License 2.0 | 6 votes |
@Nullable @Override protected RunnerAndConfigurationSettings createConfigurationByElement(Location location, ConfigurationContext configurationContext) { sourceFile = location.getPsiElement().getContainingFile(); if (sourceFile != null && sourceFile.getFileType().getName().toLowerCase().contains("javascript")) { Project project = sourceFile.getProject(); VirtualFile file = sourceFile.getVirtualFile(); RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, configurationContext); MongoRunConfiguration runConfiguration = (MongoRunConfiguration) settings.getConfiguration(); runConfiguration.setName(file.getName()); runConfiguration.setScriptPath(file.getPath()); Module module = ModuleUtil.findModuleForPsiElement(location.getPsiElement()); if (module != null) { runConfiguration.setModule(module); } return settings; } return null; }
Example #23
Source File: GaugeExecutionProducer.java From Intellij-Plugin with Apache License 2.0 | 6 votes |
@Override protected boolean setupConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context, Ref sourceElement) { VirtualFile[] selectedFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context.getDataContext()); if (selectedFiles == null || selectedFiles.length > 1) return false; Module module = context.getModule(); if (context.getPsiLocation() == null || module == null) return false; PsiFile file = context.getPsiLocation().getContainingFile(); if (!isSpecFile(file) || !isInSpecScope(context.getPsiLocation())) return false; try { VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) return false; String name = virtualFile.getCanonicalPath(); configuration.setName(file.getName()); ((GaugeRunConfiguration) configuration).setSpecsToExecute(name); ((GaugeRunConfiguration) configuration).setModule(module); return true; } catch (Exception ex) { LOG.debug(ex); ex.printStackTrace(); } return true; }
Example #24
Source File: ScalaBinaryContextProvider.java From intellij with Apache License 2.0 | 5 votes |
@Nullable @Override public BinaryRunContext getRunContext(ConfigurationContext context) { ScObject mainObject = getMainObject(context); if (mainObject == null) { return null; } TargetIdeInfo target = getTarget(context.getProject(), mainObject); if (target == null) { return null; } Option<PsiMethod> mainMethod = ScalaSdkCompat.findMainMethod(mainObject); PsiElement sourceElement = mainMethod.getOrElse(() -> mainObject); return BinaryRunContext.create(sourceElement, target.toTargetInfo()); }
Example #25
Source File: RuntimeConfigurationProducer.java From consulo with Apache License 2.0 | 5 votes |
public RuntimeConfigurationProducer createProducer(final Location location, final ConfigurationContext context) { final RuntimeConfigurationProducer result = clone(); result.myConfiguration = location != null ? result.createConfigurationByElement(location, context) : null; if (result.myConfiguration != null) { final PsiElement psiElement = result.getSourceElement(); final Location<PsiElement> _location = PsiLocation.fromPsiElement(psiElement, location != null ? location.getModule() : null); if (_location != null) { // replace with existing configuration if any final RunManager runManager = RunManager.getInstance(context.getProject()); final ConfigurationType type = result.myConfiguration.getType(); final List<RunnerAndConfigurationSettings> configurations = runManager.getConfigurationSettingsList(type); final RunnerAndConfigurationSettings configuration = result.findExistingByElement(_location, configurations, context); if (configuration != null) { result.myConfiguration = configuration; } else { final ArrayList<String> currentNames = new ArrayList<>(); for (RunnerAndConfigurationSettings configurationSettings : configurations) { currentNames.add(configurationSettings.getName()); } result.myConfiguration.setName(RunManager.suggestUniqueName(result.myConfiguration.getName(), currentNames)); } } } return result; }
Example #26
Source File: BlazeJavaAbstractTestCaseConfigurationProducer.java From intellij with Apache License 2.0 | 5 votes |
@Override protected boolean doSetupConfigFromContext( BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) { AbstractTestLocation location = getAbstractLocation(context); if (location == null) { return false; } sourceElement.set(location.method != null ? location.method : location.abstractClass); configuration.setName( "Choose subclass for " + configName(location.abstractClass, location.method)); configuration.setNameChangedByUser(true); return true; }
Example #27
Source File: CreateCustomGoalAction.java From MavenHelper with Apache License 2.0 | 5 votes |
public void actionPerformed(AnActionEvent e) { ApplicationService instance = ApplicationService.getInstance(); ApplicationSettings state = instance.getState(); DataContext context = e.getDataContext(); Project project = MavenActionUtil.getProject(context); String pomDir = Utils.getPomDirAsString(context, mavenProject); MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context); PsiFile data = LangDataKeys.PSI_FILE.getData(e.getDataContext()); ConfigurationContext configurationContext = ConfigurationContext.getFromContext(e.getDataContext()); GoalEditor editor = new GoalEditor("Create and Run", "", state, true, e.getProject(), e.getDataContext()); if (editor.showAndGet()) { String s = editor.getCmd(); if (StringUtils.isNotBlank(s)) { Goal goal = new Goal(s); PropertiesComponent.getInstance().setValue(GoalEditor.SAVE, editor.isPersist(), true); if (editor.isPersist()) { state.getGoals().add(goal); instance.registerAction(goal, getRunGoalAction(goal)); } if (runGoal) { getRunGoalAction(goal).actionPerformed(project, pomDir, projectsManager, data, configurationContext); } } } }
Example #28
Source File: TestContextRunConfigurationProducer.java From intellij with Apache License 2.0 | 5 votes |
@Override protected boolean doSetupConfigFromContext( BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) { RunConfigurationContext testContext = findTestContext(context); if (testContext == null) { return false; } if (!testContext.setupRunConfiguration(configuration)) { return false; } sourceElement.set(testContext.getSourceElement()); return true; }
Example #29
Source File: KotlinTestContextProvider.java From intellij with Apache License 2.0 | 5 votes |
@Nullable @Override public RunConfigurationContext getTestContext(ConfigurationContext context) { Location<?> location = context.getLocation(); if (location == null) { return null; } PsiElement element = location.getPsiElement(); KtNamedFunction testMethod = PsiUtils.getParentOfType(element, KtNamedFunction.class, false); KtClass testClass = PsiUtils.getParentOfType(element, KtClass.class, false); if (testClass == null) { return null; } // TODO: detect test size from kotlin source code ListenableFuture<TargetInfo> target = TestTargetHeuristic.targetFutureForPsiElement(testClass, /* testSize= */ null); if (target == null) { return null; } String filter = getTestFilter(testClass, testMethod); String description = testClass.getName(); if (testMethod != null) { description += "." + testMethod.getName(); } PsiElement contextElement = testMethod != null ? testMethod : testClass; return TestContext.builder(contextElement, ExecutorType.DEBUG_SUPPORTED_TYPES) .setTarget(target) .setTestFilter(filter) .setDescription(description) .build(); }
Example #30
Source File: PyBinaryContextProviderTest.java From intellij with Apache License 2.0 | 5 votes |
@Test public void testProducedFromPyFile() { 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); }