fixed hanging JSExtFileInspectionTest: ensure that we always run inspection in tests with the context which supports 'finished' flag

This commit is contained in:
nik
2015-02-05 19:18:30 +03:00
parent 54fac7397f
commit ae80a32678
4 changed files with 51 additions and 17 deletions
@@ -42,6 +42,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests;
import com.intellij.util.ArrayUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
@@ -145,7 +146,7 @@ public abstract class InspectionTestCase extends PsiTestCase {
InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject());
InspectionToolWrapper[] toolWrappers = runDeadCodeFirst ? new InspectionToolWrapper []{getUnusedDeclarationWrapper(), toolWrapper} : new InspectionToolWrapper []{toolWrapper};
toolWrappers = ArrayUtil.mergeArrays(toolWrappers, additional);
final GlobalInspectionContextImpl globalContext =
final GlobalInspectionContextForTests globalContext =
CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, toolWrappers);
InspectionTestUtil.runTool(toolWrapper, scope, globalContext);
@@ -22,7 +22,7 @@ import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ui.InspectionToolPresentation;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests;
import com.intellij.util.ui.UIUtil;
import org.jdom.Document;
import org.jdom.Element;
@@ -153,7 +153,7 @@ expected:
public static void runTool(@NotNull InspectionToolWrapper toolWrapper,
@NotNull final AnalysisScope scope,
@NotNull final GlobalInspectionContextImpl globalContext) {
@NotNull final GlobalInspectionContextForTests globalContext) {
final String shortName = toolWrapper.getShortName();
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
if (key == null){
@@ -164,6 +164,6 @@ expected:
do {
UIUtil.dispatchAllInvocationEvents();
}
while (!CodeInsightTestFixtureImpl.isInspectionsFinished(globalContext));
while (!globalContext.isFinished());
}
}
@@ -462,19 +462,19 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
scope.invalidate();
InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject());
GlobalInspectionContextImpl globalContext = createGlobalContextForTool(scope, getProject(), inspectionManager, toolWrapper);
GlobalInspectionContextForTests globalContext = createGlobalContextForTool(scope, getProject(), inspectionManager, toolWrapper);
InspectionTestUtil.runTool(toolWrapper, scope, globalContext);
InspectionTestUtil.compareToolResults(globalContext, toolWrapper, false, new File(getTestDataPath(), testDir).getPath());
}
@NotNull
public static GlobalInspectionContextImpl createGlobalContextForTool(@NotNull AnalysisScope scope,
public static GlobalInspectionContextForTests createGlobalContextForTool(@NotNull AnalysisScope scope,
@NotNull final Project project,
@NotNull InspectionManagerEx inspectionManager,
@NotNull final InspectionToolWrapper ... toolWrappers) {
final InspectionProfileImpl profile = InspectionProfileImpl.createSimple("test", project, toolWrappers);
GlobalInspectionContextImpl context = new GlobalInspectionContextImpl(project, inspectionManager.getContentManager()) {
GlobalInspectionContextForTests context = new GlobalInspectionContextForTests(project, inspectionManager.getContentManager()) {
@Override
protected List<Tools> getUsedTools() {
try {
@@ -488,21 +488,11 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
InspectionProfileImpl.INIT_INSPECTIONS = false;
}
}
@Override
protected void notifyInspectionsFinished() {
super.notifyInspectionsFinished();
putUserData(FINISHED, true);
}
};
context.setCurrentScope(scope);
return context;
}
private static final Key<Boolean> FINISHED = Key.create("Inspections finished");
public static boolean isInspectionsFinished(@NotNull GlobalInspectionContext context) {
return context.getUserData(FINISHED) == Boolean.TRUE;
}
@Override
@Nullable
@@ -0,0 +1,43 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.testFramework.fixtures.impl;
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.ui.content.ContentManager;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public class GlobalInspectionContextForTests extends GlobalInspectionContextImpl {
private volatile boolean myFinished;
public GlobalInspectionContextForTests(@NotNull Project project, @NotNull NotNullLazyValue<ContentManager> contentManager) {
super(project, contentManager);
}
@Override
protected void notifyInspectionsFinished() {
super.notifyInspectionsFinished();
myFinished = true;
}
public boolean isFinished() {
return myFinished;
}
}