test(diagnostics): restore RenderingDiagnostics state in try/finally
Final code review of Phase 1 flagged that the three flag-mutating tests leaked static state across test boundaries. Wrap each in try/finally that snapshots IndoorAll on entry and restores it on exit, matching the PhysicsDiagnosticsTests pattern at line 30-49. Tests now safe under parallel test runs + future additions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
25f009140a
commit
9f152d9754
1 changed files with 55 additions and 25 deletions
|
|
@ -5,8 +5,17 @@ namespace AcDream.Core.Tests.Rendering;
|
||||||
|
|
||||||
public sealed class RenderingDiagnosticsTests
|
public sealed class RenderingDiagnosticsTests
|
||||||
{
|
{
|
||||||
|
// Each flag-mutating test snapshots the IndoorAll state on entry and
|
||||||
|
// restores it via try/finally. RenderingDiagnostics is a process-wide
|
||||||
|
// static (env-var-initialized); without restoration a mutated state
|
||||||
|
// leaks into other tests + into parallel test runs. Mirrors the
|
||||||
|
// PhysicsDiagnosticsTests pattern at line 30-49.
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void IndoorAll_True_TurnsAllFlagsOn()
|
public void IndoorAll_True_TurnsAllFlagsOn()
|
||||||
|
{
|
||||||
|
bool initial = RenderingDiagnostics.IndoorAll;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
// Reset all flags off first to make the test deterministic
|
// Reset all flags off first to make the test deterministic
|
||||||
// regardless of env-var state on the test runner.
|
// regardless of env-var state on the test runner.
|
||||||
|
|
@ -25,9 +34,17 @@ public sealed class RenderingDiagnosticsTests
|
||||||
Assert.True(RenderingDiagnostics.ProbeIndoorCullEnabled);
|
Assert.True(RenderingDiagnostics.ProbeIndoorCullEnabled);
|
||||||
Assert.True(RenderingDiagnostics.IndoorAll);
|
Assert.True(RenderingDiagnostics.IndoorAll);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
RenderingDiagnostics.IndoorAll = initial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void IndoorAll_False_TurnsAllFlagsOff()
|
public void IndoorAll_False_TurnsAllFlagsOff()
|
||||||
|
{
|
||||||
|
bool initial = RenderingDiagnostics.IndoorAll;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
RenderingDiagnostics.IndoorAll = true; // start from all-on
|
RenderingDiagnostics.IndoorAll = true; // start from all-on
|
||||||
RenderingDiagnostics.IndoorAll = false;
|
RenderingDiagnostics.IndoorAll = false;
|
||||||
|
|
@ -39,14 +56,27 @@ public sealed class RenderingDiagnosticsTests
|
||||||
Assert.False(RenderingDiagnostics.ProbeIndoorCullEnabled);
|
Assert.False(RenderingDiagnostics.ProbeIndoorCullEnabled);
|
||||||
Assert.False(RenderingDiagnostics.IndoorAll);
|
Assert.False(RenderingDiagnostics.IndoorAll);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
RenderingDiagnostics.IndoorAll = initial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void IndoorAll_OneOff_ReadsAsFalse()
|
public void IndoorAll_OneOff_ReadsAsFalse()
|
||||||
|
{
|
||||||
|
bool initial = RenderingDiagnostics.IndoorAll;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
RenderingDiagnostics.IndoorAll = true;
|
RenderingDiagnostics.IndoorAll = true;
|
||||||
RenderingDiagnostics.ProbeIndoorCullEnabled = false; // flip one off
|
RenderingDiagnostics.ProbeIndoorCullEnabled = false; // flip one off
|
||||||
Assert.False(RenderingDiagnostics.IndoorAll);
|
Assert.False(RenderingDiagnostics.IndoorAll);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
RenderingDiagnostics.IndoorAll = initial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(0x00000029ul, false)] // outdoor cell 0x29 in 8x8 grid
|
[InlineData(0x00000029ul, false)] // outdoor cell 0x29 in 8x8 grid
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue