mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tests must not crash when run under windows without enough privileges to create symlinks
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ public class ProjectRootUtilSymlinkedFilesTest extends PlatformTestCase {
|
||||
|
||||
@Override
|
||||
protected boolean shouldRunTest() {
|
||||
return super.shouldRunTest() && SystemInfo.areSymLinksSupported;
|
||||
return super.shouldRunTest() && SystemInfo.isSymLinkCreationSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
@@ -140,6 +140,7 @@ public class CanonicalPathMapTest {
|
||||
|
||||
@Test
|
||||
public void remappedSymLinkReportsOriginalWatchedPath() throws IOException {
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
// Tests the situation where the watch root is a symlink AND REMAPPED by the native file watcher.
|
||||
File realDir = myTempDir.newFolder("real");
|
||||
File symLink = IoTestUtil.createSymLink(realDir.getPath(), myTempDir.getRoot() + "/link");
|
||||
|
||||
@@ -32,12 +32,9 @@ import com.intellij.util.Alarm
|
||||
import com.intellij.util.TimeoutUtil
|
||||
import com.intellij.util.concurrency.Semaphore
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.After
|
||||
import org.junit.*
|
||||
import org.junit.Assume.assumeFalse
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
@@ -228,6 +225,7 @@ class FileWatcherTest : BareTestFixtureTestCase() {
|
||||
|
||||
// ensure that flat roots set via symbolic paths behave correctly and do not report dirty files returned from other recursive roots
|
||||
@Test fun testSymbolicLinkIntoFlatRoot() {
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported()
|
||||
val root = tempDir.newFolder("root")
|
||||
val cDir = tempDir.newFolder("root/A/B/C")
|
||||
val aLink = File(root, "aLink")
|
||||
@@ -243,6 +241,8 @@ class FileWatcherTest : BareTestFixtureTestCase() {
|
||||
}
|
||||
|
||||
@Test fun testMultipleSymbolicLinkPathsToFile() {
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported()
|
||||
|
||||
val root = tempDir.newFolder("root")
|
||||
val file = tempDir.newFile("root/A/B/C/test.txt")
|
||||
val bLink = File(root, "bLink")
|
||||
@@ -261,6 +261,7 @@ class FileWatcherTest : BareTestFixtureTestCase() {
|
||||
}
|
||||
|
||||
@Test fun testSymbolicLinkWatchRoot() {
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported()
|
||||
val top = tempDir.newFolder("top")
|
||||
val file = tempDir.newFile("top/dir1/dir2/dir3/test.txt")
|
||||
val link = Files.createSymbolicLink(Paths.get(top.path, "link"), Paths.get("${top.path}/dir1/dir2")).toFile()
|
||||
@@ -274,6 +275,7 @@ class FileWatcherTest : BareTestFixtureTestCase() {
|
||||
}
|
||||
|
||||
@Test fun testSymbolicLinkAboveWatchRoot() {
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported()
|
||||
val top = tempDir.newFolder("top")
|
||||
val file = tempDir.newFile("top/dir1/dir2/dir3/test.txt")
|
||||
val link = Files.createSymbolicLink(Paths.get(top.path, "link"), Paths.get("${top.path}/dir1/dir2")).toFile()
|
||||
@@ -474,7 +476,7 @@ class FileWatcherTest : BareTestFixtureTestCase() {
|
||||
}
|
||||
|
||||
@Test fun testLineBreaksInName() {
|
||||
assumeTrue(SystemInfo.isUnix)
|
||||
assumeTrue("Expected Unix", SystemInfo.isUnix)
|
||||
|
||||
val root = tempDir.newFolder("root")
|
||||
val file = tempDir.newFile("root/weird\ndir\nname/weird\nfile\nname")
|
||||
|
||||
+2
-2
@@ -571,7 +571,7 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase {
|
||||
|
||||
@Test
|
||||
public void testSymlinkTargetBlink() throws IOException {
|
||||
assumeTrue(SystemInfo.areSymLinksSupported);
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
|
||||
File target = tempDir.newFolder("target");
|
||||
File link = new File(tempDir.getRoot(), "link");
|
||||
@@ -700,7 +700,7 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase {
|
||||
|
||||
@Test
|
||||
public void testBrokenSymlinkMove() {
|
||||
assumeTrue(SystemInfo.areSymLinksSupported);
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
|
||||
runInEdtAndWait(() -> {
|
||||
File srcDir = tempDir.newFolder("src");
|
||||
|
||||
+2
-2
@@ -4,6 +4,7 @@ package com.intellij.openapi.vfs.local;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.IoTestUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.testFramework.fixtures.BareTestFixtureTestCase;
|
||||
@@ -21,14 +22,13 @@ import java.util.Set;
|
||||
|
||||
import static com.intellij.openapi.util.io.IoTestUtil.*;
|
||||
import static com.intellij.testFramework.PlatformTestUtil.assertPathsEqual;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
public class SymlinkHandlingTest extends BareTestFixtureTestCase {
|
||||
@Rule public TempDirectory myTempDir = new TempDirectory();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
assumeTrue(SystemInfo.areSymLinksSupported);
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,6 +10,8 @@ import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assume;
|
||||
import org.junit.AssumptionViolatedException;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -82,6 +84,10 @@ public class IoTestUtil {
|
||||
return linkFile;
|
||||
}
|
||||
|
||||
public static void assumeSymLinkCreationIsSupported() throws AssumptionViolatedException {
|
||||
Assume.assumeTrue("Expected can create symlinks", SystemInfo.isSymLinkCreationSupported);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File createJunction(@NotNull String target, @NotNull String junction) {
|
||||
assertTrue(SystemInfo.isWindows);
|
||||
|
||||
@@ -6,6 +6,9 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.lang.JavaVersion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -87,6 +90,28 @@ public class SystemInfo extends SystemInfoRt {
|
||||
|
||||
public static final boolean isFileSystemCaseSensitive = SystemInfoRt.isFileSystemCaseSensitive;
|
||||
public static final boolean areSymLinksSupported = isUnix || isWinVistaOrNewer;
|
||||
public static final boolean isSymLinkCreationSupported = isUnix || isWinVistaOrNewer && holdsEnoughPrivilegesToCreateSymlinks();
|
||||
|
||||
private static boolean holdsEnoughPrivilegesToCreateSymlinks() {
|
||||
try {
|
||||
File src = File.createTempFile("tempSrc", ".txt");
|
||||
src.delete();
|
||||
File dest = File.createTempFile("tempDst", ".txt");
|
||||
try {
|
||||
Files.createSymbolicLink(src.toPath(), dest.toPath());
|
||||
}
|
||||
catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
dest.delete();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final boolean is32Bit = SystemInfoRt.is32Bit;
|
||||
public static final boolean is64Bit = SystemInfoRt.is64Bit;
|
||||
|
||||
@@ -195,7 +195,7 @@ public abstract class FileAttributesReadingTest {
|
||||
|
||||
@Test
|
||||
public void linkToFile() throws IOException {
|
||||
assumeTrue(SystemInfo.areSymLinksSupported);
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
|
||||
File file = tempDir.newFile("file.txt");
|
||||
FileUtil.writeToFile(file, myTestData);
|
||||
@@ -217,7 +217,7 @@ public abstract class FileAttributesReadingTest {
|
||||
|
||||
@Test
|
||||
public void doubleLink() throws IOException {
|
||||
assumeTrue(SystemInfo.areSymLinksSupported);
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
|
||||
File file = tempDir.newFile("file.txt");
|
||||
FileUtil.writeToFile(file, myTestData);
|
||||
@@ -241,7 +241,7 @@ public abstract class FileAttributesReadingTest {
|
||||
|
||||
@Test
|
||||
public void linkToDirectory() throws IOException {
|
||||
assumeTrue(SystemInfo.areSymLinksSupported);
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
|
||||
File dir = tempDir.newFolder("dir");
|
||||
if (SystemInfo.isUnix) assertTrue(dir.setWritable(false, false));
|
||||
@@ -262,7 +262,7 @@ public abstract class FileAttributesReadingTest {
|
||||
|
||||
@Test
|
||||
public void missingLink() throws IOException {
|
||||
assumeTrue(SystemInfo.areSymLinksSupported);
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
|
||||
File file = new File(tempDir.getRoot(), "file.txt");
|
||||
File link = new File(tempDir.getRoot(), "link");
|
||||
@@ -279,7 +279,7 @@ public abstract class FileAttributesReadingTest {
|
||||
|
||||
@Test
|
||||
public void selfLink() throws IOException {
|
||||
assumeTrue(SystemInfo.areSymLinksSupported);
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
|
||||
File dir = tempDir.newFolder("dir");
|
||||
File link = new File(dir, "link");
|
||||
@@ -470,7 +470,7 @@ public abstract class FileAttributesReadingTest {
|
||||
File link = new File(tempDir.getRoot(), "link");
|
||||
Files.createLink(link.toPath(), target.toPath());
|
||||
|
||||
FileAttributes attributes = getAttributes(link, SystemInfo.areSymLinksSupported); // ignore XP
|
||||
FileAttributes attributes = getAttributes(link, SystemInfo.isSymLinkCreationSupported); // ignore XP
|
||||
assertEquals(FileAttributes.Type.FILE, attributes.type);
|
||||
assertEquals(target.length(), attributes.length);
|
||||
assertTimestampsEqual(target.lastModified(), attributes.lastModified);
|
||||
@@ -485,7 +485,7 @@ public abstract class FileAttributesReadingTest {
|
||||
assertEquals(myTestData.length, bytes.length);
|
||||
}
|
||||
|
||||
attributes = getAttributes(link, SystemInfo.areSymLinksSupported); // ignore XP
|
||||
attributes = getAttributes(link, SystemInfo.isSymLinkCreationSupported); // ignore XP
|
||||
assertEquals(FileAttributes.Type.FILE, attributes.type);
|
||||
assertEquals(target.length(), attributes.length);
|
||||
assertTimestampsEqual(target.lastModified(), attributes.lastModified);
|
||||
|
||||
@@ -223,7 +223,7 @@ public class FileUtilHeavyTest {
|
||||
|
||||
@Test
|
||||
public void testSymlinkDeletion() {
|
||||
assumeTrue(SystemInfo.areSymLinksSupported);
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
|
||||
File targetDir = IoTestUtil.createTestDir(myTempDirectory, "lnk_del_test_1");
|
||||
IoTestUtil.createTestFile(targetDir, "file");
|
||||
@@ -255,7 +255,7 @@ public class FileUtilHeavyTest {
|
||||
|
||||
@Test
|
||||
public void testToCanonicalPathSymLinksAware() throws IOException {
|
||||
assumeTrue(SystemInfo.areSymLinksSupported);
|
||||
IoTestUtil.assumeSymLinkCreationIsSupported();
|
||||
|
||||
File rootDir = IoTestUtil.createTestDir(myTempDirectory, "root");
|
||||
assertTrue(new File(rootDir, "dir1/dir2/dir3/dir4").mkdirs());
|
||||
|
||||
Reference in New Issue
Block a user