From 229deb0a99abc4ee1cf7a5f25106594e982f0970 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 20 Sep 2013 13:29:21 +0400 Subject: [PATCH] test framework: ok, put light project file into ephemeral directory, but keep it for a project's life --- .../testFramework/LightPlatformTestCase.java | 4 ++- .../testFramework/UsefulTestCase.java | 30 +++++++++++++------ .../properties/PropertiesProjectViewTest.java | 16 ++++++++++ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 3963e70c462d..b2b0270d256c 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -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; } } diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index 22abc3a4b84d..a66ee1ae0fb5 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -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)); + } } } diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesProjectViewTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesProjectViewTest.java index 1b2ffb9fb334..b91a878024b2 100644 --- a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesProjectViewTest.java +++ b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesProjectViewTest.java @@ -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(); }