Skip to content

Commit

Permalink
Rework cds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyavskiy committed Sep 5, 2023
1 parent 195dd53 commit 8ab37af
Show file tree
Hide file tree
Showing 12 changed files with 19,872 additions and 17 deletions.
3 changes: 0 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ grpc-kotlin = "1.3.1" # https://github.com/grpc/grpc-kotlin
dokka = "1.8.20" # https://github.com/Kotlin/dokka
retrofit = "2.9.0" # https://mvnrepository.com/artifact/com.squareup.retrofit2/retrofit/2.9.0
json5 = "0.3.0" # https://github.com/xn32/json5k
approvaltests = "18.7.1" # https://github.com/approvals/ApprovalTests.Java

[libraries]

Expand Down Expand Up @@ -78,8 +77,6 @@ grpc-gen-kotlin = { version.ref = "grpc-kotlin", group = "io.grpc", name = "prot
protobuf = { version.ref = "protobuf", group = "com.google.protobuf", name = "protobuf-kotlin" }
protoc = { version.ref = "protobuf", group = "com.google.protobuf", name = "protoc" }

approvaltests = { version.ref = "approvaltests", group = "com.approvaltests", name = "approvaltests" }

[plugins]

ktor = { id = "io.ktor.plugin", version.ref = "ktor" }
Expand Down
1 change: 0 additions & 1 deletion src/cds/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,4 @@ dependencies {
implementation(projects.common)

testImplementation(libs.kotlin.junit)
testImplementation(libs.approvaltests)
}
51 changes: 41 additions & 10 deletions src/cds/src/test/kotlin/org/icpclive/cds/CdsLoadersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,59 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.approvaltests.Approvals
import org.approvaltests.core.Options
import org.icpclive.api.ContestResultType
import org.icpclive.api.tunning.*
import org.icpclive.cds.adapters.applyAdvancedProperties
import org.icpclive.cds.adapters.finalContestState
import org.icpclive.cds.clics.FeedVersion
import org.icpclive.cds.common.ContestParseResult
import org.icpclive.cds.settings.*
import org.opentest4j.AssertionFailedError
import java.nio.file.Path
import kotlin.test.Test
import kotlin.text.Regex
import kotlin.time.Duration.Companion.minutes

class CdsLoadersTest {
object CdsLoadersTest {
private val goldenDataDir = Path.of("").toAbsolutePath().resolve("testData").resolve("loaders").resolve("goldenData")
private val updateTestData = false

@Test
fun pcmsTest() {
fun pcms() {
loaderTest(
goldenDataDir.resolve("pcms.txt"),
PCMSSettings(
url = "testData/loaders/pcms.xml"
)
)
}

@Test
fun pcmsIOITest() {
fun pcmsIOI() {
loaderTest(
goldenDataDir.resolve("pcmsIOI.txt"),
PCMSSettings(
resultType = ContestResultType.IOI,
url = "testData/loaders/pcms-ioi.xml"
)
)
}

@Test
fun ejudge() {
loaderTest(
goldenDataDir.resolve("ejudge.txt"),
EjudgeSettings(
url = "testData/loaders/ejudge.xml"
)
)
}


@Test
fun clics202003Test() {
fun clics202003() {
loaderTest(
goldenDataDir.resolve("clics202003.txt"),
ClicsSettings(
url = "testData/loaders/clics-2020-03",
feedVersion = FeedVersion.`2020_03`
Expand All @@ -49,8 +65,9 @@ class CdsLoadersTest {
}

@Test
fun clics202207Test() {
fun clics202207() {
loaderTest(
goldenDataDir.resolve("clics202207.txt"),
ClicsSettings(
url = "testData/loaders/clics-2022-07",
feedVersion = FeedVersion.`2022_07`
Expand All @@ -61,6 +78,7 @@ class CdsLoadersTest {
@Test
fun testSys() {
loaderTest(
goldenDataDir.resolve("testSys.txt"),
TestSysSettings(
url = "testData/loaders/testsys.dat"
)
Expand All @@ -70,6 +88,7 @@ class CdsLoadersTest {
@Test
fun testSysWithAdvancedOverride() {
loaderTest(
goldenDataDir.resolve("testSysWithAdvancedOverride.txt"),
TestSysSettings(
url = "testData/loaders/testsys.dat"
),
Expand Down Expand Up @@ -100,7 +119,7 @@ class CdsLoadersTest {
prettyPrint = true
}

private fun loaderTest(args: CDSSettings, advanced: AdvancedProperties? = null) {
private fun loaderTest(expectedFile: Path, args: CDSSettings, advanced: AdvancedProperties? = null) {
val loader = args.toFlow(emptyMap())
val result = runBlocking {
val result = withTimeout(1.minutes) {
Expand All @@ -124,7 +143,19 @@ class CdsLoadersTest {
result
}
}
val options = Options()
Approvals.verify(json.encodeToString(result), options)
val actual = json.encodeToString(result)
val expected = expectedFile.toFile().takeIf { it.exists() }?.readText() ?: ""
if (actual != expected) {
if (updateTestData) {
expectedFile.toFile().printWriter().use {
it.print(actual)
}
}
throw AssertionFailedError(
"Actual result doesn't match expected in file ${expectedFile}",
expected,
actual,
)
}
}
}
3 changes: 0 additions & 3 deletions src/cds/src/test/kotlin/org/icpclive/cds/approve.sh

This file was deleted.

Loading

0 comments on commit 8ab37af

Please sign in to comment.