40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
using System.IO;
|
|
|
|
namespace CursorLang.Tests.Infrastructure;
|
|
|
|
/// <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>
|
|
internal sealed class TempFolder : IDisposable
|
|
{
|
|
internal TempFolder()
|
|
{
|
|
Path = System.IO.Path.Combine(
|
|
System.IO.Path.GetTempPath(),
|
|
"CursorLang.Tests",
|
|
Guid.NewGuid().ToString("N"));
|
|
|
|
Directory.CreateDirectory(Path);
|
|
}
|
|
|
|
internal string Path { get; }
|
|
|
|
internal 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
|
|
}
|
|
}
|
|
}
|