More verification fixes

This commit is contained in:
Ben Olden-Cooligan 2022-12-18 15:27:57 -08:00
parent 7490821920
commit 50721c200d
6 changed files with 45 additions and 28 deletions

View File

@ -46,7 +46,7 @@ public static class AppTestHelper
public static string GetExePath(AppTestExe exe)
{
var dir = GetBaseDirectory(exe);
if (dir != exe.DefaultRootPath)
if (dir != exe.DefaultRootPath && exe.TestRootSubPath != null)
{
dir = Path.Combine(dir, exe.TestRootSubPath);
}

View File

@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Threading;
using NAPS2.App.Tests.Targets;
using NAPS2.App.Tests.Verification;
using OpenQA.Selenium.Appium.Windows;
@ -60,6 +61,7 @@ public class LanguageSelectionTests : AppiumTests
private void ClickAndResetWindow(string name)
{
ClickAtName(name);
Thread.Sleep(100);
ResetMainWindow();
}

View File

@ -2,16 +2,16 @@ namespace NAPS2.App.Tests.Targets;
public class WinNet462AppTestTarget : IAppTestTarget
{
public AppTestExe Console => GetAppTestExe("NAPS2.App.Console", "NAPS2.Console.exe");
public AppTestExe Gui => GetAppTestExe("NAPS2.App.WinForms", "NAPS2.exe");
public AppTestExe Worker => GetAppTestExe("NAPS2.App.Worker", "NAPS2.Worker.exe");
public AppTestExe Console => GetAppTestExe("NAPS2.App.Console", "NAPS2.Console.exe", null);
public AppTestExe Gui => GetAppTestExe("NAPS2.App.WinForms", "NAPS2.exe", null);
public AppTestExe Worker => GetAppTestExe("NAPS2.App.Worker", "NAPS2.Worker.exe", "lib");
private AppTestExe GetAppTestExe(string project, string exeName)
private AppTestExe GetAppTestExe(string project, string exeName, string testRootSubPath)
{
return new AppTestExe(
Path.Combine(AppTestHelper.SolutionRoot, project, "bin", "Debug", "net462"),
exeName,
TestRootSubPath: "lib");
TestRootSubPath: testRootSubPath);
}
public override string ToString() => "Windows (net462)";

View File

@ -7,7 +7,7 @@ public class NativeLibrary
public static string FindPath(string libraryName, string? baseFolder = null)
{
var baseFolders = !string.IsNullOrWhiteSpace(baseFolder)
? new[] { baseFolder }
? new[] { baseFolder, Path.Combine(baseFolder, "lib") }
: new[] { AssemblyHelper.LibFolder, AssemblyHelper.EntryFolder };
foreach (var actualBaseFolder in baseFolders)
{

View File

@ -5,7 +5,8 @@ namespace NAPS2.Tools;
public static class Cli
{
public static void Run(string command, string args, Dictionary<string, string>? env = null, CancellationToken cancel = default)
public static void Run(string command, string args, Dictionary<string, string>? env = null,
CancellationToken cancel = default, bool noVerbose = false)
{
var startInfo = new ProcessStartInfo
{
@ -30,29 +31,43 @@ public static class Cli
{
throw new Exception($"Could not start {command}");
}
void ConsoleCancel(object? sender, EventArgs e)
{
proc.Kill();
}
cancel.Register(proc.Kill);
// TODO: Maybe we forward Console.CancelKeyPress
Console.CancelKeyPress += ConsoleCancel;
try
{
var savedOutput = new StringBuilder();
var savedOutput = new StringBuilder();
void Save(object sender, DataReceivedEventArgs e)
{
savedOutput.AppendLine(e.Data);
}
proc.OutputDataReceived += Output.EnableVerbose ? Print : Save;
proc.ErrorDataReceived += Print;
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
while (!proc.WaitForExit(100))
{
}
if (proc.ExitCode != 0 && !cancel.IsCancellationRequested)
{
if (!Output.EnableVerbose)
void Save(object sender, DataReceivedEventArgs e)
{
Console.Write(savedOutput);
savedOutput.AppendLine(e.Data);
}
throw new Exception($"Command failed: {command} {args}");
bool print = Output.EnableVerbose && !noVerbose;
proc.OutputDataReceived += print ? Print : Save;
proc.ErrorDataReceived += Print;
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
while (!proc.WaitForExit(100))
{
}
if (proc.ExitCode != 0 && !cancel.IsCancellationRequested)
{
if (!print)
{
Console.Write(savedOutput);
}
throw new Exception($"Command failed: {command} {args}");
}
}
finally
{
Console.CancelKeyPress -= ConsoleCancel;
}
}

View File

@ -16,7 +16,7 @@ public class AppDriverRunner : IDisposable
var path = @"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe";
new Thread(() =>
{
Cli.Run(path, "", cancel: _cts.Token);
Cli.Run(path, "", cancel: _cts.Token, noVerbose: true);
// TODO: Wait for successful starting and handle errors (e.g. if the dev doesn't have developer mode on)
}).Start();
}