Files
alex 55ac8e6556 lightweight variant (#1)
Reviewed-on: #1
Co-authored-by: Aleksandr Neychev <alexnejchev73@gmail.com>
2026-08-12 13:37:30 +00:00

37 lines
960 B
C#

using Microsoft.Win32;
namespace CursorLang.Tests.Shared;
/// <summary>
/// A registry key of one test's own. Startup outside a package lives in the
/// registry, and the real startup list of the user is no place to experiment.
/// </summary>
public sealed class TempRegistryKey : IDisposable
{
private const string Parent = @"Software\CursorLang.Tests";
private readonly string _path;
public TempRegistryKey()
{
_path = $@"{Parent}\{Guid.NewGuid():N}";
Key = Registry.CurrentUser.CreateSubKey(_path);
}
public RegistryKey Key { get; }
public void Dispose()
{
Key.Dispose();
try
{
Registry.CurrentUser.DeleteSubKeyTree(_path, throwOnMissingSubKey: false);
}
catch (Exception e) when (e is System.Security.SecurityException or UnauthorizedAccessException)
{
// A leftover key is no reason to fail a test that passed
}
}
}