Skip to content

Commit

Permalink
Fix common test pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
bachish committed Aug 27, 2024
1 parent d21e22e commit c845e36
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
6 changes: 6 additions & 0 deletions benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ repositories {
}

dependencies {
// Other dependencies.
testImplementation(kotlin("test"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.0")
//compared projects
// 1. for ucfs
Expand All @@ -22,4 +24,8 @@ dependencies {

kotlin {
jvmToolchain(17)
}

tasks.test {
useJUnitPlatform()
}
1 change: 0 additions & 1 deletion benchmarks/src/test/kotlin/AntlrBenchmark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ class AntlrBenchmark: TimeParsingBenchmark() {
)
antlrParser.compilationUnit()
}

}
25 changes: 21 additions & 4 deletions benchmarks/src/test/kotlin/TimeParsingBenchmark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@ import org.junit.jupiter.api.TestFactory
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.io.path.name

abstract class TimeParsingBenchmark {
val version: String = LocalDateTime.now().format(
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))
private val repeatCount: Int = 5
lateinit var file: File


private fun initFolder(): DynamicTest {
val resultPath = Path.of("src", "test", "result")
return dynamicTest("initiation for ${getShortName()}") {
Files.createDirectories(resultPath)
file = File(resultPath.toString(), "${getShortName()}_$version.csv")
file.createNewFile()
file.writeText("fileName,result(avg $repeatCount times)")
}
}


val repeatCount: Int = 5
abstract fun getShortName(): String

private fun runTimeTest(fileName: String, text: String) {
Expand All @@ -22,12 +38,13 @@ abstract class TimeParsingBenchmark {
result /= repeatCount
val message = "$fileName,$result"
println(message)
File("${getShortName()}.csv").writeText(message)
file.appendText("\n$message")
}

abstract fun parse(text: String)

private fun getResourceFolder(): String = Path.of("java", "correct").toString()
private fun getResourceFolder(): String = Path.of("java", "correct", "junit-4-12")
.toString()


private fun getResource(resourceFolder: String): Path {
Expand All @@ -42,7 +59,7 @@ abstract class TimeParsingBenchmark {
}

private fun getTests(folder: Path, run: (String, String) -> Unit): Collection<DynamicTest> {
return Files.list(folder).map { file ->
return listOf(initFolder()) + Files.list(folder).map { file ->
dynamicTest(file.fileName.toString()) {
val source = file.toFile().readText()
run(file.name, source)
Expand Down

0 comments on commit c845e36

Please sign in to comment.