Skip to content

Commit

Permalink
assertionPattern issue fixes (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan108 authored Apr 10, 2024
1 parent 3b861c4 commit d802652
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
13 changes: 10 additions & 3 deletions src/main/kotlin/com/featurevisor/testRunner/TestExecuter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data class TestProjectOption(
fun startTest(option: TestProjectOption) {
var hasError = false
val folder = File("${option.projectRootPath}/${option.testDirPath}")
val listOfFiles = folder.listFiles()
val listOfFiles = folder.listFiles()?.sortedBy { it }
var executionResult: ExecutionResult? = null
val startTime = System.currentTimeMillis()
var passedTestsCount = 0
Expand Down Expand Up @@ -103,11 +103,18 @@ private fun executeTest(filePath: String, dataFile: DataFile, option: TestProjec

val testResult: TestResult = when (test) {
is Test.Feature -> {
testFeature(test.value, dataFile = dataFile, option)
testFeature(
testFeature = test.value,
dataFile = dataFile,
option = option
)
}

is Test.Segment -> {
testSegment(test.value, option.projectRootPath)
testSegment(
testSegment = test.value,
option = option
)
}
}

Expand Down
22 changes: 13 additions & 9 deletions src/main/kotlin/com/featurevisor/testRunner/TestSegment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.featurevisor.types.TestResultAssertion
import com.featurevisor.types.TestResultAssertionError
import com.featurevisor.types.TestSegment

fun testSegment(test: TestSegment, segmentFilePath: String): TestResult {
fun testSegment(testSegment: TestSegment, option: TestProjectOption): TestResult {
val testStartTime = System.currentTimeMillis()
val segmentKey = test.key
val segmentKey = testSegment.key

val testResult = TestResult(
type = "segment",
Expand All @@ -19,22 +19,26 @@ fun testSegment(test: TestSegment, segmentFilePath: String): TestResult {
assertions = mutableListOf()
)

for (aIndex in 0 until test.assertions.size) {
val assertions = getSegmentAssertionsFromMatrix(aIndex, test.assertions[aIndex])
testSegment.assertions.forEachIndexed { index, segmentAssertion ->
val assertions = getSegmentAssertionsFromMatrix(index,segmentAssertion)

for (assertion in assertions) {
assertions.forEach {
val assertionStartTime = System.currentTimeMillis()

val testResultAssertion = TestResultAssertion(
description = assertion.description.orEmpty(),
description = it.description.orEmpty(),
duration = 0,
passed = true,
errors = mutableListOf()
)

val yamlSegment = parseYamlSegment("$segmentFilePath/segments/$segmentKey.yml")
val expected = assertion.expectedToMatch
val actual = segmentIsMatched(yamlSegment!!, assertion.context)
if (option.assertionPattern.isNotEmpty() && !it.description.orEmpty().contains(option.assertionPattern)) {
return@forEach
}

val yamlSegment = parseYamlSegment("${option.projectRootPath}/segments/$segmentKey.yml")
val expected = it.expectedToMatch
val actual = segmentIsMatched(yamlSegment!!, it.context)
val passed = actual == expected

if (!passed) {
Expand Down

0 comments on commit d802652

Please sign in to comment.