Skip to content

Commit

Permalink
replace TestCaseParseResult to OperationResult
Browse files Browse the repository at this point in the history
  • Loading branch information
arksap2002 committed Feb 14, 2025
1 parent 3dbe4d8 commit f14857f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.jetbrains.research.testspark.core.test

import org.jetbrains.research.testspark.core.test.data.TestCaseGeneratedByLLM
import org.jetbrains.research.testspark.core.test.data.TestSuiteGeneratedByLLM

data class TestCaseParseResult(
val testCase: TestCaseGeneratedByLLM?,
val errorMessage: String,
val errorOccurred: Boolean,
data class OperationResult<Payload>(
val content: Payload? = null,
val error: ErrorDetails? = null,
)

data class ErrorDetails(val message: String)

interface TestSuiteParser {
/**
* Extracts test cases from raw text and generates a test suite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package org.jetbrains.research.testspark.core.test.strategies

import org.jetbrains.research.testspark.core.data.JUnitVersion
import org.jetbrains.research.testspark.core.test.TestBodyPrinter
import org.jetbrains.research.testspark.core.test.TestCaseParseResult
import org.jetbrains.research.testspark.core.test.OperationResult
import org.jetbrains.research.testspark.core.test.ErrorDetails
import org.jetbrains.research.testspark.core.test.data.TestCaseGeneratedByLLM
import org.jetbrains.research.testspark.core.test.data.TestLine
import org.jetbrains.research.testspark.core.test.data.TestLineType
import org.jetbrains.research.testspark.core.test.data.TestSuiteGeneratedByLLM

typealias TestCaseParseResult = OperationResult<TestCaseGeneratedByLLM>

class JUnitTestSuiteParserStrategy {
companion object {
fun parseJUnitTestSuite(
Expand Down Expand Up @@ -54,12 +57,12 @@ class JUnitTestSuiteParserStrategy {
val result: TestCaseParseResult =
testCaseParser.parse(rawTest, isLastTestCaseInTestSuite, testNamePattern, printTestBodyStrategy)

if (result.errorOccurred) {
println("WARNING: ${result.errorMessage}")
if (result.error != null) {
println("WARNING: ${result.error}")
return@ca
}

val currentTest = result.testCase!!
val currentTest = result.content!!

// TODO: make logging work
// log.info("New test case: $currentTest")
Expand Down Expand Up @@ -104,9 +107,7 @@ class JUnitTestSuiteParserStrategy {
*/
if (!rawTest.contains(testNamePattern)) {
return TestCaseParseResult(
testCase = null,
errorMessage = "The raw Test does not contain $testNamePattern:\n $rawTest",
errorOccurred = true,
error = ErrorDetails("The raw Test does not contain $testNamePattern:\n $rawTest")
)
}

Expand Down Expand Up @@ -182,11 +183,7 @@ class JUnitTestSuiteParserStrategy {
printTestBodyStrategy = printTestBodyStrategy,
)

return TestCaseParseResult(
testCase = currentTest,
errorMessage = "",
errorOccurred = false,
)
return TestCaseParseResult(content = currentTest)
}
}
}

0 comments on commit f14857f

Please sign in to comment.