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

39 lines
994 B
C#

namespace CursorLang.Tests.Shared;
/// <summary>
/// An empty folder for the lifetime of one test. Settings live in a file, and
/// working with that file has to be verified where nothing is worth losing.
/// </summary>
public sealed class TempFolder : IDisposable
{
public TempFolder()
{
Path = System.IO.Path.Combine(
System.IO.Path.GetTempPath(),
"CursorLang.Tests",
Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(Path);
}
public string Path { get; }
public string File(string name) => System.IO.Path.Combine(Path, name);
public void Dispose()
{
try
{
if (Directory.Exists(Path))
{
Directory.Delete(Path, recursive: true);
}
}
catch (Exception e) when (e is IOException or UnauthorizedAccessException)
{
// Litter in the temp folder is no reason to fail a test that passed
}
}
}