Search in sources :

Example 1 with TempDirTestFixture

use of com.intellij.testFramework.fixtures.TempDirTestFixture in project intellij-community by JetBrains.

the class HgTestRepository method cloneRepository.

/**
   * Clones a repository from this one. New repository is located in a new temporary test directory.
   * @return New repository cloned from this one.
   */
public HgTestRepository cloneRepository() throws Exception {
    final TempDirTestFixture dirFixture = createFixtureDir();
    final ProcessOutput processOutput = myTest.runHg(null, "clone", getDirFixture().getTempDirPath(), dirFixture.getTempDirPath());
    AbstractVcsTestCase.verify(processOutput);
    return new HgTestRepository(myTest, dirFixture);
}
Also used : TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture) ProcessOutput(com.intellij.execution.process.ProcessOutput)

Example 2 with TempDirTestFixture

use of com.intellij.testFramework.fixtures.TempDirTestFixture in project intellij-community by JetBrains.

the class HgTestRepository method createFixtureDir.

private static TempDirTestFixture createFixtureDir() throws Exception {
    final TempDirTestFixture fixture = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
    fixture.setUp();
    return fixture;
}
Also used : TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture)

Example 3 with TempDirTestFixture

use of com.intellij.testFramework.fixtures.TempDirTestFixture in project intellij-community by JetBrains.

the class FindUsagesTest method testNonCodeClassUsages.

public void testNonCodeClassUsages() throws Exception {
    final TempDirTestFixture tdf = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
    tdf.setUp();
    try {
        new WriteCommandAction(getProject()) {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                final ModifiableModuleModel moduleModel = ModuleManager.getInstance(getProject()).getModifiableModel();
                moduleModel.newModule("independent/independent.iml", StdModuleTypes.JAVA.getId());
                moduleModel.commit();
                tdf.createFile("plugin.xml", "<document>\n" + "  <action class=\"com.Foo\" />\n" + "  <action class=\"com.Foo.Bar\" />\n" + "  <action class=\"com.Foo$Bar\" />\n" + "</document>");
                PsiTestUtil.addContentRoot(ModuleManager.getInstance(getProject()).findModuleByName("independent"), tdf.getFile(""));
            }
        }.execute();
        GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
        PsiClass foo = myJavaFacade.findClass("com.Foo", scope);
        PsiClass bar = myJavaFacade.findClass("com.Foo.Bar", scope);
        final int[] count = { 0 };
        Processor<UsageInfo> processor = usageInfo -> {
            int navigationOffset = usageInfo.getNavigationOffset();
            assertTrue(navigationOffset > 0);
            String textAfter = usageInfo.getFile().getText().substring(navigationOffset);
            assertTrue(textAfter, textAfter.startsWith("Foo") || textAfter.startsWith("Bar") || textAfter.startsWith("com.Foo.Bar"));
            count[0]++;
            return true;
        };
        JavaFindUsagesHandler handler = new JavaFindUsagesHandler(bar, JavaFindUsagesHandlerFactory.getInstance(getProject()));
        count[0] = 0;
        handler.processUsagesInText(foo, processor, scope);
        assertEquals(3, count[0]);
        count[0] = 0;
        handler.processUsagesInText(bar, processor, scope);
        assertEquals(2, count[0]);
    } finally {
        tdf.tearDown();
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture) ModuleManager(com.intellij.openapi.module.ModuleManager) JavaFindUsagesHandlerFactory(com.intellij.find.findUsages.JavaFindUsagesHandlerFactory) UsageInfo(com.intellij.usageView.UsageInfo) IntArrayList(com.intellij.util.containers.IntArrayList) ArrayList(java.util.ArrayList) MethodReferencesSearch(com.intellij.psi.search.searches.MethodReferencesSearch) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) IdeaTestUtil(com.intellij.testFramework.IdeaTestUtil) PsiTestCase(com.intellij.testFramework.PsiTestCase) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) PsiTestUtil(com.intellij.testFramework.PsiTestUtil) JavaTestUtil(com.intellij.JavaTestUtil) OverridingMethodsSearch(com.intellij.psi.search.searches.OverridingMethodsSearch) Collection(java.util.Collection) TextRange(com.intellij.openapi.util.TextRange) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) JavaFindUsagesHandler(com.intellij.find.findUsages.JavaFindUsagesHandler) List(java.util.List) Result(com.intellij.openapi.application.Result) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) IdeaTestFixtureFactory(com.intellij.testFramework.fixtures.IdeaTestFixtureFactory) Collections(java.util.Collections) TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture) JavaFindUsagesHandler(com.intellij.find.findUsages.JavaFindUsagesHandler) Result(com.intellij.openapi.application.Result) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) UsageInfo(com.intellij.usageView.UsageInfo)

