Skip to content

Commit 123f37c

Browse files
committed
Amend EnsureInitialised init variable
1 parent c6a85aa commit 123f37c

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using NUnit.Framework;
22
using System.Runtime.InteropServices;
3-
using Terraria.Utilities;
43

54
namespace TerrariaServerAPI.Tests;
65

@@ -11,27 +10,28 @@ public class BaseTest
1110
[OneTimeSetUp]
1211
public void EnsureInitialised()
1312
{
14-
TestContext.Out.WriteLine($"Test architecture {RuntimeInformation.ProcessArchitecture}");
15-
1613
if (!_initialized)
1714
{
15+
TestContext.Out.WriteLine($"Test architecture {RuntimeInformation.ProcessArchitecture}");
16+
1817
bool invoked = false;
19-
HookEvents.HookDelegate<global::Terraria.Main, HookEvents.Terraria.Main.DedServEventArgs> cb = (instance, args) =>
18+
HookEvents.HookDelegate<Terraria.Main, HookEvents.Terraria.Main.DedServEventArgs> cb = (instance, args) =>
2019
{
2120
invoked = true;
2221
// DedServ typically requires input, so no need to continue execution
2322
args.ContinueExecution = false;
2423
// DedServ calls the following, which is needed for subsequent tests
25-
global::Terraria.Main.rand = new UnifiedRandom();
2624
instance.Initialize();
2725
};
2826
HookEvents.Terraria.Main.DedServ += cb;
2927

30-
global::TerrariaApi.Server.Program.Main([]);
28+
TerrariaApi.Server.Program.Main([]);
3129

3230
HookEvents.Terraria.Main.DedServ -= cb;
3331

3432
Assert.That(invoked, Is.True);
33+
34+
_initialized = true;
3535
}
3636
}
3737
}

TerrariaServerAPI.Tests/ServerInitTests.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@ public void EnsureRuntimeDetours()
2222

2323
bool invoked = false;
2424

25-
On.Terraria.Main.hook_DedServ callback = (orig, self) =>
26-
{
27-
invoked = true;
28-
// DedServ typically requires input, so no need to continue execution
29-
};
30-
On.Terraria.Main.DedServ += callback;
25+
On.Terraria.Program.hook_RunGame callback = (orig) => invoked = true;
26+
On.Terraria.Program.RunGame += callback;
3127

32-
global::TerrariaApi.Server.Program.Main([]);
28+
Terraria.Program.RunGame();
3329

34-
On.Terraria.Main.DedServ -= callback;
30+
On.Terraria.Program.RunGame -= callback;
3531

3632
Assert.That(invoked, Is.True);
3733
}

0 commit comments

Comments
 (0)