Skip to content

Commit

Permalink
Fix #80 + add log test
Browse files Browse the repository at this point in the history
  • Loading branch information
sschr15 committed Sep 25, 2023
1 parent 9c7073c commit 0f66565
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 5 deletions.
Empty file.
18 changes: 18 additions & 0 deletions buildSrc/src/main/kotlin/testing.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

plugins {
kotlin("jvm")
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

tasks.named<Test>("test") {
useJUnitPlatform()
}
1 change: 1 addition & 0 deletions module-log-parser/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
`api-module`
`cozy-module`
`published-module`
testing
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import org.quiltmc.community.cozy.modules.logs.data.Order
import org.quiltmc.community.cozy.modules.logs.types.LogParser

private val OPENING_LINES = arrayOf(
"Loading \\d+ mods:\n".toRegex(RegexOption.IGNORE_CASE),
"-- Mods --\n".toRegex(RegexOption.IGNORE_CASE),
"-- Mod Table --\n".toRegex(RegexOption.IGNORE_CASE),
"\tQuilt Mods: \n".toRegex(RegexOption.IGNORE_CASE),
"Loading \\d+ mods:\\n".toRegex(RegexOption.IGNORE_CASE),
"-- Mods --\\n".toRegex(RegexOption.IGNORE_CASE),
"-- Mod Table --\\n".toRegex(RegexOption.IGNORE_CASE),
"\\tQuilt Mods: \\n".toRegex(RegexOption.IGNORE_CASE),
)

private val CLOSE = "\n[^|]".toRegex(RegexOption.IGNORE_CASE)
private val CLOSE = "\\n[^|\\n]*\\n|$".toRegex(RegexOption.IGNORE_CASE)

public class QuiltModsParser : LogParser() {
override val identifier: String = "mods-quilt"
Expand Down
62 changes: 62 additions & 0 deletions module-log-parser/src/test/kotlin/LogParseTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import kotlinx.coroutines.runBlocking
import mu.KotlinLogging
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.quiltmc.community.cozy.modules.logs.Version
import org.quiltmc.community.cozy.modules.logs.config.SimpleLogParserConfig
import org.quiltmc.community.cozy.modules.logs.data.LoaderType
import org.quiltmc.community.cozy.modules.logs.data.Log
import java.net.URL

class LogParseTests {
private val config = SimpleLogParserConfig {}
private val logger = KotlinLogging.logger {}

private suspend fun loadLog(
url: URL,
parseAbortStatus: Boolean = false,
processAbortStatus: Boolean = false
): Log {
val log = Log()
log.content = url.readText()
log.url = url

for (parser in config.getParsers()) {
try {
parser.process(log)
} catch (e: Exception) {
logger.warn(e) { "Unexpected error while parsing logs" }
}

assertEquals(parseAbortStatus, log.aborted) { "Unexpected log abort during parsing" }
}

for (processor in config.getProcessors()) {
try {
processor.process(log)
} catch (e: Exception) {
logger.warn(e) { "Unexpected error while processing logs" }
}

assertEquals(processAbortStatus, log.aborted) { "Unexpected log abort during processing" }
}

return log
}

@Test
fun `Test Quilt crash log`(): Unit = runBlocking {
val file = ClassLoader.getSystemResource("quilt-crash.txt")
val log = loadLog(file)

assertEquals(167, log.getMods().size)
assertEquals(Version("1.19.3"), log.minecraftVersion)
assertEquals(mapOf(LoaderType.Quilt to Version("0.18.10")), log.getLoaders())
}
}
Loading

0 comments on commit 0f66565

Please sign in to comment.