From 54de424b4ca7ec687180f07d33b876a464fbf301 Mon Sep 17 00:00:00 2001 From: Joel Rosario Date: Wed, 18 Sep 2024 12:04:39 +0530 Subject: [PATCH] Don't look for _examples if we are only validating inline examples --- .../src/main/kotlin/application/ExamplesCommand.kt | 8 +------- .../examples/server/ExamplesInteractiveServer.kt | 12 ++++++++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/application/src/main/kotlin/application/ExamplesCommand.kt b/application/src/main/kotlin/application/ExamplesCommand.kt index bce3dc7bb..5c3376bfb 100644 --- a/application/src/main/kotlin/application/ExamplesCommand.kt +++ b/application/src/main/kotlin/application/ExamplesCommand.kt @@ -101,13 +101,7 @@ class ExamplesCommand : Callable { exitProcess(1) } } else { - val examplesDir = contractFile.absoluteFile.parentFile.resolve(contractFile.nameWithoutExtension + "_examples") - if (!examplesDir.isDirectory) { - logger.log("$examplesDir does not exist, did not find any files to validate") - exitProcess(1) - } - - val (internalResult, externalResults) = ExamplesInteractiveServer.validateAll(contractFile, examplesDir) + val (internalResult, externalResults) = ExamplesInteractiveServer.validateAll(contractFile) val hasFailures = internalResult is Result.Failure || externalResults?.any { it.value is Result.Failure } == true diff --git a/core/src/main/kotlin/io/specmatic/core/examples/server/ExamplesInteractiveServer.kt b/core/src/main/kotlin/io/specmatic/core/examples/server/ExamplesInteractiveServer.kt index 3ab16e9ff..55f1db86c 100644 --- a/core/src/main/kotlin/io/specmatic/core/examples/server/ExamplesInteractiveServer.kt +++ b/core/src/main/kotlin/io/specmatic/core/examples/server/ExamplesInteractiveServer.kt @@ -342,7 +342,7 @@ class ExamplesInteractiveServer( return file.absolutePath } - fun validateAll(contractFile: File, examplesDir: File): Pair?> { + fun validateAll(contractFile: File): Pair?> { val feature = parseContractFileToFeature(contractFile) val (validateInline, validateExternal) = if(!Flags.getBooleanValue("VALIDATE_INLINE_EXAMPLES") && !Flags.getBooleanValue("IGNORE_INLINE_EXAMPLES")) { @@ -356,8 +356,16 @@ class ExamplesInteractiveServer( validateInlineExamples(feature) } else null - val externalResult = if(validateExternal) + val externalResult = if(validateExternal) { + val examplesDir = + contractFile.absoluteFile.parentFile.resolve(contractFile.nameWithoutExtension + "_examples") + if (!examplesDir.isDirectory) { + logger.log("$examplesDir does not exist, did not find any files to validate") + exitProcess(1) + } + validateExternalExamples(examplesDir, feature) + } else null return inlineResult to externalResult