test framework: use case-sensitive file lookup in more places (IDEA-CR-6089)

This commit is contained in:
Sergey Simonchik
2015-10-22 16:29:55 +03:00
parent 65430c26d0
commit 687e45b262
5 changed files with 31 additions and 40 deletions
@@ -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
@@ -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;
@@ -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);
@@ -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 = "<ref>";
@@ -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));
@@ -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;
}
}