From 9e1a9e6ede2cf428a73ba8023e4c7d5dec3c9a13 Mon Sep 17 00:00:00 2001 From: ike709 Date: Sat, 16 Nov 2024 00:06:00 -0600 Subject: [PATCH] Unit test some `world` vars against bad const folding, fix `world.system_type` (#2096) Co-authored-by: ike709 Co-authored-by: wixoa --- .../DMProject/Tests/Builtins/world_opendream_topic_port.dm | 3 +++ Content.Tests/DMProject/Tests/Builtins/world_system_type.dm | 3 +++ DMCompiler/DMStandard/Defines.dm | 4 ++-- OpenDreamRuntime/Objects/Types/DreamObjectWorld.cs | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 Content.Tests/DMProject/Tests/Builtins/world_opendream_topic_port.dm create mode 100644 Content.Tests/DMProject/Tests/Builtins/world_system_type.dm diff --git a/Content.Tests/DMProject/Tests/Builtins/world_opendream_topic_port.dm b/Content.Tests/DMProject/Tests/Builtins/world_opendream_topic_port.dm new file mode 100644 index 0000000000..a815651f3f --- /dev/null +++ b/Content.Tests/DMProject/Tests/Builtins/world_opendream_topic_port.dm @@ -0,0 +1,3 @@ + +/proc/RunTest() + ASSERT(isnum(world.opendream_topic_port)) diff --git a/Content.Tests/DMProject/Tests/Builtins/world_system_type.dm b/Content.Tests/DMProject/Tests/Builtins/world_system_type.dm new file mode 100644 index 0000000000..ea9ce6b505 --- /dev/null +++ b/Content.Tests/DMProject/Tests/Builtins/world_system_type.dm @@ -0,0 +1,3 @@ + +/proc/RunTest() + ASSERT(istext(world.system_type) && length(world.system_type)) diff --git a/DMCompiler/DMStandard/Defines.dm b/DMCompiler/DMStandard/Defines.dm index fcd13bf77d..148660d34c 100644 --- a/DMCompiler/DMStandard/Defines.dm +++ b/DMCompiler/DMStandard/Defines.dm @@ -60,8 +60,8 @@ #define SYNC_STEPS 3 //world.system_type -#define UNIX 0 -#define MS_WINDOWS 1 +#define UNIX "UNIX" +#define MS_WINDOWS "MS_WINDOWS" //Icon blending functions #define ICON_ADD 0 diff --git a/OpenDreamRuntime/Objects/Types/DreamObjectWorld.cs b/OpenDreamRuntime/Objects/Types/DreamObjectWorld.cs index 2582437476..0dd50ac411 100644 --- a/OpenDreamRuntime/Objects/Types/DreamObjectWorld.cs +++ b/OpenDreamRuntime/Objects/Types/DreamObjectWorld.cs @@ -214,9 +214,9 @@ protected override bool TryGetVar(string varName, out DreamValue value) { case "system_type": //system_type value should match the defines in Defines.dm if (Environment.OSVersion.Platform is PlatformID.Unix or PlatformID.MacOSX or PlatformID.Other) - value = new DreamValue(0); + value = new DreamValue("UNIX"); else - value = new DreamValue(1); //Windows + value = new DreamValue("MS_WINDOWS"); //Windows return true;