This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user