Extract VcsPlatformTest

This commit is contained in:
Kirill Likhodedov
2016-03-30 18:50:17 +03:00
parent fbb17618e7
commit c5d74d5c29
8 changed files with 168 additions and 114 deletions
+1
View File
@@ -262,6 +262,7 @@
<module fileurl="file://$PROJECT_DIR$/platform/vcs-api/vcs-api.iml" filepath="$PROJECT_DIR$/platform/vcs-api/vcs-api.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/platform/vcs-api/vcs-api-core/vcs-api-core.iml" filepath="$PROJECT_DIR$/platform/vcs-api/vcs-api-core/vcs-api-core.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/platform/vcs-impl/vcs-impl.iml" filepath="$PROJECT_DIR$/platform/vcs-impl/vcs-impl.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/platform/vcs-tests/vcs-tests.iml" filepath="$PROJECT_DIR$/platform/vcs-tests/vcs-tests.iml" group="platform" />
<module fileurl="file://$PROJECT_DIR$/platform/vcs-log/api/vcs-log-api.iml" filepath="$PROJECT_DIR$/platform/vcs-log/api/vcs-log-api.iml" group="platform/vcs-log" />
<module fileurl="file://$PROJECT_DIR$/platform/vcs-log/graph/vcs-log-graph.iml" filepath="$PROJECT_DIR$/platform/vcs-log/graph/vcs-log-graph.iml" group="platform/vcs-log" />
<module fileurl="file://$PROJECT_DIR$/platform/vcs-log/graph-api/vcs-log-graph-api.iml" filepath="$PROJECT_DIR$/platform/vcs-log/graph-api/vcs-log-graph-api.iml" group="platform/vcs-log" />
@@ -0,0 +1,137 @@
/*
* Copyright 2000-2016 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.vcs.test
import com.intellij.ide.highlighter.ProjectFileType
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vcs.changes.ChangeListManager
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.PlatformTestCase
import com.intellij.testFramework.TestLoggerFactory
import com.intellij.testFramework.runInEdtAndWait
import com.intellij.util.ArrayUtil
import java.io.File
import java.util.*
abstract class VcsPlatformTest : PlatformTestCase() {
protected lateinit var myTestRoot: File
protected lateinit var myProjectRoot: VirtualFile
protected lateinit var myProjectPath: String
private lateinit var myTestStartedIndicator: String
@Throws(Exception::class)
override fun setUp() {
myTestRoot = File(FileUtil.getTempDirectory(), "testRoot")
PlatformTestCase.myFilesToDelete.add(myTestRoot)
checkTestRootIsEmpty(myTestRoot)
runInEdtAndWait { super@VcsPlatformTest.setUp() }
myTestStartedIndicator = enableDebugLogging()
myProjectRoot = myProject.baseDir
myProjectPath = myProjectRoot.path
}
@Throws(Exception::class)
override fun tearDown() {
try {
runInEdtAndWait { super@VcsPlatformTest.tearDown() }
}
finally {
if (myAssertionsInTestDetected) {
TestLoggerFactory.dumpLogToStdout(myTestStartedIndicator)
}
}
}
/**
* Returns log categories which will be switched to DEBUG level.
* Implementations must add theirs categories to the ones from super class,
* not to erase log categories from the super class.
* (e.g. by calling `super.getDebugLogCategories().plus(additionalCategories)`.
*/
protected open fun getDebugLogCategories(): Collection<String> = emptyList()
override fun getIprFile(): File {
val projectRoot = File(myTestRoot, "project")
return FileUtil.createTempFile(projectRoot, name + "_", ProjectFileType.DOT_DEFAULT_EXTENSION)
}
override fun setUpModule() {
// we don't need a module in Git tests
}
override fun isRunInEdt(): Boolean {
return false
}
override fun getTestName(lowercaseFirstLetter: Boolean): String {
var name = super.getTestName(lowercaseFirstLetter)
name = StringUtil.shortenTextWithEllipsis(name.trim { it <= ' ' }.replace(" ", "_"), 12, 6, "_")
if (name.startsWith("_")) {
name = name.substring(1)
}
return name
}
protected inline fun wasInit(f: () -> Unit): Boolean {
try {
f()
}
catch(e: UninitializedPropertyAccessException) {
return false
}
return true
}
protected open fun refresh() {
VfsUtil.markDirtyAndRefresh(false, true, false, myProjectRoot)
}
protected fun updateChangeListManager() {
val changeListManager = ChangeListManager.getInstance(myProject)
VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty()
changeListManager.ensureUpToDate(false)
}
private fun checkTestRootIsEmpty(testRoot: File) {
val files = testRoot.listFiles()
if (files != null && files.size > 0) {
LOG.warn("Test root was not cleaned up during some previous test run. " + "testRoot: " + testRoot +
", files: " + Arrays.toString(files))
for (file in files) {
LOG.assertTrue(FileUtil.delete(file))
}
}
}
private fun enableDebugLogging(): String {
TestLoggerFactory.enableDebugLogging(myTestRootDisposable, *ArrayUtil.toStringArray(getDebugLogCategories()))
val testStartedIndicator = createTestStartedIndicator()
LOG.info(testStartedIndicator)
return testStartedIndicator
}
private fun createTestStartedIndicator(): String {
return "Starting " + javaClass.name + "." + getTestName(false) + Math.random()
}
}
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="testFramework" scope="TEST" />
<orderEntry type="module" module-name="vcs-api" scope="TEST" />
<orderEntry type="module" module-name="vcs-impl" scope="TEST" />
<orderEntry type="module" module-name="vcs-api-core" scope="TEST" />
<orderEntry type="module" module-name="core-api" scope="TEST" />
</component>
</module>
+1
View File
@@ -62,5 +62,6 @@
<orderEntry type="library" scope="TEST" name="mockito" level="project" />
<orderEntry type="library" scope="TEST" name="cucumber-java" level="project" />
<orderEntry type="library" scope="TEST" name="KotlinTest" level="project" />
<orderEntry type="module" module-name="vcs-tests" scope="TEST" />
</component>
</module>
@@ -56,9 +56,7 @@ abstract class GitPushOperationBaseTest : GitPlatformTest() {
myGitRepositoryManager.updateAllRepositories()
}
override fun getDebugLogCategories(): Collection<String> {
return listOf("#" + GitPushOperation::class.java.name)
}
override fun getDebugLogCategories() = super.getDebugLogCategories().plus("#" + GitPushOperation::class.java.name)
protected fun setupRepositories(repoRoot: String, parentName: String, broName: String): Trinity<GitRepository, File, File> {
val parentRepo = createParentRepo(parentName)
@@ -41,7 +41,7 @@ abstract class GitRebaseBaseTest : GitPlatformTest() {
override fun createRepository(rootDir: String) = GitTestUtil.createRepository(myProject, rootDir, false)
override fun getDebugLogCategories() = listOf("#git4idea.rebase")
override fun getDebugLogCategories() = super.getDebugLogCategories().plus("#git4idea.rebase")
protected fun GitRepository.`diverge feature and master`() {
build(this) {
@@ -15,23 +15,13 @@
*/
package git4idea.test
import com.intellij.ide.highlighter.ProjectFileType
import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vcs.*
import com.intellij.openapi.vcs.changes.ChangeListManager
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.PlatformTestCase
import com.intellij.testFramework.TestLoggerFactory
import com.intellij.testFramework.runInEdtAndWait
import com.intellij.testFramework.vcs.AbstractVcsTestCase
import com.intellij.util.ArrayUtil
import com.intellij.vcs.test.VcsPlatformTest
import git4idea.DialogManager
import git4idea.GitPlatformFacade
import git4idea.GitUtil
@@ -42,14 +32,9 @@ import git4idea.config.GitVcsSettings
import git4idea.repo.GitRepository
import git4idea.repo.GitRepositoryManager
import java.io.File
import java.util.*
abstract class GitPlatformTest : PlatformTestCase() {
abstract class GitPlatformTest : VcsPlatformTest() {
protected val LOG = Logger.getInstance(GitPlatformTest::class.java)
protected lateinit var myProjectRoot: VirtualFile
protected lateinit var myProjectPath: String
protected lateinit var myGitRepositoryManager: GitRepositoryManager
protected lateinit var myGitSettings: GitVcsSettings
protected lateinit var myPlatformFacade: GitPlatformFacade
@@ -58,23 +43,9 @@ abstract class GitPlatformTest : PlatformTestCase() {
protected lateinit var myDialogManager: TestDialogManager
protected lateinit var myVcsNotifier: TestVcsNotifier
protected lateinit var myTestRoot: File
private lateinit var myTestStartedIndicator: String
@Throws(Exception::class)
override fun setUp() {
myTestRoot = File(FileUtil.getTempDirectory(), "testRoot")
PlatformTestCase.myFilesToDelete.add(myTestRoot)
checkTestRootIsEmpty(myTestRoot)
runInEdtAndWait { super@GitPlatformTest.setUp() }
myTestStartedIndicator = enableDebugLogging()
myProjectRoot = myProject.baseDir
myProjectPath = myProjectRoot.path
super.setUp()
myGitSettings = GitVcsSettings.getInstance(myProject)
myGitSettings.appSettings.pathToGit = GitExecutor.PathHolder.GIT_EXECUTABLE
@@ -101,64 +72,14 @@ abstract class GitPlatformTest : PlatformTestCase() {
myGit.reset()
}
finally {
try {
runInEdtAndWait { super@GitPlatformTest.tearDown() }
}
finally {
if (myAssertionsInTestDetected) {
TestLoggerFactory.dumpLogToStdout(myTestStartedIndicator)
}
}
super.tearDown()
}
}
override fun getIprFile(): File {
val projectRoot = File(myTestRoot, "project")
return FileUtil.createTempFile(projectRoot, name + "_", ProjectFileType.DOT_DEFAULT_EXTENSION)
}
override fun setUpModule() {
// we don't need a module in Git tests
}
override fun isRunInEdt(): Boolean {
return false
}
override fun getTestName(lowercaseFirstLetter: Boolean): String {
var name = super.getTestName(lowercaseFirstLetter)
name = StringUtil.shortenTextWithEllipsis(name.trim { it <= ' ' }.replace(" ", "_"), 12, 6, "_")
if (name.startsWith("_")) {
name = name.substring(1)
}
return name
}
inline fun wasInit(f: () -> Unit): Boolean {
try {
f()
}
catch(e: UninitializedPropertyAccessException) {
return false
}
return true
}
private fun enableDebugLogging(): String {
val commonCategories = ArrayList(Arrays.asList("#" + Executor::class.java.name,
"#" + GitHandler::class.java.name,
GitHandler::class.java.name))
commonCategories.addAll(getDebugLogCategories())
TestLoggerFactory.enableDebugLogging(myTestRootDisposable, *ArrayUtil.toStringArray(commonCategories))
val testStartedIndicator = createTestStartedIndicator()
LOG.info(testStartedIndicator)
return testStartedIndicator
}
protected open fun getDebugLogCategories(): Collection<String> = emptyList()
private fun createTestStartedIndicator(): String {
return "Starting " + javaClass.name + "." + getTestName(false) + Math.random()
override fun getDebugLogCategories(): Collection<String> {
return super.getDebugLogCategories().plus(listOf("#" + Executor::class.java.name,
"#" + GitHandler::class.java.name,
GitHandler::class.java.name))
}
protected open fun createRepository(rootDir: String): GitRepository {
@@ -177,20 +98,10 @@ abstract class GitPlatformTest : PlatformTestCase() {
GitExecutor.git("remote add %s '%s'", targetName, "$myProjectRoot/$target")
}
protected open fun refresh() {
VfsUtil.markDirtyAndRefresh(false, true, false, myProjectRoot)
}
protected fun doActionSilently(op: VcsConfiguration.StandardConfirmation) {
AbstractVcsTestCase.setStandardConfirmation(myProject, GitVcs.NAME, op, VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY)
}
protected fun updateChangeListManager() {
val changeListManager = ChangeListManager.getInstance(myProject)
VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty()
changeListManager.ensureUpToDate(false)
}
protected fun addSilently() {
doActionSilently(VcsConfiguration.StandardConfirmation.ADD)
}
@@ -199,17 +110,6 @@ abstract class GitPlatformTest : PlatformTestCase() {
doActionSilently(VcsConfiguration.StandardConfirmation.REMOVE)
}
private fun checkTestRootIsEmpty(testRoot: File) {
val files = testRoot.listFiles()
if (files != null && files.size > 0) {
LOG.warn("Test root was not cleaned up during some previous test run. " + "testRoot: " + testRoot +
", files: " + Arrays.toString(files))
for (file in files) {
LOG.assertTrue(FileUtil.delete(file))
}
}
}
protected fun installHook(gitDir: File, hookName: String, hookContent: String) {
val hookFile = File(gitDir, "hooks/$hookName")
FileUtil.writeToFile(hookFile, hookContent)
+2 -2
View File
@@ -26,6 +26,6 @@
<orderEntry type="module" module-name="vcs-log-api" />
<orderEntry type="module" module-name="vcs-log-impl" />
<orderEntry type="module" module-name="jira" scope="TEST" />
<orderEntry type="module" module-name="vcs-tests" scope="TEST" />
</component>
</module>
</module>