mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-03 03:54:24 +00:00
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
|
|
using AIStudio.Tools;
|
|
|
|
namespace AIStudio.Tests.Tools;
|
|
|
|
/// <summary>
|
|
/// Checks which failures to start Pandoc mean that it is not installed.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Most users have no Pandoc until they install it through AI Studio. The log notes that once, without a stack trace,
|
|
/// and keeps errors with their stack traces for what nobody expects. The exception comes from a real Process.Start, since
|
|
/// only it shows what each OS reports for a program which does not exist.
|
|
/// </remarks>
|
|
[TestFixture]
|
|
public sealed class PandocMissingExecutableTests
|
|
{
|
|
[Test]
|
|
public void AProgramWhichDoesNotExistCounts()
|
|
{
|
|
var startInfo = new ProcessStartInfo($"ai-studio-missing-program-{Guid.NewGuid():N}")
|
|
{
|
|
ArgumentList = { "--version" },
|
|
UseShellExecute = false,
|
|
RedirectStandardOutput = true,
|
|
RedirectStandardError = true
|
|
};
|
|
|
|
var failure = Assert.Catch(() => Process.Start(startInfo)?.Dispose());
|
|
|
|
Assert.That(Pandoc.IsMissingExecutable(failure!), Is.True, failure?.ToString());
|
|
}
|
|
|
|
[Test]
|
|
public void AProgramWhichCannotBeStartedDoesNotCount()
|
|
{
|
|
// Windows reports a denied access as ERROR_ACCESS_DENIED (5), macOS and Linux as EACCES (13):
|
|
var failure = new Win32Exception(OperatingSystem.IsWindows() ? 5 : 13);
|
|
|
|
Assert.That(Pandoc.IsMissingExecutable(failure), Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void AnotherExceptionDoesNotCount()
|
|
{
|
|
var failure = new InvalidOperationException("No process is associated with this object.");
|
|
|
|
Assert.That(Pandoc.IsMissingExecutable(failure), Is.False);
|
|
}
|
|
} |