fix: full verification against the brief — 137 confirmed findings fixed over six passes #4

Merged
Alby96 merged 169 commits from claude/keen-knuth-uhxv8w into main 2026-10-13 12:10:04 +02:00
3 changed files with 76 additions and 4 deletions
Showing only changes of commit bef602a9c4 - Show all commits

No files matched your search

+7 -2
View File
@@ -1,3 +1,4 @@
using System.Globalization;
using Titano.Core.Localization;
using Titano.Testing;
@@ -9,10 +10,14 @@ internal static class TestMain
{
// The UI language is process-wide: a test that leaves English outside a serial class races with the English
// assertions of the classes running beside it, so it fails at the switch instead of making another one flaky.
// English comes back before the failure, so the classes beside it never see the other language (switching back
// passes this guard).
Loc.CultureChanged += (_, _) =>
{
if (TestContext.Current is { IsSerial: false } test && Loc.Culture.TwoLetterISOLanguageName != "en")
throw new AssertionException($"{test.TestName} switched the UI language to '{Loc.Culture.Name}' outside a [Serial] class");
if (TestContext.Current is not { IsSerial: false } test || Loc.Culture.TwoLetterISOLanguageName == "en") return;
var culture = Loc.Culture.Name;
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
throw new AssertionException($"{test.TestName} switched the UI language to '{culture}' outside a [Serial] class");
};
return TestRunner.RunAsync(args, typeof(TestMain).Assembly);
}
@@ -0,0 +1,62 @@
using System.Globalization;
using Titano.Core.Localization;
using Titano.Testing;
namespace Titano.Core.Tests.Localization;
/// <summary>
/// The guard <see cref="TestMain"/> installs: a test outside a [Serial] class that leaves English fails, and English is
/// back before anything else runs. Serial itself: the fixture it runs switches the language for a moment.
/// </summary>
[Serial]
public sealed class LanguageGuardTests
{
/// <summary>A fixture (assembly discovery leaves nested classes out) that runs beside others and switches to Hebrew.</summary>
public sealed class SwitchesBesideOthers
{
[Test]
public void Body()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
Assert.Fail("the switch went through");
}
}
[Test]
public async Task ATestBesideOthersThatLeavesEnglishFailsAndEnglishIsBackAtOnce()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
var cultures = new List<string>();
void Record(object? sender, EventArgs e) => cultures.Add(Loc.Culture.Name);
Loc.CultureChanged += Record;
try
{
var result = await TestRunner.ExecuteAsync(TestRunner.Discover(typeof(SwitchesBesideOthers)).Single());
Assert.Equal(TestOutcome.Failed, result.Outcome);
Assert.Equal(typeof(SwitchesBesideOthers).FullName + ".Body switched the UI language to 'he' outside a [Serial] class", result.Message);
Assert.Equal("en", Loc.Culture.Name);
// The guard runs first and switches back inside the change, so later listeners only ever hear of English.
Assert.SequenceEqual(new[] { "en" }, cultures);
}
finally
{
Loc.CultureChanged -= Record;
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
}
}
[Test]
public void ASerialTestMaySwitchTheLanguage()
{
try
{
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
Assert.Equal("he", Loc.Culture.Name);
}
finally
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
}
}
}
+7 -2
View File
@@ -1,3 +1,4 @@
using System.Globalization;
using Titano.Core.Localization;
using Titano.Testing;
@@ -9,10 +10,14 @@ internal static class TestMain
{
// The UI language is process-wide: a test that leaves English outside a serial class races with the English
// assertions of the classes running beside it, so it fails at the switch instead of making another one flaky.
// English comes back before the failure, so the classes beside it never see the other language (switching back
// passes this guard).
Loc.CultureChanged += (_, _) =>
{
if (TestContext.Current is { IsSerial: false } test && Loc.Culture.TwoLetterISOLanguageName != "en")
throw new AssertionException($"{test.TestName} switched the UI language to '{Loc.Culture.Name}' outside a [Serial] class");
if (TestContext.Current is not { IsSerial: false } test || Loc.Culture.TwoLetterISOLanguageName == "en") return;
var culture = Loc.Culture.Name;
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
throw new AssertionException($"{test.TestName} switched the UI language to '{culture}' outside a [Serial] class");
};
return TestRunner.RunAsync(args, typeof(TestMain).Assembly);
}