[Test gen] Remove duplicate checks if file is equal to some string

This commit is contained in:
Kirill Rakhman
2024-02-26 18:07:29 +01:00
committed by Space Team
parent cba65d7186
commit 3c23319f70
3 changed files with 11 additions and 10 deletions
@@ -101,10 +101,10 @@ private class TestGeneratorImplInstance(
val generatedCode = generate()
val testSourceFile = File(testSourceFilePath)
val changed =
GeneratorsFileUtil.isFileContentChangedIgnoringLineSeparators(testSourceFile, generatedCode)
if (!dryRun) {
val changed = if (!dryRun) {
GeneratorsFileUtil.writeFileIfContentChanged(testSourceFile, generatedCode, false)
} else {
GeneratorsFileUtil.isFileContentChangedIgnoringLineSeparators(testSourceFile, generatedCode)
}
return TestGenerator.GenerationResult(changed, testSourceFilePath)
}
+5 -4
View File
@@ -24,11 +24,11 @@ object GeneratorsFileUtil {
@JvmStatic
@JvmOverloads
@Throws(IOException::class)
fun writeFileIfContentChanged(file: File, newText: String, logNotChanged: Boolean = true, forbidGenerationOnTeamcity: Boolean = true) {
fun writeFileIfContentChanged(file: File, newText: String, logNotChanged: Boolean = true, forbidGenerationOnTeamcity: Boolean = true): Boolean {
val parentFile = file.parentFile
if (!parentFile.exists()) {
if (forbidGenerationOnTeamcity) {
if (failOnTeamCity("Create dir `${parentFile.path}`")) return
if (failOnTeamCity("Create dir `${parentFile.path}`")) return false
}
if (parentFile.mkdirs()) {
println("Directory created: " + parentFile.absolutePath)
@@ -40,10 +40,10 @@ object GeneratorsFileUtil {
if (logNotChanged) {
println("Not changed: " + file.absolutePath)
}
return
return false
}
if (forbidGenerationOnTeamcity) {
if (failOnTeamCity("Write file `${file.toPath()}`")) return
if (failOnTeamCity("Write file `${file.toPath()}`")) return false
}
val useTempFile = !SystemInfo.isWindows
val targetFile = file.toPath()
@@ -54,6 +54,7 @@ object GeneratorsFileUtil {
tempFile.moveTo(targetFile, overwrite = true)
}
println("File written: ${targetFile.toAbsolutePath()}")
return true
}
private fun failOnTeamCity(message: String): Boolean {
@@ -112,10 +112,10 @@ class NewTestGeneratorImpl(
val generatedCode = generate()
val testSourceFile = File(testSourceFilePath)
val changed =
GeneratorsFileUtil.isFileContentChangedIgnoringLineSeparators(testSourceFile, generatedCode)
if (!dryRun) {
val changed = if (!dryRun) {
GeneratorsFileUtil.writeFileIfContentChanged(testSourceFile, generatedCode, false)
} else {
GeneratorsFileUtil.isFileContentChangedIgnoringLineSeparators(testSourceFile, generatedCode)
}
return GenerationResult(changed, testSourceFilePath)
}