Example 4 with TempDirTestFixture

use of com.intellij.testFramework.fixtures.TempDirTestFixture in project intellij-community by JetBrains.

the class FindManagerTest method testFindInCurrentFileOutsideProject.

public void testFindInCurrentFileOutsideProject() throws Exception {
    final TempDirTestFixture tempDirFixture = new TempDirTestFixtureImpl();
    tempDirFixture.setUp();
    try {
        VirtualFile file = tempDirFixture.createFile("a.txt", "foo bar foo");
        FindModel findModel = FindManagerTestUtils.configureFindModel("foo");
        findModel.setWholeWordsOnly(true);
        findModel.setCustomScope(true);
        findModel.setCustomScope(new LocalSearchScope(PsiManager.getInstance(myProject).findFile(file)));
        assertSize(2, findUsages(findModel));
    } finally {
        tempDirFixture.tearDown();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture) LightTempDirTestFixtureImpl(com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl) TempDirTestFixtureImpl(com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl)

Example 5 with TempDirTestFixture

use of com.intellij.testFramework.fixtures.TempDirTestFixture in project intellij-community by JetBrains.

the class FindManagerTest method testLocalScopeSearchPerformance.

public void testLocalScopeSearchPerformance() throws Exception {
    final int fileCount = 3000;
    final int lineCount = 500;
    TempDirTestFixture fixture = new LightTempDirTestFixtureImpl();
    fixture.setUp();
    try {
        String sampleText = StringUtil.repeat("zoo TargetWord foo bar goo\n", lineCount);
        for (int i = 0; i < fileCount; i++) {
            fixture.createFile("a" + i + ".txt", sampleText);
        }
        PsiTestUtil.addSourceContentToRoots(myModule, fixture.getFile(""));
        VirtualFile file = fixture.createFile("target.txt", sampleText);
        PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
        assertNotNull(psiFile);
        final FindModel findModel = new FindModel();
        findModel.setStringToFind("TargetWord");
        findModel.setWholeWordsOnly(true);
        findModel.setFromCursor(false);
        findModel.setGlobal(true);
        findModel.setMultipleFiles(true);
        findModel.setCustomScope(true);
        ThrowableRunnable test = () -> assertSize(lineCount, findUsages(findModel));
        findModel.setCustomScope(GlobalSearchScope.fileScope(psiFile));
        PlatformTestUtil.startPerformanceTest("slow", 400, test).attempts(2).cpuBound().usesAllCPUCores().useLegacyScaling().assertTiming();
        findModel.setCustomScope(new LocalSearchScope(psiFile));
        PlatformTestUtil.startPerformanceTest("slow", 400, test).attempts(2).cpuBound().usesAllCPUCores().useLegacyScaling().assertTiming();
    } finally {
        fixture.tearDown();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture) ThrowableRunnable(com.intellij.util.ThrowableRunnable) LightTempDirTestFixtureImpl(com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl)

Aggregations

TempDirTestFixture (com.intellij.testFramework.fixtures.TempDirTestFixture)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Result (com.intellij.openapi.application.Result)3 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 LightTempDirTestFixtureImpl (com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl)3 TempDirTestFixtureImpl (com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl)3 ProcessOutput (com.intellij.execution.process.ProcessOutput)2 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 File (java.io.File)2 JavaTestUtil (com.intellij.JavaTestUtil)1 JavaFindUsagesHandler (com.intellij.find.findUsages.JavaFindUsagesHandler)1 JavaFindUsagesHandlerFactory (com.intellij.find.findUsages.JavaFindUsagesHandlerFactory)1 StdFileTypes (com.intellij.openapi.fileTypes.StdFileTypes)1 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFileFilter (com.intellij.openapi.vfs.VirtualFileFilter)1 com.intellij.psi (com.intellij.psi)1