mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
test framework: ok, put light project file into ephemeral directory, but keep it for a project's life
This commit is contained in:
@@ -210,7 +210,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
private static void initProject(@NotNull final LightProjectDescriptor descriptor) throws Exception {
|
||||
ourProjectDescriptor = descriptor;
|
||||
|
||||
final File projectFile = FileUtil.createTempFile(UsefulTestCase.getOriginalTempDir(), "light_temp_", ProjectFileType.DOT_DEFAULT_EXTENSION);
|
||||
final File projectFile = FileUtil.createTempFile("light_temp_", ProjectFileType.DOT_DEFAULT_EXTENSION);
|
||||
|
||||
new WriteCommandAction.Simple(null) {
|
||||
@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
|
||||
@@ -229,6 +229,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
new Throwable(projectFile.getPath()).printStackTrace(new PrintStream(buffer));
|
||||
|
||||
ourProject = PlatformTestCase.createProject(projectFile, LIGHT_PROJECT_MARK + buffer.toString());
|
||||
ourPathToKeep = projectFile.getPath();
|
||||
if (!ourHaveShutdownHook) {
|
||||
ourHaveShutdownHook = true;
|
||||
registerShutdownHook();
|
||||
@@ -792,6 +793,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
|
||||
ProjectManagerEx.getInstanceEx().closeTestProject(ourProject);
|
||||
ourProject = null;
|
||||
ourPathToKeep = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,17 +69,17 @@ import java.util.regex.Pattern;
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class UsefulTestCase extends TestCase {
|
||||
public static final String IDEA_MARKER_CLASS = "com.intellij.openapi.components.impl.stores.IdeaProjectStoreImpl";
|
||||
|
||||
protected static boolean OVERWRITE_TESTDATA = false;
|
||||
|
||||
private static final String DEFAULT_SETTINGS_EXTERNALIZED;
|
||||
private static final Random RNG = new SecureRandom();
|
||||
private static final String ORIGINAL_TEMP_DIR = FileUtil.getTempDirectory();
|
||||
public static final String IDEA_MARKER_CLASS = "com.intellij.openapi.components.impl.stores.IdeaProjectStoreImpl";
|
||||
|
||||
protected final Disposable myTestRootDisposable = new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
public void dispose() { }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -87,6 +87,9 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
return UsefulTestCase.this.getClass() + (StringUtil.isEmpty(testName) ? "" : ".test" + testName);
|
||||
}
|
||||
};
|
||||
|
||||
protected static String ourPathToKeep = null;
|
||||
|
||||
private CodeStyleSettings myOldCodeStyleSettings;
|
||||
private String myTempDir;
|
||||
|
||||
@@ -111,10 +114,6 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static File getOriginalTempDir() {
|
||||
return new File(ORIGINAL_TEMP_DIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -123,9 +122,10 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
String testName = getTestName(true);
|
||||
if (StringUtil.isEmptyOrSpaces(testName)) testName = "";
|
||||
testName = new File(testName).getName(); // in case the test name contains file separators
|
||||
myTempDir = ORIGINAL_TEMP_DIR + "/unitTest_" + testName + "_"+ RNG.nextInt(1000);
|
||||
myTempDir = FileUtil.toSystemDependentName(ORIGINAL_TEMP_DIR + "/unitTest_" + testName + "_"+ RNG.nextInt(1000));
|
||||
FileUtil.resetCanonicalTempPathCache(myTempDir);
|
||||
}
|
||||
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||
DocumentImpl.CHECK_DOCUMENT_CONSISTENCY = !isPerformanceTest();
|
||||
}
|
||||
|
||||
@@ -138,7 +138,19 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
finally {
|
||||
if (shouldContainTempFiles()) {
|
||||
FileUtil.resetCanonicalTempPathCache(ORIGINAL_TEMP_DIR);
|
||||
FileUtil.delete(new File(myTempDir));
|
||||
if (ourPathToKeep != null && FileUtil.isAncestor(myTempDir, ourPathToKeep, false)) {
|
||||
File[] files = new File(myTempDir).listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (!FileUtil.pathsEqual(file.getPath(), ourPathToKeep)) {
|
||||
FileUtil.delete(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
FileUtil.delete(new File(myTempDir));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.lang.properties;
|
||||
|
||||
import com.intellij.ide.projectView.impl.AbstractProjectViewPSIPane;
|
||||
@@ -13,6 +28,7 @@ import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCa
|
||||
public class PropertiesProjectViewTest extends LightPlatformCodeInsightFixtureTestCase {
|
||||
private TestProjectTreeStructure myStructure;
|
||||
|
||||
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
|
||||
public PropertiesProjectViewTest() {
|
||||
PlatformTestCase.initPlatformLangPrefix();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user