[Tests] Introduce reversible source file preprocessor

This commit is contained in:
Evgeniy.Zhelenskiy
2021-12-08 22:52:03 +03:00
parent cb4ec932d7
commit b1d1f87318
12 changed files with 28 additions and 35 deletions
@@ -24,13 +24,9 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
private val allFailedExceptions = mutableListOf<WrappedException>()
private val allRanHandlers = mutableSetOf<AnalysisHandler<*>>()
fun runTest(
@TestDataFile testDataFileName: String,
expectedFileTransformer: ((String) -> String)? = null,
beforeDispose: (TestConfiguration) -> Unit = {},
) {
fun runTest(@TestDataFile testDataFileName: String, beforeDispose: (TestConfiguration) -> Unit = {}) {
try {
runTestImpl(testDataFileName, expectedFileTransformer)
runTestImpl(testDataFileName)
} finally {
try {
testConfiguration.testServices.temporaryDirectoryManager.cleanupTemporaryDirectories()
@@ -42,7 +38,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
}
}
private fun runTestImpl(@TestDataFile testDataFileName: String, expectedFileTransformer: ((String) -> String)?) {
private fun runTestImpl(@TestDataFile testDataFileName: String) {
val services = testConfiguration.testServices
@Suppress("NAME_SHADOWING")
@@ -70,14 +66,10 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
if (it.shouldSkipTest()) return
}
runTestPipeline(moduleStructure, services, expectedFileTransformer)
runTestPipeline(moduleStructure, services)
}
fun runTestPipeline(
moduleStructure: TestModuleStructure,
services: TestServices,
expectedFileTransformer: ((String) -> String)?,
) {
fun runTestPipeline(moduleStructure: TestModuleStructure, services: TestServices) {
val globalMetadataInfoHandler = testConfiguration.testServices.globalMetadataInfoHandler
globalMetadataInfoHandler.parseExistingMetadataInfosFromAllSources()
@@ -105,7 +97,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
}
if (testConfiguration.metaInfoHandlerEnabled) {
withAssertionCatching(WrappedException::FromMetaInfoHandler) {
globalMetadataInfoHandler.compareAllMetaDataInfos(expectedFileTransformer)
globalMetadataInfoHandler.compareAllMetaDataInfos()
}
}
@@ -15,6 +15,10 @@ abstract class SourceFilePreprocessor(val testServices: TestServices) {
abstract fun process(file: TestFile, content: String): String
}
abstract class ReversibleSourceFilePreprocessor(testServices: TestServices) : SourceFilePreprocessor(testServices) {
abstract fun revert(file: TestFile, actualContent: String): String
}
abstract class SourceFileProvider : TestService {
abstract val kotlinSourceDirectory: File
abstract val javaSourceDirectory: File
@@ -23,11 +27,12 @@ abstract class SourceFileProvider : TestService {
abstract fun getContentOfSourceFile(testFile: TestFile): String
abstract fun getRealFileForSourceFile(testFile: TestFile): File
abstract fun getRealFileForBinaryFile(testFile: TestFile): File
abstract val preprocessors: List<SourceFilePreprocessor>
}
val TestServices.sourceFileProvider: SourceFileProvider by TestServices.testServiceAccessor()
class SourceFileProviderImpl(val testServices: TestServices, val preprocessors: List<SourceFilePreprocessor>) : SourceFileProvider() {
class SourceFileProviderImpl(val testServices: TestServices, override val preprocessors: List<SourceFilePreprocessor>) : SourceFileProvider() {
override val kotlinSourceDirectory: File = testServices.getOrCreateTempDirectory("kotlin-files")
override val javaSourceDirectory: File = testServices.getOrCreateTempDirectory("java-files")
override val javaBinaryDirectory: File = testServices.getOrCreateTempDirectory("java-binary-files")