-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mod loading test, fix infinite loading
- Loading branch information
Showing
8 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/integration-test/kotlin/de/bixilon/minosoft/modding/loader/phase/LoadingPhaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Minosoft | ||
* Copyright (C) 2020-2023 Moritz Zwerger | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* This software is not affiliated with Mojang AB, the original developer of Minecraft. | ||
*/ | ||
|
||
package de.bixilon.minosoft.modding.loader.phase | ||
|
||
import de.bixilon.kutil.cast.CastUtil.unsafeCast | ||
import de.bixilon.kutil.latch.SimpleLatch | ||
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet | ||
import de.bixilon.kutil.reflection.ReflectionUtil.getFieldOrNull | ||
import de.bixilon.minosoft.modding.loader.ModLoader | ||
import de.bixilon.minosoft.terminal.RunConfiguration | ||
import org.testng.Assert.assertEquals | ||
import org.testng.annotations.Test | ||
import java.io.File | ||
|
||
|
||
@Test(groups = ["mods"]) | ||
class LoadingPhaseTest { | ||
|
||
private fun create(path: String): LoadingPhase { | ||
ModLoader.mods.clear() | ||
val phase = LoadingPhase(path) | ||
phase::class.java.getFieldOrNull("path")!!.forceSet(phase, File("./src/integration-test/resources/mods/$path")) | ||
|
||
return phase | ||
} | ||
|
||
private val LoadingPhase.latch: SimpleLatch get() = this::class.java.getFieldOrNull("latch")!!.get(this).unsafeCast() | ||
|
||
fun setup() { | ||
val phase = create("empty") | ||
assertEquals(phase.state, PhaseStates.WAITING) | ||
assertEquals(phase.latch.count, 1) // not started | ||
} | ||
|
||
fun `load but skip loading`() { | ||
val phase = create("empty") | ||
RunConfiguration.IGNORE_MODS = true | ||
phase.load() | ||
RunConfiguration.IGNORE_MODS = false | ||
phase.latch.await() | ||
} | ||
|
||
fun `load empty`() { | ||
val phase = create("empty") | ||
phase.load() | ||
assertEquals(phase.state, PhaseStates.COMPLETE) | ||
assertEquals(phase.latch.count, 0) | ||
phase.await() | ||
assertEquals(ModLoader.mods.mods.size, 0) | ||
} | ||
|
||
fun `broken mod`() { | ||
val phase = create("broken") | ||
phase.load() | ||
phase.await() | ||
assertEquals(ModLoader.mods.mods.size, 0) | ||
} | ||
|
||
fun `nocode mod`() { | ||
val phase = create("nocode") | ||
phase.load() | ||
phase.await() | ||
assertEquals(ModLoader.mods.mods.size, 0) | ||
} | ||
|
||
fun `dummy mod`() { | ||
val phase = create("dummy") | ||
phase.load() | ||
phase.await() | ||
assertEquals(ModLoader.mods.mods.size, 1) | ||
val mod = ModLoader.mods["dummy"]!!.main!! | ||
assertEquals(mod::class.java.getFieldOrNull("dummy")!!.get(mod), 1) | ||
assertEquals(mod::class.java.getFieldOrNull("init")!!.get(mod), 1) | ||
assertEquals(mod::class.java.getFieldOrNull("postInit")!!.get(mod), 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Intentionally bad formatted |
Binary file added
BIN
+1.63 KB
...egration-test/resources/mods/dummy/dummy/de/bixilon/minosoft/modding/dummy/DummyMod.class
Binary file not shown.
30 changes: 30 additions & 0 deletions
30
...integration-test/resources/mods/dummy/dummy/de/bixilon/minosoft/modding/dummy/DummyMod.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Minosoft | ||
* Copyright (C) 2020-2023 Moritz Zwerger | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* This software is not affiliated with Mojang AB, the original developer of Minecraft. | ||
*/ | ||
|
||
package de.bixilon.minosoft.modding.dummy | ||
|
||
import de.bixilon.minosoft.modding.loader.mod.ModMain | ||
|
||
object DummyMod : ModMain() { | ||
var dummy = 1 | ||
var init = 0 | ||
var postInit = 0 | ||
|
||
override fun init() { | ||
init++ | ||
} | ||
|
||
override fun postInit() { | ||
postInit++ | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/integration-test/resources/mods/dummy/dummy/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "dummy", | ||
"version": "1.0", | ||
"main": "de.bixilon.minosoft.modding.dummy.DummyMod" | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
src/integration-test/resources/mods/nocode/dummy/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "dummy", | ||
"version": "1.0", | ||
"main": "de.bixilon.minosoft.modding.dummy.DummyNotExistant" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters