From 687e45b26248e80ff2c3bd2256f8e2f8f862a678 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Thu, 22 Oct 2015 16:29:55 +0300 Subject: [PATCH] test framework: use case-sensitive file lookup in more places (IDEA-CR-6089) --- .../codeInsight/CodeInsightTestCase.java | 42 +++++-------------- .../intellij/testFramework/IdeaTestUtil.java | 3 +- .../intellij/testFramework/PsiTestCase.java | 3 +- .../testFramework/ResolveTestCase.java | 6 +-- .../intellij/testFramework/VfsTestUtil.java | 17 ++++++++ 5 files changed, 31 insertions(+), 40 deletions(-) diff --git a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java index f611ae7cbf80..e7c6dbfe15a2 100644 --- a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java @@ -40,7 +40,6 @@ import com.intellij.openapi.roots.ContentEntry; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; @@ -119,12 +118,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { if (files.length == 0) return null; final VirtualFile[] vFiles = new VirtualFile[files.length]; for (int i = 0; i < files.length; i++) { - String path = files[i]; - final String fullPath = FileUtil.toSystemIndependentName(getTestDataPath() + path); - allowRootAccess(fullPath); - VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath); - vFiles[i] = vFile; - assertNotNull("file " + fullPath + " not found", vFile); + vFiles[i] = findVirtualFile(files[i]); } File projectFile = projectRoot == null ? null : new File(getTestDataPath() + projectRoot); @@ -143,12 +137,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { } protected VirtualFile configureByFile(@NonNls String filePath, @Nullable String projectRoot) throws Exception { - String fullPath = getTestDataPath() + filePath; - allowRootAccess(fullPath); - - final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/')); - assertNotNull("file " + fullPath + " not found", vFile); - + VirtualFile vFile = findVirtualFile(filePath); File projectFile = projectRoot == null ? null : new File(getTestDataPath() + projectRoot); return configureByFile(vFile, projectFile); @@ -467,11 +456,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { PsiDocumentManager.getInstance(myProject).commitAllDocuments(); - String fullPath = getTestDataPath() + filePath; - allowRootAccess(fullPath); - - final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/')); - assertNotNull("Cannot find file " + fullPath, vFile); + VirtualFile vFile = findVirtualFile(filePath); String ft; try { ft = VfsUtilCore.loadText(vFile); @@ -541,21 +526,16 @@ public abstract class CodeInsightTestCase extends PsiTestCase { } } + @NotNull protected VirtualFile getVirtualFile(@NonNls @NotNull String filePath) { - String fullPath = getTestDataPath() + filePath; - allowRootAccess(fullPath); + return findVirtualFile(filePath); + } - String vfsPath = FileUtil.toSystemIndependentName(fullPath); - VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(vfsPath); - assertNotNull("file " + fullPath + " not found", vFile); - String realVfsPath = vFile.getPath(); - if (!SystemInfo.isFileSystemCaseSensitive && !vfsPath.equals(realVfsPath) && - vfsPath.equalsIgnoreCase(realVfsPath)) { - fail("Please correct case-sensitivity of path to prevent test failure on case-sensitive file systems:\n" + - " path " + vfsPath + "\n" + - "real path " + realVfsPath); - } - return vFile; + @NotNull + private VirtualFile findVirtualFile(@NonNls @NotNull String filePath) { + String absolutePath = getTestDataPath() + filePath; + allowRootAccess(absolutePath); + return VfsTestUtil.findFileByCaseSensitivePath(absolutePath); } @NotNull diff --git a/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java b/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java index d850be711527..f6ad08c80230 100644 --- a/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java +++ b/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java @@ -132,8 +132,7 @@ public class IdeaTestUtil extends PlatformTestUtil { private static VirtualFile findJar(String name) { String path = PathManager.getHomePath() + '/' + name; - VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path); - assert file != null : "not found: " + path; + VirtualFile file = VfsTestUtil.findFileByCaseSensitivePath(path); VirtualFile jar = JarFileSystem.getInstance().getJarRootForLocalFile(file); assert jar != null : "no .jar for: " + path; return jar; diff --git a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java index 26153fac55c5..476f584e86f0 100644 --- a/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/PsiTestCase.java @@ -117,8 +117,7 @@ public abstract class PsiTestCase extends ModuleTestCase { } protected PsiElement configureByFileWithMarker(String filePath, String marker) throws Exception{ - final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(filePath.replace(File.separatorChar, '/')); - assertNotNull("file " + filePath + " not found", vFile); + final VirtualFile vFile = VfsTestUtil.findFileByCaseSensitivePath(filePath); String fileText = VfsUtil.loadText(vFile); fileText = StringUtil.convertLineSeparators(fileText); diff --git a/java/testFramework/src/com/intellij/testFramework/ResolveTestCase.java b/java/testFramework/src/com/intellij/testFramework/ResolveTestCase.java index 865a6f76ed30..941b34cf29ea 100644 --- a/java/testFramework/src/com/intellij/testFramework/ResolveTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/ResolveTestCase.java @@ -19,7 +19,6 @@ import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiManager; @@ -27,8 +26,6 @@ import com.intellij.psi.PsiReference; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.File; - public abstract class ResolveTestCase extends PsiTestCase { protected static final String MARKER = ""; @@ -48,8 +45,7 @@ public abstract class ResolveTestCase extends PsiTestCase { } protected PsiReference configureByFile(@TestDataFile @NotNull String filePath, @Nullable VirtualFile parentDir) throws Exception { - final String fullPath = getTestDataPath() + filePath; - final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/')); + final VirtualFile vFile = VfsTestUtil.findFileByCaseSensitivePath(getTestDataPath() + filePath); assertNotNull("file " + filePath + " not found", vFile); String fileText = StringUtil.convertLineSeparators(VfsUtilCore.loadText(vFile)); diff --git a/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java index 0ed47ddfdffe..f9019cf47ee9 100644 --- a/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/VfsTestUtil.java @@ -18,7 +18,9 @@ package com.intellij.testFramework; import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.PathUtil; @@ -115,4 +117,19 @@ public class VfsTestUtil { throw new AssertionError(e); } } + + @NotNull + public static VirtualFile findFileByCaseSensitivePath(@NotNull String absolutePath) { + String vfsPath = FileUtil.toSystemIndependentName(absolutePath); + VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(vfsPath); + Assert.assertNotNull("file " + absolutePath + " not found", vFile); + String realVfsPath = vFile.getPath(); + if (!SystemInfo.isFileSystemCaseSensitive && !vfsPath.equals(realVfsPath) && + vfsPath.equalsIgnoreCase(realVfsPath)) { + Assert.fail("Please correct case-sensitivity of path to prevent test failure on case-sensitive file systems:\n" + + " path " + vfsPath + "\n" + + "real path " + realVfsPath); + } + return vFile; + } }