mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Add tests for VelopackApp verifier
This commit is contained in:
@@ -38,7 +38,7 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
|
|||||||
"Please publish your application to a folder without ClickOnce.");
|
"Please publish your application to a folder without ClickOnce.");
|
||||||
}
|
}
|
||||||
|
|
||||||
DotnetUtil.VerifyVelopackAppBuilder(MainExePath, Log);
|
DotnetUtil.VerifyVelopackApp(MainExePath, Log);
|
||||||
|
|
||||||
// copy files to temp dir, so we can modify them
|
// copy files to temp dir, so we can modify them
|
||||||
var dir = TempDir.CreateSubdirectory("PreprocessPackDirWin");
|
var dir = TempDir.CreateSubdirectory("PreprocessPackDirWin");
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System.Diagnostics;
|
using AsmResolver.DotNet;
|
||||||
using System.IO;
|
|
||||||
using AsmResolver.DotNet;
|
|
||||||
using AsmResolver.DotNet.Bundles;
|
using AsmResolver.DotNet.Bundles;
|
||||||
using AsmResolver.DotNet.Serialized;
|
using AsmResolver.DotNet.Serialized;
|
||||||
using AsmResolver.PE;
|
using AsmResolver.PE;
|
||||||
@@ -14,7 +12,7 @@ namespace Velopack.Packaging.Windows
|
|||||||
{
|
{
|
||||||
public class DotnetUtil
|
public class DotnetUtil
|
||||||
{
|
{
|
||||||
public static void VerifyVelopackAppBuilder(string exeFile, ILogger log)
|
public static NuGetVersion VerifyVelopackApp(string exeFile, ILogger log)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
NuGetVersion velopackVersion = null;
|
NuGetVersion velopackVersion = null;
|
||||||
@@ -25,7 +23,7 @@ namespace Velopack.Packaging.Windows
|
|||||||
|
|
||||||
if (mainAssy == null) {
|
if (mainAssy == null) {
|
||||||
// not a dotnet binary
|
// not a dotnet binary
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (velopackDll != null) {
|
if (velopackDll != null) {
|
||||||
@@ -57,8 +55,10 @@ namespace Velopack.Packaging.Windows
|
|||||||
$"This may cause compatibility issues. Expected {VelopackRuntimeInfo.VelopackProductVersion}, " +
|
$"This may cause compatibility issues. Expected {VelopackRuntimeInfo.VelopackProductVersion}, " +
|
||||||
$"but found {velopackVersion}.");
|
$"but found {velopackVersion}.");
|
||||||
}
|
}
|
||||||
|
return velopackVersion;
|
||||||
} else {
|
} else {
|
||||||
log.Warn("VelopackApp verified at entry point, but ProductVersion could not be checked.");
|
log.Warn("VelopackApp verified at entry point, but ProductVersion could not be checked.");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,9 +68,12 @@ namespace Velopack.Packaging.Windows
|
|||||||
// if we've iterated the whole main method and not found the call, then the velopack builder is missing
|
// if we've iterated the whole main method and not found the call, then the velopack builder is missing
|
||||||
throw new UserInfoException($"Unable to verify VelopackApp, in application main method '{entryPoint.FullName}'. " +
|
throw new UserInfoException($"Unable to verify VelopackApp, in application main method '{entryPoint.FullName}'. " +
|
||||||
"Please ensure that 'VelopackApp.Build().Run()' is present in your Program.Main().");
|
"Please ensure that 'VelopackApp.Build().Run()' is present in your Program.Main().");
|
||||||
|
|
||||||
} catch (Exception ex) when (ex is not UserInfoException) {
|
} catch (Exception ex) when (ex is not UserInfoException) {
|
||||||
log.Error("Unable to verify VelopackApp: " + ex.Message);
|
log.Error("Unable to verify VelopackApp: " + ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AssemblyDefinition LoadFullFramework(string exeFile, ref IPEImage velopackDll)
|
private static AssemblyDefinition LoadFullFramework(string exeFile, ref IPEImage velopackDll)
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ public static class PathHelper
|
|||||||
public static string GetProjectDir()
|
public static string GetProjectDir()
|
||||||
=> Path.Combine(GetTestRoot(), "..");
|
=> Path.Combine(GetTestRoot(), "..");
|
||||||
|
|
||||||
|
public static string GetAvaloniaSample()
|
||||||
|
=> Path.Combine(GetProjectDir(), "examples", "AvaloniaCrossPlat");
|
||||||
|
|
||||||
|
public static string GetWpfSample()
|
||||||
|
=> Path.Combine(GetProjectDir(), "examples", "VeloWpfSample");
|
||||||
|
|
||||||
public static string GetVendorLibDir()
|
public static string GetVendorLibDir()
|
||||||
=> Path.Combine(GetProjectDir(), "vendor");
|
=> Path.Combine(GetProjectDir(), "vendor");
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ try {
|
|||||||
bool shouldExit = false;
|
bool shouldExit = false;
|
||||||
bool shouldAutoUpdate = args.Any(a => a.Equals("--autoupdate", StringComparison.OrdinalIgnoreCase));
|
bool shouldAutoUpdate = args.Any(a => a.Equals("--autoupdate", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
#if !NO_VELO_BUILDER
|
||||||
VelopackApp.Build()
|
VelopackApp.Build()
|
||||||
.SetAutoApplyOnStartup(shouldAutoUpdate)
|
.SetAutoApplyOnStartup(shouldAutoUpdate)
|
||||||
.WithFirstRun((v) => {
|
.WithFirstRun((v) => {
|
||||||
@@ -33,6 +34,7 @@ try {
|
|||||||
if (shouldExit) {
|
if (shouldExit) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (args.Length == 1 && args[0] == "version") {
|
if (args.Length == 1 && args[0] == "version") {
|
||||||
var locator = VelopackLocator.GetDefault(new ConsoleLogger());
|
var locator = VelopackLocator.GetDefault(new ConsoleLogger());
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition=" $(NoVelopackApp) != '' ">
|
||||||
|
<DefineConstants>NO_VELO_BUILDER</DefineConstants>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Velopack\Velopack.csproj" />
|
<ProjectReference Include="..\..\src\Velopack\Velopack.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
108
test/Velopack.Packaging.Tests/DotnetUtilTests.cs
Normal file
108
test/Velopack.Packaging.Tests/DotnetUtilTests.cs
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Velopack.Packaging.Exceptions;
|
||||||
|
using Velopack.Packaging.Windows;
|
||||||
|
using Velopack.Packaging.Windows.Commands;
|
||||||
|
|
||||||
|
namespace Velopack.Packaging.Tests
|
||||||
|
{
|
||||||
|
public class DotnetUtilTests
|
||||||
|
{
|
||||||
|
private readonly ITestOutputHelper _output;
|
||||||
|
|
||||||
|
public DotnetUtilTests(ITestOutputHelper output)
|
||||||
|
{
|
||||||
|
_output = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public void NonDotnetBinaryPasses()
|
||||||
|
{
|
||||||
|
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
|
||||||
|
using var logger = _output.BuildLoggerFor<DotnetUtilTests>();
|
||||||
|
Assert.Null(DotnetUtil.VerifyVelopackApp(PathHelper.GetRustAsset("testapp.exe"), logger));
|
||||||
|
}
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public void PublishSingleFilePasses()
|
||||||
|
{
|
||||||
|
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
|
||||||
|
using var logger = _output.BuildLoggerFor<DotnetUtilTests>();
|
||||||
|
using var _1 = Utility.GetTempDirectory(out var dir);
|
||||||
|
var sample = PathHelper.GetAvaloniaSample();
|
||||||
|
Exe.InvokeAndThrowIfNonZero(
|
||||||
|
"dotnet",
|
||||||
|
new string[] { "publish", "--no-self-contained", "-r", "win-x64", "-o", dir,
|
||||||
|
"-p:UseLocalVelopack=true", "-p:PublishSingleFile=true" },
|
||||||
|
sample);
|
||||||
|
|
||||||
|
var path = Path.Combine(dir, "AvaloniaCrossPlat.exe");
|
||||||
|
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, DotnetUtil.VerifyVelopackApp(path, logger));
|
||||||
|
|
||||||
|
var newPath = Path.Combine(dir, "AvaloniaCrossPlat-asd2.exe");
|
||||||
|
File.Move(path, newPath);
|
||||||
|
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, DotnetUtil.VerifyVelopackApp(newPath, logger));
|
||||||
|
}
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public void PublishDotnet6Passes()
|
||||||
|
{
|
||||||
|
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
|
||||||
|
using var logger = _output.BuildLoggerFor<DotnetUtilTests>();
|
||||||
|
using var _1 = Utility.GetTempDirectory(out var dir);
|
||||||
|
var sample = PathHelper.GetAvaloniaSample();
|
||||||
|
Exe.InvokeAndThrowIfNonZero(
|
||||||
|
"dotnet",
|
||||||
|
new string[] { "publish", "--no-self-contained", "-r", "win-x64", "-o", dir,
|
||||||
|
"-p:UseLocalVelopack=true" },
|
||||||
|
sample);
|
||||||
|
|
||||||
|
var path = Path.Combine(dir, "AvaloniaCrossPlat.exe");
|
||||||
|
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, DotnetUtil.VerifyVelopackApp(path, logger));
|
||||||
|
|
||||||
|
var newPath = Path.Combine(dir, "AvaloniaCrossPlat-asd2.exe");
|
||||||
|
File.Move(path, newPath);
|
||||||
|
Assert.Equal(VelopackRuntimeInfo.VelopackProductVersion, DotnetUtil.VerifyVelopackApp(newPath, logger));
|
||||||
|
}
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public void PublishNet48Passes()
|
||||||
|
{
|
||||||
|
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
|
||||||
|
using var logger = _output.BuildLoggerFor<DotnetUtilTests>();
|
||||||
|
using var _1 = Utility.GetTempDirectory(out var dir);
|
||||||
|
var sample = PathHelper.GetWpfSample();
|
||||||
|
Exe.InvokeAndThrowIfNonZero(
|
||||||
|
"dotnet",
|
||||||
|
new string[] { "publish", "-o", dir },
|
||||||
|
sample);
|
||||||
|
|
||||||
|
var path = Path.Combine(dir, "VeloWpfSample.exe");
|
||||||
|
Assert.NotNull(DotnetUtil.VerifyVelopackApp(path, logger));
|
||||||
|
|
||||||
|
var newPath = Path.Combine(dir, "VeloWpfSample-asd2.exe");
|
||||||
|
File.Move(path, newPath);
|
||||||
|
Assert.NotNull(DotnetUtil.VerifyVelopackApp(newPath, logger));
|
||||||
|
}
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public void UnawareDotnetAppFails()
|
||||||
|
{
|
||||||
|
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
|
||||||
|
using var logger = _output.BuildLoggerFor<DotnetUtilTests>();
|
||||||
|
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:NoVelopackApp=true" },
|
||||||
|
sample);
|
||||||
|
|
||||||
|
var path = Path.Combine(dir, "TestApp.exe");
|
||||||
|
Assert.Throws<UserInfoException>(() => DotnetUtil.VerifyVelopackApp(path, logger));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user