Detect VelopackApp.Run() in any method in main module

This commit is contained in:
Caelan Sayler
2024-03-27 10:23:01 +00:00
parent 97c9a05dbb
commit f1fd069ac7
10 changed files with 315 additions and 169 deletions

View File

@@ -7,6 +7,10 @@ try {
bool shouldExit = false;
bool shouldAutoUpdate = args.Any(a => a.Equals("--autoupdate", StringComparison.OrdinalIgnoreCase));
#if USE_ASYNC_MAIN
await Task.Delay(10).ConfigureAwait(false);
#endif
#if !NO_VELO_BUILDER
VelopackApp.Build()
.SetAutoApplyOnStartup(shouldAutoUpdate)

View File

@@ -10,6 +10,10 @@
<DefineConstants>NO_VELO_BUILDER</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" $(UseAsyncMain) != '' ">
<DefineConstants>USE_ASYNC_MAIN</DefineConstants>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Velopack\Velopack.csproj" />
</ItemGroup>

View File

@@ -1,30 +1,39 @@
using Velopack.Packaging.Exceptions;
using Divergic.Logging.Xunit;
using Velopack.Packaging.Exceptions;
using Velopack.Packaging.Windows;
using Velopack.Vpk.Logging;
namespace Velopack.Packaging.Tests;
public class DotnetUtilTests
public class CompatUtilTests
{
private readonly ITestOutputHelper _output;
public DotnetUtilTests(ITestOutputHelper output)
public CompatUtilTests(ITestOutputHelper output)
{
_output = output;
}
private ICacheLogger<CompatUtilTests> GetCompat(out CompatUtil compat)
{
var logger = _output.BuildLoggerFor<CompatUtilTests>();
compat = new CompatUtil(logger, new BasicConsole(logger, new DefaultPromptValueFactory(true)));
return logger;
}
[SkippableFact]
public void NonDotnetBinaryPasses()
{
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
using var logger = _output.BuildLoggerFor<DotnetUtilTests>();
Assert.Null(DotnetUtil.VerifyVelopackApp(PathHelper.GetRustAsset("testapp.exe"), logger));
using var logger = GetCompat(out var compat);
Assert.Null(compat.Verify(PathHelper.GetRustAsset("testapp.exe")));
}
[SkippableFact]
public void PublishSingleFilePasses()
{
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
using var logger = _output.BuildLoggerFor<DotnetUtilTests>();
using var logger = GetCompat(out var compat);
using var _1 = Utility.GetTempDirectory(out var dir);
var sample = PathHelper.GetAvaloniaSample();
Exe.InvokeAndThrowIfNonZero(
@@ -34,18 +43,18 @@ public class DotnetUtilTests
sample);
var path = Path.Combine(dir, "AvaloniaCrossPlat.exe");
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, DotnetUtil.VerifyVelopackApp(path, logger));
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, compat.Verify(path));
var newPath = Path.Combine(dir, "AvaloniaCrossPlat-asd2.exe");
File.Move(path, newPath);
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, DotnetUtil.VerifyVelopackApp(newPath, logger));
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, compat.Verify(newPath));
}
[SkippableFact]
public void PublishDotnet6Passes()
{
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
using var logger = _output.BuildLoggerFor<DotnetUtilTests>();
using var logger = GetCompat(out var compat);
using var _1 = Utility.GetTempDirectory(out var dir);
var sample = PathHelper.GetAvaloniaSample();
Exe.InvokeAndThrowIfNonZero(
@@ -55,18 +64,18 @@ public class DotnetUtilTests
sample);
var path = Path.Combine(dir, "AvaloniaCrossPlat.exe");
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, DotnetUtil.VerifyVelopackApp(path, logger));
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, compat.Verify(path));
var newPath = Path.Combine(dir, "AvaloniaCrossPlat-asd2.exe");
File.Move(path, newPath);
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, DotnetUtil.VerifyVelopackApp(newPath, logger));
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, compat.Verify(newPath));
}
[SkippableFact]
public void PublishNet48Passes()
{
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
using var logger = _output.BuildLoggerFor<DotnetUtilTests>();
using var logger = GetCompat(out var compat);
using var _1 = Utility.GetTempDirectory(out var dir);
var sample = PathHelper.GetWpfSample();
Exe.InvokeAndThrowIfNonZero(
@@ -75,18 +84,18 @@ public class DotnetUtilTests
sample);
var path = Path.Combine(dir, "VeloWpfSample.exe");
Assert.NotNull(DotnetUtil.VerifyVelopackApp(path, logger));
Assert.NotNull(compat.Verify(path));
var newPath = Path.Combine(dir, "VeloWpfSample-asd2.exe");
File.Move(path, newPath);
Assert.NotNull(DotnetUtil.VerifyVelopackApp(newPath, logger));
Assert.NotNull(compat.Verify(newPath));
}
[SkippableFact]
public void UnawareDotnetAppFails()
{
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
using var logger = _output.BuildLoggerFor<DotnetUtilTests>();
using var logger = GetCompat(out var compat);
using var _1 = Utility.GetTempDirectory(out var dir);
var sample = PathHelper.GetTestRootPath("TestApp");
Exe.InvokeAndThrowIfNonZero(
@@ -96,6 +105,27 @@ public class DotnetUtilTests
sample);
var path = Path.Combine(dir, "TestApp.exe");
Assert.Throws<UserInfoException>(() => DotnetUtil.VerifyVelopackApp(path, logger));
Assert.Throws<UserInfoException>(() => compat.Verify(path));
}
[SkippableFact]
public void PublishAsyncMainPasses()
{
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
using var logger = GetCompat(out var compat);
using var _1 = Utility.GetTempDirectory(out var dir);
var sample = PathHelper.GetTestRootPath("TestApp");
Exe.InvokeAndThrowIfNonZero(
"dotnet",
new string[] { "publish", "--no-self-contained", "-r", "win-x64", "-o", dir,
"-p:UseAsyncMain=true" },
sample);
var path = Path.Combine(dir, "TestApp.exe");
Assert.NotNull(compat.Verify(path));
var newPath = Path.Combine(dir, "VeloWpfSample-asd2.exe");
File.Move(path, newPath);
Assert.NotNull(compat.Verify(newPath));
}
}