mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
InspectionSchemeTest — use in memory fs
This commit is contained in:
Generated
+11
@@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="memoryfilesystem">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/dev/memoryfilesystem-0.8.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/dev/memoryfilesystem-0.8.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
@@ -54,5 +54,6 @@
|
||||
<orderEntry type="library" scope="TEST" name="KotlinTest" level="project" />
|
||||
<orderEntry type="module" module-name="built-in-server-api" scope="TEST" />
|
||||
<orderEntry type="module" module-name="configuration-store-impl" scope="TEST" />
|
||||
<orderEntry type="library" name="memoryfilesystem" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -18,8 +18,8 @@ package com.intellij.codeInspection.ex
|
||||
import com.intellij.configurationStore.SchemeManagerFactoryBase
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.util.Computable
|
||||
import com.intellij.testFramework.InMemoryFsRule
|
||||
import com.intellij.testFramework.ProjectRule
|
||||
import com.intellij.testFramework.TemporaryDirectory
|
||||
import com.intellij.util.readText
|
||||
import com.intellij.util.write
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
@@ -33,19 +33,19 @@ internal class InspectionSchemeTest {
|
||||
@ClassRule val projectRule = ProjectRule()
|
||||
}
|
||||
|
||||
private val tempDirManager = TemporaryDirectory()
|
||||
@Rule fun getTemporaryFolder() = tempDirManager
|
||||
@JvmField
|
||||
@Rule
|
||||
val fsRule = InMemoryFsRule()
|
||||
|
||||
@Test fun loadSchemes() {
|
||||
val schemeDir = tempDirManager.newPath()
|
||||
val schemeFile = schemeDir.resolve("inspection/Bar.xml")
|
||||
val schemeFile = fsRule.fs.getPath("inspection/Bar.xml")
|
||||
val schemeData = """
|
||||
<inspections profile_name="Bar" version="1.0">
|
||||
<option name="myName" value="Bar" />
|
||||
<inspection_tool class="Since15" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||
"</inspections>""".trimIndent()
|
||||
schemeFile.write(schemeData)
|
||||
val schemeManagerFactory = SchemeManagerFactoryBase.TestSchemeManagerFactory(schemeDir)
|
||||
val schemeManagerFactory = SchemeManagerFactoryBase.TestSchemeManagerFactory(fsRule.fs.getPath(""))
|
||||
val profileManager = InspectionProfileManagerImpl(InspectionToolRegistrar.getInstance(), schemeManagerFactory, ApplicationManager.getApplication().messageBus)
|
||||
profileManager.forceInitProfiles(true)
|
||||
profileManager.initProfiles()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -26,5 +26,6 @@
|
||||
<orderEntry type="module" module-name="RegExpSupport" exported="" scope="RUNTIME" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="assertJ" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="memoryfilesystem" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.testFramework
|
||||
|
||||
import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder
|
||||
import org.junit.rules.ExternalResource
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runners.model.Statement
|
||||
import java.net.URLEncoder
|
||||
import java.nio.file.FileSystem
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class InMemoryFsRule : ExternalResource() {
|
||||
private var _fs: FileSystem? = null
|
||||
|
||||
private var sanitizedName: String by Delegates.notNull()
|
||||
|
||||
override fun apply(base: Statement, description: Description): Statement {
|
||||
sanitizedName = URLEncoder.encode(description.methodName, Charsets.UTF_8.name())
|
||||
return super.apply(base, description)
|
||||
}
|
||||
|
||||
val fs: FileSystem
|
||||
get() {
|
||||
var r = _fs
|
||||
if (r == null) {
|
||||
r = MemoryFileSystemBuilder
|
||||
.newLinux()
|
||||
.setCurrentWorkingDirectory("/")
|
||||
.build(sanitizedName)
|
||||
_fs = r
|
||||
}
|
||||
return r!!
|
||||
}
|
||||
|
||||
override fun after() {
|
||||
_fs?.close()
|
||||
_fs = null
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -23,16 +23,6 @@
|
||||
<orderEntry type="module" module-name="util-tests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="settings-repository" />
|
||||
<orderEntry type="library" scope="TEST" name="assertJ" level="project" />
|
||||
<orderEntry type="module-library" scope="TEST">
|
||||
<library name="memoryfilesystem">
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/lib/dev/memoryfilesystem-0.6.7.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$MODULE_DIR$/lib/dev/memoryfilesystem-0.6.7-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" scope="TEST" name="memoryfilesystem" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.settingsRepository.test
|
||||
|
||||
import com.intellij.testFramework.InMemoryFsRule
|
||||
import com.intellij.testFramework.TemporaryDirectory
|
||||
import com.intellij.util.writeChild
|
||||
import org.eclipse.jgit.lib.Repository
|
||||
@@ -46,8 +47,9 @@ abstract class IcsTestCase {
|
||||
val tempDirManager = TemporaryDirectory()
|
||||
@Rule fun getTemporaryFolder() = tempDirManager
|
||||
|
||||
private val fsRule = InMemoryFsRule()
|
||||
@Rule fun _inMemoryFsRule() = fsRule
|
||||
@JvmField
|
||||
@Rule
|
||||
val fsRule = InMemoryFsRule()
|
||||
|
||||
val fs: FileSystem
|
||||
get() = fsRule.fs
|
||||
|
||||
@@ -15,49 +15,13 @@
|
||||
*/
|
||||
package org.jetbrains.settingsRepository.test
|
||||
|
||||
import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder
|
||||
import com.intellij.util.exists
|
||||
import com.intellij.util.isFile
|
||||
import gnu.trove.THashSet
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.eclipse.jgit.lib.Constants
|
||||
import org.junit.rules.ExternalResource
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runners.model.Statement
|
||||
import java.net.URLEncoder
|
||||
import java.nio.file.FileSystem
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class InMemoryFsRule : ExternalResource() {
|
||||
private var _fs: FileSystem? = null
|
||||
|
||||
private var sanitizedName: String by Delegates.notNull()
|
||||
|
||||
override fun apply(base: Statement, description: Description): Statement {
|
||||
sanitizedName = URLEncoder.encode(description.methodName, Charsets.UTF_8.name())
|
||||
return super.apply(base, description)
|
||||
}
|
||||
|
||||
val fs: FileSystem
|
||||
get() {
|
||||
var r = _fs
|
||||
if (r == null) {
|
||||
r = MemoryFileSystemBuilder
|
||||
.newLinux()
|
||||
.setCurrentWorkingDirectory("/")
|
||||
.build(sanitizedName)
|
||||
_fs = r
|
||||
}
|
||||
return r!!
|
||||
}
|
||||
|
||||
override fun after() {
|
||||
_fs?.close()
|
||||
_fs = null
|
||||
}
|
||||
}
|
||||
|
||||
private fun getChildrenStream(path: Path, excludes: Array<out String>? = null) = Files.list(path)
|
||||
.filter { !it.endsWith(Constants.DOT_GIT) && (excludes == null || !excludes.contains(it.fileName.toString())) }
|
||||
|
||||
Reference in New Issue
Block a user