[Tests] Generate runTest with transformer parameter + example
This commit is contained in:
@@ -24,9 +24,13 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
|
||||
private val allFailedExceptions = mutableListOf<WrappedException>()
|
||||
private val allRanHandlers = mutableSetOf<AnalysisHandler<*>>()
|
||||
|
||||
fun runTest(@TestDataFile testDataFileName: String, beforeDispose: (TestConfiguration) -> Unit = {}) {
|
||||
fun runTest(
|
||||
@TestDataFile testDataFileName: String,
|
||||
beforeDispose: (TestConfiguration) -> Unit = {},
|
||||
expectedFileTransformer: ((String) -> String)? = null
|
||||
) {
|
||||
try {
|
||||
runTestImpl(testDataFileName)
|
||||
runTestImpl(testDataFileName, expectedFileTransformer)
|
||||
} finally {
|
||||
try {
|
||||
testConfiguration.testServices.temporaryDirectoryManager.cleanupTemporaryDirectories()
|
||||
@@ -38,7 +42,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun runTestImpl(@TestDataFile testDataFileName: String) {
|
||||
private fun runTestImpl(@TestDataFile testDataFileName: String, expectedFileTransformer: ((String) -> String)?) {
|
||||
val services = testConfiguration.testServices
|
||||
|
||||
@Suppress("NAME_SHADOWING")
|
||||
@@ -66,12 +70,13 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
|
||||
if (it.shouldSkipTest()) return
|
||||
}
|
||||
|
||||
runTestPipeline(moduleStructure, services)
|
||||
runTestPipeline(moduleStructure, services, expectedFileTransformer)
|
||||
}
|
||||
|
||||
fun runTestPipeline(
|
||||
moduleStructure: TestModuleStructure,
|
||||
services: TestServices
|
||||
services: TestServices,
|
||||
expectedFileTransformer: ((String) -> String)?,
|
||||
) {
|
||||
val globalMetadataInfoHandler = testConfiguration.testServices.globalMetadataInfoHandler
|
||||
globalMetadataInfoHandler.parseExistingMetadataInfosFromAllSources()
|
||||
@@ -100,7 +105,7 @@ class TestRunner(private val testConfiguration: TestConfiguration) {
|
||||
}
|
||||
if (testConfiguration.metaInfoHandlerEnabled) {
|
||||
withAssertionCatching(WrappedException::FromMetaInfoHandler) {
|
||||
globalMetadataInfoHandler.compareAllMetaDataInfos()
|
||||
globalMetadataInfoHandler.compareAllMetaDataInfos(expectedFileTransformer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-2
@@ -51,7 +51,7 @@ class GlobalMetadataInfoHandler(
|
||||
infos += codeMetaInfos
|
||||
}
|
||||
|
||||
fun compareAllMetaDataInfos() {
|
||||
fun compareAllMetaDataInfos(expectedTransformer: ((String) -> String)?) {
|
||||
// TODO: adapt to multiple testdata files
|
||||
val moduleStructure = testServices.moduleStructure
|
||||
val builder = StringBuilder()
|
||||
@@ -70,7 +70,14 @@ class GlobalMetadataInfoHandler(
|
||||
}
|
||||
}
|
||||
val actualText = builder.toString()
|
||||
testServices.assertions.assertEqualsToFile(moduleStructure.originalTestDataFiles.single(), actualText)
|
||||
val expectedFile = moduleStructure.originalTestDataFiles.single()
|
||||
if (expectedTransformer != null) {
|
||||
val expectedContent = expectedFile.readText().let(expectedTransformer)
|
||||
val message = "Actual data differs from transformed content of file $expectedFile"
|
||||
testServices.assertions.assertEquals(expectedContent, actualText) { message }
|
||||
} else {
|
||||
testServices.assertions.assertEqualsToFile(expectedFile, actualText)
|
||||
}
|
||||
}
|
||||
|
||||
private fun StringBuilder.stripAdditionalEmptyLines(file: TestFile): CharSequence {
|
||||
|
||||
Reference in New Issue
Block a user