namespace Febe.Tests.Desktop.Support;
/// Files of the repository the desktop tests look at (the committed icon, the build script of the installer).
internal static class Repository
{
/// The folder with Febe.slnx, found from the test binaries upward; null outside a checkout.
public static string? Root()
{
for (var folder = new DirectoryInfo(AppContext.BaseDirectory); folder is not null; folder = folder.Parent)
{
if (File.Exists(Path.Combine(folder.FullName, "Febe.slnx")))
{
return folder.FullName;
}
}
return null;
}
/// A file of the repository; the test is inconclusive when the checkout is not there.
public static string PathOf(params string[] parts)
{
var root = Root();
if (root is null)
{
Assert.Inconclusive("Il repository non รจ accanto alle prove.");
}
return Path.Combine([root, .. parts]);
}
///
/// A file or folder under docs/. The build of the Docker image copies the sources without docs/ (.dockerignore) and
/// without .git: there the test is inconclusive. In a checkout docs/ is always there, so the test goes on and a
/// missing path fails it.
///
public static string Docs(params string[] parts)
{
var path = PathOf(["docs", .. parts]);
var root = Root()!;
var isCheckout = Directory.Exists(Path.Combine(root, ".git")) || File.Exists(Path.Combine(root, ".git"));
if (!Directory.Exists(Path.Combine(root, "docs")) && !isCheckout)
{
Assert.Inconclusive("Questa copia del repository non ha docs/ (costruzione dell'immagine Docker).");
}
return path;
}
}