mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[tests] symlink-related tests fixed on OS X
This commit is contained in:
+3
-3
@@ -16,9 +16,9 @@
|
||||
package com.intellij.openapi.vfs.impl.local;
|
||||
|
||||
import com.intellij.openapi.util.io.IoTestUtil;
|
||||
import com.intellij.testFramework.rules.TempDirectory;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
@@ -28,7 +28,7 @@ import static com.intellij.openapi.util.Pair.pair;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class CanonicalPathMapTest {
|
||||
@Rule public TemporaryFolder myTempDir = new TemporaryFolder();
|
||||
@Rule public TempDirectory myTempDir = new TempDirectory();
|
||||
|
||||
@Test
|
||||
public void testRemappedSymLinkReportsOriginalWatchedPath() throws Exception {
|
||||
@@ -41,7 +41,7 @@ public class CanonicalPathMapTest {
|
||||
CanonicalPathMap pathMap = new CanonicalPathMap(Collections.singletonList(symLink.getPath()), Collections.emptyList());
|
||||
|
||||
// REMAP from native file watcher: /?/root/mapped -> /?/root/real
|
||||
pathMap.addMapping(Collections.singletonList(pair(mappedDir.getPath(), realDir.getCanonicalPath())));
|
||||
pathMap.addMapping(Collections.singletonList(pair(mappedDir.getPath(), realDir.getPath())));
|
||||
|
||||
Collection<String> watchedPaths = pathMap.getWatchedPaths(new File(mappedDir, "file.txt").getPath(), true, false);
|
||||
assertThat(watchedPaths).containsExactly(new File(symLink, "file.txt").getPath());
|
||||
|
||||
+2
-2
@@ -22,12 +22,12 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.testFramework.fixtures.BareTestFixtureTestCase;
|
||||
import com.intellij.testFramework.rules.TempDirectory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
@@ -40,7 +40,7 @@ import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
public class SymlinkHandlingTest extends BareTestFixtureTestCase {
|
||||
@Rule public TemporaryFolder myTempDir = new TemporaryFolder();
|
||||
@Rule public TempDirectory myTempDir = new TempDirectory();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.rules;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* A clone of {@link TemporaryFolder} with no symlinks in a temporary directory path and better directory name.
|
||||
*/
|
||||
public class TempDirectory extends TemporaryFolder {
|
||||
private String myName = null;
|
||||
private File myRoot = null;
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
myName = FileUtil.sanitizeFileName(description.getMethodName(), false);
|
||||
return super.apply(base, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void before() throws IOException {
|
||||
if (myName == null) {
|
||||
throw new IllegalStateException("apply() was not called");
|
||||
}
|
||||
|
||||
@SuppressWarnings("SSBasedInspection") File dir = File.createTempFile("junit_" + myName + "_", "");
|
||||
assertTrue("Cannot delete: " + dir.getPath(), dir.delete() || !dir.exists());
|
||||
assertTrue("Cannot create: " + dir.getPath(), dir.mkdir() || dir.isDirectory());
|
||||
myRoot = dir.getCanonicalFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void after() {
|
||||
if (myRoot == null) {
|
||||
throw new IllegalStateException("before() was not called");
|
||||
}
|
||||
|
||||
FileUtil.delete(myRoot);
|
||||
myRoot = null;
|
||||
myName = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getRoot() {
|
||||
if (myRoot == null) {
|
||||
throw new IllegalStateException("before() was not called");
|
||||
}
|
||||
|
||||
return myRoot;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user