Skip to content

Commit

Permalink
Fix examples validate output and associated test
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrosario committed Oct 7, 2024
1 parent 071144e commit 2f7c8a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
33 changes: 20 additions & 13 deletions application/src/main/kotlin/application/ExamplesCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.specmatic.core.log.*
import io.specmatic.core.parseContractFileToFeature
import io.specmatic.core.pattern.ContractException
import io.specmatic.core.utilities.Flags
import io.specmatic.core.utilities.capitalizeFirstChar
import io.specmatic.core.utilities.exceptionCauseMessage
import io.specmatic.core.utilities.exitWithMessage
import io.specmatic.mock.ScenarioStub
Expand Down Expand Up @@ -171,15 +172,11 @@ class ExamplesCommand : Callable<Int> {

val hasFailures = inlineExampleValidationResults.any { it.value is Result.Failure } || externalExampleValidationResults.any { it.value is Result.Failure }

if(hasFailures) {
println()
logger.log("=============== Validation Results ===============")

printValidationResult(inlineExampleValidationResults, "Inline example")
printValidationResult(externalExampleValidationResults, "Example file")
printValidationResult(inlineExampleValidationResults, "Inline example")
printValidationResult(externalExampleValidationResults, "Example file")

if(hasFailures)
return 1
}
}

return 0
Expand All @@ -189,17 +186,27 @@ class ExamplesCommand : Callable<Int> {
if(validationResults.isEmpty())
return

validationResults.forEach { (exampleFileName, result) ->
if (!result.isSuccess()) {
logger.log(System.lineSeparator() + "$tag $exampleFileName has the following validation error(s):")
logger.log(result.reportString())
val hasFailures = validationResults.any { it.value is Result.Failure }

val titleTag = tag.split(" ").joinToString(" ") { if(it.isBlank()) it else it.capitalizeFirstChar() }

if(hasFailures) {
println()
logger.log("=============== $titleTag Validation Results ===============")

validationResults.forEach { (exampleFileName, result) ->
if (!result.isSuccess()) {
logger.log(System.lineSeparator() + "$tag $exampleFileName has the following validation error(s):")
logger.log(result.reportString())
}
}
}

println()
logger.log("=============== Validation Summary ===============")
val summaryTitle = "=============== $titleTag Validation Summary ==============="
logger.log(summaryTitle)
logger.log(Results(validationResults.values.toList()).summary())
logger.log("""==================================================""")
logger.log("=".repeat(summaryTitle.length))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ paths:
println(output)

assertThat(returnValue).isEqualTo(0)
assertThat(output.lines().last()).matches("Validating.*example.json")
assertThat(output).contains("are valid")
}

@Test
Expand Down

0 comments on commit 2f7c8a2

Please sign in to comment.