Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit 4c84b03

Browse files
committed
Fixed a small bug and some minor changes
- Updated testing lib - Added some docs in the tests Signed-off-by: DeathsGun <deathsgun@protonmail.com>
1 parent 6ce1077 commit 4c84b03

File tree

5 files changed

+54
-20
lines changed

5 files changed

+54
-20
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ dependencies {
4242
minecraft "com.mojang:minecraft:${project.minecraft_version}"
4343
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
4444
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
45-
45+
4646
modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"
4747
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
4848

49-
testImplementation "org.jetbrains.kotlin:kotlin-test:1.5.21"
49+
testImplementation 'org.jetbrains.kotlin:kotlin-test:1.5.31'
5050
}
5151

5252
processResources {

src/main/kotlin/xyz/deathsgun/modmanager/update/UpdateManager.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ class UpdateManager {
120120

121121
val queryResult = provider.search(metadata.name, Sorting.RELEVANCE, 0, 10)
122122
if (queryResult is ModsResult.Error) {
123-
logger.warn("Error while searching for fallback id for mod {}: ", metadata.id, queryResult.cause)
123+
logger.warn(
124+
"Error while searching for fallback id for mod {}: {}",
125+
metadata.id,
126+
queryResult.text.key,
127+
queryResult.cause
128+
)
124129
ModManager.modManager.setModState(metadata.id, metadata.id, ModState.INSTALLED)
125130
return
126131
}

src/main/kotlin/xyz/deathsgun/modmanager/update/VersionFinder.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ object VersionFinder {
5454
var latestVer: SemanticVersion? = null
5555
val installedVer = VersionDeserializer.deserializeSemantic(installedVersion)
5656
for (version in versions) {
57-
val parsedVersion = try {
58-
VersionDeserializer.deserializeSemantic(version.version)
59-
} catch (e: VersionParsingException) {
60-
continue
61-
}
57+
val parsedVersion = VersionDeserializer.deserializeSemantic(version.version)
6258
if (latestVersion == null) {
6359
latestVersion = version
6460
latestVer = parsedVersion
@@ -69,7 +65,7 @@ object VersionFinder {
6965
latestVer = parsedVersion
7066
}
7167
}
72-
if (installedVersion == latestVersion?.version || installedVer >= latestVer) {
68+
if (installedVersion == latestVersion?.version || (latestVer != null && installedVer >= latestVer)) {
7369
return null
7470
}
7571
return latestVersion

src/test/kotlin/xyz/deathsgun/modmanager/dummy/DummyModrinthProvider.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import java.io.InputStreamReader
3131
import java.time.Instant
3232
import java.time.ZoneOffset
3333

34+
/**
35+
* Dummy which provided the version data
36+
* for [xyz.deathsgun.modmanager.update.VersionFinderTest]
37+
*/
3438
internal class DummyModrinthVersionProvider : IModUpdateProvider {
3539

3640
private val json = Json {
@@ -41,6 +45,10 @@ internal class DummyModrinthVersionProvider : IModUpdateProvider {
4145
return "Modrinth"
4246
}
4347

48+
/**
49+
* Reads the provided id from /version/id.json
50+
* @param id the mod slug from Modrinth
51+
*/
4452
@OptIn(ExperimentalSerializationApi::class)
4553
override fun getVersionsForMod(id: String): VersionResult {
4654
return try {

src/test/kotlin/xyz/deathsgun/modmanager/update/VersionFinderTest.kt

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package xyz.deathsgun.modmanager.update
1818

1919
import net.fabricmc.loader.api.VersionParsingException
20-
import org.apache.logging.log4j.LogManager
2120
import org.junit.jupiter.api.DynamicTest.dynamicTest
2221
import org.junit.jupiter.api.TestFactory
2322
import org.junit.jupiter.api.fail
@@ -30,11 +29,17 @@ import kotlin.test.assertNotNull
3029
import kotlin.test.assertNull
3130
import kotlin.test.assertTrue
3231

32+
/**
33+
* Tests the [VersionFinder] implementation
34+
*/
3335
internal class VersionFinderTest {
3436

35-
private val logger = LogManager.getLogger()
3637
private val provider: IModUpdateProvider = DummyModrinthVersionProvider()
3738

39+
/**
40+
* Tests the fallback for versions which are not following
41+
* the SemVer scheme. These mods are resolved by their release date.
42+
*/
3843
@TestFactory
3944
fun findUpdateByFallback() = listOf(
4045
Scenario(
@@ -76,21 +81,45 @@ internal class VersionFinderTest {
7681
}
7782
}
7883

84+
/**
85+
* Tests some version scenarios in which the [VersionFinder]
86+
* should definitely return null.
87+
*/
7988
@TestFactory
8089
fun findUpdateByVersionError() = listOf(
90+
/**
91+
* This scenario will fail because mc1.17.1-0.7.1
92+
* can not be parsed by the parser as it starts with mc.
93+
*/
8194
Scenario(
8295
"lithium",
83-
"mc1.17.1-0.7.4",
96+
"none",
8497
"mc1.17.1-0.7.1",
8598
Config.UpdateChannel.STABLE,
8699
"1.17"
87100
),
101+
/**
102+
* This scenario will fail because fabric-5.3.3-BETA+6027c282
103+
* can not be parsed by the parser as it starts with fabric.
104+
*/
88105
Scenario(
89106
"terra",
90-
"5.4.1-BETA+40e95073",
107+
"none",
91108
"fabric-5.3.3-BETA+6027c282",
92109
Config.UpdateChannel.ALL,
93110
"1.17"
111+
),
112+
/**
113+
* No update for this scenario should be found.
114+
* When an update should be found this would be an
115+
* error as 2.0.13 is the latest
116+
*/
117+
Scenario(
118+
"modmenu",
119+
"none",
120+
"2.0.13",
121+
Config.UpdateChannel.STABLE,
122+
"1.17"
94123
)
95124
).map { scenario ->
96125
dynamicTest("${scenario.mod} ${scenario.expectedVersion} ${scenario.channel}") {
@@ -112,6 +141,9 @@ internal class VersionFinderTest {
112141
}
113142
}
114143

144+
/**
145+
* This tests all mods which are following the semantic version scheme.
146+
*/
115147
@TestFactory
116148
fun findUpdateByVersion() = listOf(
117149
Scenario(
@@ -121,13 +153,6 @@ internal class VersionFinderTest {
121153
Config.UpdateChannel.ALL,
122154
"1.17"
123155
),
124-
Scenario(
125-
"terra",
126-
"5.4.1-BETA+40e95073",
127-
"5.3.3-BETA+6027c282", // actually fabric-5.3.3-BETA+6027c282
128-
Config.UpdateChannel.ALL,
129-
"1.17"
130-
),
131156
Scenario(
132157
"modmenu",
133158
"2.0.13",

0 commit comments

Comments
 (0)