File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed
main/java/io/github/opencubicchunks/cubicchunks
test/java/io/github/opencubicchunks/cubicchunks/testutils Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 1818 */
1919@ Mod ("cubicchunks" )
2020public class CubicChunks extends CubicChunksBase {
21+ /**
22+ * true when running in a junit test, false otherwise.
23+ */
24+ public static boolean IS_IN_TEST = false ;
2125 protected static CommonConfig config = null ;
2226 // For hardcoding height in P1
2327 public static final int SUPERFLAT_HEIGHT = 5 ;
Original file line number Diff line number Diff line change 44
55import com .electronwill .nightconfig .core .CommentedConfig ;
66import com .electronwill .nightconfig .core .Config ;
7+ import io .github .opencubicchunks .cubicchunks .CubicChunks ;
78import net .neoforged .fml .loading .FMLPaths ;
89
910public class CommonConfig extends BaseConfig {
1011 private static final String FILE_NAME = "cubicchunks_common.toml" ;
1112 // TODO forge/fabric-agnostic method for getting config directory
12- private static final File FILE_PATH = new File (FMLPaths .CONFIGDIR .get ().toFile (), FILE_NAME );
13+ // Note that this relies on IS_IN_TEST being set before this class is classloaded
14+ private static final File FILE_PATH = CubicChunks .IS_IN_TEST ? null : new File (FMLPaths .CONFIGDIR .get ().toFile (), FILE_NAME );
1315
1416 private static final String KEY_GENERAL = "general" ;
1517 private static final String KEY_VERTICAL_VIEW_DISTANCE = KEY_GENERAL + ".verticalViewDistance" ;
@@ -60,6 +62,10 @@ public void setGenerateNewWorldsAsCC(boolean generateNewWorldsAsCC) {
6062
6163 public static CommonConfig getConfig () {
6264 var config = createDefaultConfig ();
65+ if (CubicChunks .IS_IN_TEST ) {
66+ // Skip file access when running in a test environment; tests should manually update relevant config values before running game code.
67+ return new CommonConfig (config );
68+ }
6369 // Read existing values to the config
6470 if (FILE_PATH .exists ()) {
6571 read (FILE_PATH , config );
Original file line number Diff line number Diff line change 11package io .github .opencubicchunks .cubicchunks .testutils ;
22
3+ import io .github .opencubicchunks .cubicchunks .CubicChunks ;
34import net .minecraft .SharedConstants ;
45import net .minecraft .server .Bootstrap ;
56import org .junit .jupiter .api .AfterEach ;
@@ -12,6 +13,7 @@ public class BaseTest {
1213 @ BeforeAll
1314 public static void setup () {
1415 SharedConstants .tryDetectVersion ();
16+ CubicChunks .IS_IN_TEST = true ;
1517 Bootstrap .bootStrap ();
1618 SharedConstants .IS_RUNNING_IN_IDE = true ;
1719 }
You can’t perform that action at this time.
0 commit comments