Skip to content

Commit

Permalink
Fix the logs in backwardCompatibilityCheckCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshnikam671 committed Aug 21, 2024
1 parent ad35cdc commit 17ec532
Showing 1 changed file with 61 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ abstract class BackwardCompatibilityCheckBaseCommand : Callable<Unit> {
specificationsOfChangedExternalisedExamples: Set<String>
) {

println("Checking backward compatibility of the following files: $newLine")
println("${ONE_INDENT}Files that have changed:")
println("Checking backward compatibility of the following specs: $newLine")
println("${ONE_INDENT}Specs that have changed:")
changedFiles.forEach { println(it.prependIndent(TWO_INDENTS)) }
println()

if(filesReferringToChangedFiles.isNotEmpty()) {
println("${ONE_INDENT}Files referring to the changed files - ")
println("${ONE_INDENT}Specs referring to the changed specs - ")
filesReferringToChangedFiles.forEach { println(it.prependIndent(TWO_INDENTS)) }
println()
}

if(specificationsOfChangedExternalisedExamples.isNotEmpty()) {
println("${ONE_INDENT}Specifications whose externalised examples were changed - ")
println("${ONE_INDENT}Specs whose externalised examples were changed - ")
filesReferringToChangedFiles.forEach { println(it.prependIndent(TWO_INDENTS)) }
println()
}
Expand Down Expand Up @@ -167,49 +167,12 @@ abstract class BackwardCompatibilityCheckBaseCommand : Callable<Unit> {

val backwardCompatibilityResult = checkBackwardCompatibility(older, newer)

if (backwardCompatibilityResult.success()) {
println(
"$newLine The file $specFilePath is backward compatible.$newLine".prependIndent(
MARGIN_SPACE
)
)
println()
var errorsFound = false

if(!areExamplesValid(newer, "newer")) {
println(
"$newLine *** Examples in $specFilePath are not valid. ***$newLine".prependIndent(
MARGIN_SPACE
)
)
println()
errorsFound = true
}

if(unusedExamples.isNotEmpty()) {
println(
"$newLine *** Some examples for $specFilePath could not be loaded. ***$newLine".prependIndent(
MARGIN_SPACE
)
)
println()
errorsFound = true
}

if(errorsFound) CompatibilityResult.FAILED
else CompatibilityResult.PASSED
} else {
println("$newLine ${backwardCompatibilityResult.report().prependIndent(
MARGIN_SPACE
)}")
println(
"$newLine *** The file $specFilePath is NOT backward compatible. ***$newLine".prependIndent(
MARGIN_SPACE
)
)
println()
CompatibilityResult.FAILED
}
return@mapIndexed getCompatibilityResult(
backwardCompatibilityResult,
specFilePath,
newer,
unusedExamples
)
} finally {
gitCommand.checkout(treeishWithChanges)
if (areLocalChangesStashed) gitCommand.stashPop()
Expand All @@ -224,6 +187,57 @@ abstract class BackwardCompatibilityCheckBaseCommand : Callable<Unit> {

private fun baseBranch() = baseBranch ?: gitCommand.currentRemoteBranch()

private fun getCompatibilityResult(
backwardCompatibilityResult: Results,
specFilePath: String,
newer: IFeature,
unusedExamples: Set<String>
): CompatibilityResult {
if (backwardCompatibilityResult.success()) {
println(
"$newLine The spec $specFilePath is backward compatible with the corresponding spec from ${baseBranch()}$newLine".prependIndent(
MARGIN_SPACE
)
)
println()
var errorsFound = false

if(!areExamplesValid(newer, "newer")) {
println(
"$newLine *** Examples in $specFilePath are not valid. ***$newLine".prependIndent(
MARGIN_SPACE
)
)
println()
errorsFound = true
}

if(unusedExamples.isNotEmpty()) {
println(
"$newLine *** Some examples for $specFilePath could not be loaded. ***$newLine".prependIndent(
MARGIN_SPACE
)
)
println()
errorsFound = true
}

return if(errorsFound) CompatibilityResult.FAILED
else CompatibilityResult.PASSED
} else {
println("$newLine ${backwardCompatibilityResult.report().prependIndent(
MARGIN_SPACE
)}")
println(
"$newLine *** The spec $specFilePath is NOT backward compatible with the corresponding spec from ${baseBranch()}***$newLine".prependIndent(
MARGIN_SPACE
)
)
println()
return CompatibilityResult.FAILED
}
}

companion object {
private const val HEAD = "HEAD"
private const val MARGIN_SPACE = " "
Expand Down

0 comments on commit 17ec532

Please sign in to comment.