Skip to content

Commit d802652

Browse files
authored
assertionPattern issue fixes (#36)
1 parent 3b861c4 commit d802652

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/main/kotlin/com/featurevisor/testRunner/TestExecuter.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ data class TestProjectOption(
1717
fun startTest(option: TestProjectOption) {
1818
var hasError = false
1919
val folder = File("${option.projectRootPath}/${option.testDirPath}")
20-
val listOfFiles = folder.listFiles()
20+
val listOfFiles = folder.listFiles()?.sortedBy { it }
2121
var executionResult: ExecutionResult? = null
2222
val startTime = System.currentTimeMillis()
2323
var passedTestsCount = 0
@@ -103,11 +103,18 @@ private fun executeTest(filePath: String, dataFile: DataFile, option: TestProjec
103103

104104
val testResult: TestResult = when (test) {
105105
is Test.Feature -> {
106-
testFeature(test.value, dataFile = dataFile, option)
106+
testFeature(
107+
testFeature = test.value,
108+
dataFile = dataFile,
109+
option = option
110+
)
107111
}
108112

109113
is Test.Segment -> {
110-
testSegment(test.value, option.projectRootPath)
114+
testSegment(
115+
testSegment = test.value,
116+
option = option
117+
)
111118
}
112119
}
113120

src/main/kotlin/com/featurevisor/testRunner/TestSegment.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import com.featurevisor.types.TestResultAssertion
66
import com.featurevisor.types.TestResultAssertionError
77
import com.featurevisor.types.TestSegment
88

9-
fun testSegment(test: TestSegment, segmentFilePath: String): TestResult {
9+
fun testSegment(testSegment: TestSegment, option: TestProjectOption): TestResult {
1010
val testStartTime = System.currentTimeMillis()
11-
val segmentKey = test.key
11+
val segmentKey = testSegment.key
1212

1313
val testResult = TestResult(
1414
type = "segment",
@@ -19,22 +19,26 @@ fun testSegment(test: TestSegment, segmentFilePath: String): TestResult {
1919
assertions = mutableListOf()
2020
)
2121

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

25-
for (assertion in assertions) {
25+
assertions.forEach {
2626
val assertionStartTime = System.currentTimeMillis()
2727

2828
val testResultAssertion = TestResultAssertion(
29-
description = assertion.description.orEmpty(),
29+
description = it.description.orEmpty(),
3030
duration = 0,
3131
passed = true,
3232
errors = mutableListOf()
3333
)
3434

35-
val yamlSegment = parseYamlSegment("$segmentFilePath/segments/$segmentKey.yml")
36-
val expected = assertion.expectedToMatch
37-
val actual = segmentIsMatched(yamlSegment!!, assertion.context)
35+
if (option.assertionPattern.isNotEmpty() && !it.description.orEmpty().contains(option.assertionPattern)) {
36+
return@forEach
37+
}
38+
39+
val yamlSegment = parseYamlSegment("${option.projectRootPath}/segments/$segmentKey.yml")
40+
val expected = it.expectedToMatch
41+
val actual = segmentIsMatched(yamlSegment!!, it.context)
3842
val passed = actual == expected
3943

4044
if (!passed) {

0 commit comments

Comments
 (0)