Rename to Velopack

This commit is contained in:
Caelan Sayler
2023-12-31 10:59:34 +00:00
parent 1ad0b01eda
commit eff71d9b3f
255 changed files with 190 additions and 2292 deletions

View File

@@ -0,0 +1,27 @@
using Squirrel.Csq.Commands;
namespace Squirrel.CommandLine.Tests;
public abstract class BaseCommandTests<T> : TempFileTestBase
where T : BaseCommand, new()
{
public virtual bool ShouldBeNonEmptyReleaseDir => false;
//[Fact]
//public void ReleaseDirectory_WithDirectory_ParsesValue()
//{
// var releaseDirectory = CreateTempDirectory();
// if (ShouldBeNonEmptyReleaseDir)
// CreateTempFile(releaseDirectory, "anything");
// BaseCommand command = new T();
// var cli = GetRequiredDefaultOptions() + $"--outputDir \"{releaseDirectory.FullName}\"";
// var parseResult = command.ParseAndApply(cli);
// Assert.Equal(releaseDirectory.FullName, command.ReleaseDirectory);
//}
protected virtual string GetRequiredDefaultOptions() => "";
}

View File

@@ -0,0 +1,100 @@
using System.CommandLine;
using Squirrel.Csq.Commands;
namespace Squirrel.CommandLine.Tests.Commands;
public abstract class GitHubCommandTests<T> : BaseCommandTests<T>
where T : GitHubBaseCommand, new()
{
[Fact]
public void RepoUrl_WithUrl_ParsesValue()
{
GitHubBaseCommand command = new T();
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"http://clowd.squirrel.com\"");
Assert.Empty(parseResult.Errors);
Assert.Equal("http://clowd.squirrel.com/", command.RepoUrl);
}
[Fact]
public void RepoUrl_WithNonHttpValue_ShowsError()
{
GitHubBaseCommand command = new T();
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"file://clowd.squirrel.com\"");
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--repoUrl must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
}
[Fact]
public void RepoUrl_WithRelativeUrl_ShowsError()
{
GitHubBaseCommand command = new T();
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"clowd.squirrel.com\"");
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--repoUrl must contain an absolute Uri.", parseResult.Errors[0].Message);
}
[Fact]
public void Token_WithValue_ParsesValue()
{
GitHubBaseCommand command = new T();
string cli = GetRequiredDefaultOptions() + $"--token \"abc\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal("abc", command.Token);
}
protected override string GetRequiredDefaultOptions()
{
return $"--repoUrl \"https://clowd.squirrel.com\" ";
}
}
public class GitHubDownloadCommandTests : GitHubCommandTests<GitHubDownloadCommand>
{
[Fact]
public void Pre_BareOption_SetsFlag()
{
var command = new GitHubDownloadCommand();
string cli = GetRequiredDefaultOptions() + "--pre";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.True(command.Pre);
}
}
public class GitHubUploadCommandTests : GitHubCommandTests<GitHubUploadCommand>
{
public override bool ShouldBeNonEmptyReleaseDir => true;
[Fact]
public void Publish_BareOption_SetsFlag()
{
var command = new GitHubUploadCommand();
string cli = GetRequiredDefaultOptions() + "--publish";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.True(command.Publish);
}
[Fact]
public void ReleaseName_WithName_ParsesValue()
{
var command = new GitHubUploadCommand();
string cli = GetRequiredDefaultOptions() + $"--releaseName \"my release\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal("my release", command.ReleaseName);
}
}

View File

@@ -0,0 +1,48 @@

using System.CommandLine;
using Squirrel.Csq.Commands;
namespace Squirrel.CommandLine.Tests.Commands;
public class HttpDownloadCommandTests : BaseCommandTests<HttpDownloadCommand>
{
[Fact]
public void Url_WithUrl_ParsesValue()
{
var command = new HttpDownloadCommand();
ParseResult parseResult = command.ParseAndApply($"--url \"http://clowd.squirrel.com\"");
Assert.Empty(parseResult.Errors);
Assert.Equal("http://clowd.squirrel.com/", command.Url);
}
[Fact]
public void Url_WithNonHttpValue_ShowsError()
{
var command = new HttpDownloadCommand();
ParseResult parseResult = command.ParseAndApply($"--url \"file://clowd.squirrel.com\"");
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--url must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
}
[Fact]
public void Url_WithRelativeUrl_ShowsError()
{
var command = new HttpDownloadCommand();
ParseResult parseResult = command.ParseAndApply($"--url \"clowd.squirrel.com\"");
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--url must contain an absolute Uri.", parseResult.Errors[0].Message);
}
protected override string GetRequiredDefaultOptions()
{
return $"--url \"https://clowd.squirrel.com\" ";
}
}

View File

@@ -0,0 +1,324 @@
//using System.CommandLine;
//using System.CommandLine.Parsing;
//using Xunit;
//namespace Squirrel.CommandLine.Tests.Commands
//{
// public class PackCommandTests : BaseCommandTests<PackOsxCommand>
// {
// [Fact]
// public void Command_WithValidRequiredArguments_Parses()
// {
// DirectoryInfo packDir = CreateTempDirectory();
// CreateTempFile(packDir);
// var command = new PackCommand();
// ParseResult parseResult = command.Parse($"--packId Clowd.Squirrel -v 1.2.3 -p \"{packDir.FullName}\"");
// Assert.Empty(parseResult.Errors);
// Assert.Equal("Clowd.Squirrel", command.PackId);
// Assert.Equal("1.2.3", command.PackVersion);
// Assert.Equal(packDir.FullName, command.PackDirectory?.FullName);
// }
// [Fact]
// public void PackId_WithInvalidNuGetId_ShowsError()
// {
// DirectoryInfo packDir = CreateTempDirectory();
// CreateTempFile(packDir);
// var command = new PackCommand();
// ParseResult parseResult = command.Parse($"--packId $42@ -v 1.0.0 -p \"{packDir.FullName}\"");
// Assert.Equal(1, parseResult.Errors.Count);
// Assert.StartsWith("--packId is an invalid NuGet package id.", parseResult.Errors[0].Message);
// Assert.Contains("$42@", parseResult.Errors[0].Message);
// }
// [Fact]
// public void PackVersion_WithInvalidVersion_ShowsError()
// {
// DirectoryInfo packDir = CreateTempDirectory();
// CreateTempFile(packDir);
// var command = new PackCommand();
// ParseResult parseResult = command.Parse($"-u Clowd.Squirrel --packVersion 1.a.c -p \"{packDir.FullName}\"");
// Assert.Equal(1, parseResult.Errors.Count);
// Assert.StartsWith("--packVersion contains an invalid package version", parseResult.Errors[0].Message);
// Assert.Contains("1.a.c", parseResult.Errors[0].Message);
// }
// [Fact]
// public void PackDirectory_WithEmptyFolder_ShowsError()
// {
// DirectoryInfo packDir = CreateTempDirectory();
// var command = new PackCommand();
// ParseResult parseResult = command.Parse($"-u Clowd.Squirrel -v 1.0.0 --packDir \"{packDir.FullName}\"");
// Assert.Equal(1, parseResult.Errors.Count);
// Assert.StartsWith("--packDir must a non-empty directory", parseResult.Errors[0].Message);
// Assert.Contains(packDir.FullName, parseResult.Errors[0].Message);
// }
// [Fact]
// public void PackAuthors_WithMultipleAuthors_ParsesValue()
// {
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + "--packAuthors Me,mysel,I";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal("Me,mysel,I", command.PackAuthors);
// }
// [Fact]
// public void PackTitle_WithTitle_ParsesValue()
// {
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + "--packTitle \"My Awesome Title\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal("My Awesome Title", command.PackTitle);
// }
// [Fact]
// public void IncludePdb_BareOption_SetsFlag()
// {
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + "--includePdb";
// ParseResult parseResult = command.Parse(cli);
// Assert.True(command.IncludePdb);
// }
// [Fact]
// public void ReleaseNotes_WithExistingFile_ParsesValue()
// {
// FileInfo releaseNotes = CreateTempFile();
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--releaseNotes \"{releaseNotes.FullName}\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal(releaseNotes.FullName, command.ReleaseNotes?.FullName);
// }
// [Fact]
// public void ReleaseNotes_WithoutFile_ShowsError()
// {
// string releaseNotes = Path.GetFullPath(Path.GetRandomFileName());
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--releaseNotes \"{releaseNotes}\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal(1, parseResult.Errors.Count);
// Assert.Equal(command.ReleaseNotes, parseResult.Errors[0].SymbolResult?.Symbol.Parents.Single());
// Assert.Contains(releaseNotes, parseResult.Errors[0].Message);
// }
// [Fact]
// public void SquirrelAwareExecutable_WithFileName_ParsesValue()
// {
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--mainExe \"MyApp.exe\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal("MyApp.exe", command.SquirrelAwareExecutable);
// }
// [Fact]
// public void Icon_WithValidFile_ParsesValue()
// {
// FileInfo fileInfo = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".ico"));
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--icon \"{fileInfo.FullName}\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal(fileInfo.FullName, command.Icon?.FullName);
// }
// [Fact]
// public void Icon_WithBadFileExtension_ShowsError()
// {
// FileInfo fileInfo = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".wrong"));
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--icon \"{fileInfo.FullName}\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal(1, parseResult.Errors.Count);
// Assert.Equal($"--icon does not have an .ico extension", parseResult.Errors[0].Message);
// }
// [Fact]
// public void Icon_WithoutFile_ShowsError()
// {
// string file = Path.GetFullPath(Path.ChangeExtension(Path.GetRandomFileName(), ".ico"));
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--icon \"{file}\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal(1, parseResult.Errors.Count);
// Assert.Equal(command.Icon, parseResult.Errors[0].SymbolResult?.Symbol.Parents.Single());
// Assert.Contains(file, parseResult.Errors[0].Message);
// }
// [Fact]
// public void BundleId_WithValue_ParsesValue()
// {
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--bundleId \"some id\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal("some id", command.BundleId);
// }
// [Fact]
// public void NoDelta_BareOption_SetsFlag()
// {
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + "--noDelta";
// ParseResult parseResult = command.Parse(cli);
// Assert.True(command.NoDelta);
// }
// [Fact]
// public void NoPackage_BareOption_SetsFlag()
// {
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + "--noPkg";
// ParseResult parseResult = command.Parse(cli);
// Assert.True(command.NoPackage);
// }
// [Fact]
// public void PackageContent_CanSpecifyMultipleValues()
// {
// DirectoryInfo packDir = CreateTempDirectory();
// FileInfo testFile1 = CreateTempFile(packDir);
// FileInfo testFile2 = CreateTempFile(packDir);
// PackCommand command = new PackCommand();
// string cli = $"-u clowd.squirrel -v 1.0.0 -p \"{packDir.FullName}\"";
// cli += $" --pkgContent welcome={testFile1.FullName}";
// cli += $" --pkgContent license={testFile2.FullName}";
// ParseResult parseResult = command.Parse(cli);
// Assert.Empty(parseResult.Errors);
// var packageContent = command.PackageContent;
// Assert.Equal(2, packageContent?.Length);
// Assert.Equal("welcome", packageContent![0].Key);
// Assert.Equal(testFile1.FullName, packageContent![0].Value.FullName);
// Assert.Equal("license", packageContent![1].Key);
// Assert.Equal(testFile2.FullName, packageContent![1].Value.FullName);
// }
// [Fact]
// public void PackageContent_WihtInvalidKey_DisplaysError()
// {
// DirectoryInfo packDir = CreateTempDirectory();
// FileInfo testFile1 = CreateTempFile(packDir);
// PackCommand command = new PackCommand();
// string cli = $"-u clowd.squirrel -v 1.0.0 -p \"{packDir.FullName}\"";
// cli += $" --pkgContent unknown={testFile1.FullName}";
// ParseResult parseResult = command.Parse(cli);
// ParseError error = parseResult.Errors.Single();
// Assert.Equal("Invalid pkgContent key: unknown. Must be one of: welcome, readme, license, conclusion", error.Message);
// }
// [Fact]
// public void SigningAppIdentity_WithSubject_ParsesValue()
// {
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--signAppIdentity \"Mac Developer\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal("Mac Developer", command.SigningAppIdentity);
// }
// [Fact]
// public void SigningInstallIdentity_WithSubject_ParsesValue()
// {
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--signInstallIdentity \"Mac Developer\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal("Mac Developer", command.SigningInstallIdentity);
// }
// [Fact]
// public void SigningEntitlements_WithValidFile_ParsesValue()
// {
// FileInfo fileInfo = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".entitlements"));
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--signEntitlements \"{fileInfo.FullName}\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal(fileInfo.FullName, command.SigningEntitlements?.FullName);
// }
// [Fact]
// public void SigningEntitlements_WithBadFileExtension_ShowsError()
// {
// FileInfo fileInfo = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".wrong"));
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--signEntitlements \"{fileInfo.FullName}\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal(1, parseResult.Errors.Count);
// Assert.Equal($"--signEntitlements does not have an .entitlements extension", parseResult.Errors[0].Message);
// }
// [Fact]
// public void SigningEntitlements_WithoutFile_ShowsError()
// {
// string file = Path.GetFullPath(Path.ChangeExtension(Path.GetRandomFileName(), ".entitlements"));
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--signEntitlements \"{file}\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal(1, parseResult.Errors.Count);
// Assert.Equal(command.SigningEntitlements, parseResult.Errors[0].SymbolResult?.Symbol.Parents.Single());
// Assert.Contains(file, parseResult.Errors[0].Message);
// }
// [Fact]
// public void NotaryProfile_WithName_ParsesValue()
// {
// var command = new PackCommand();
// string cli = GetRequiredDefaultOptions() + $"--notaryProfile \"profile name\"";
// ParseResult parseResult = command.Parse(cli);
// Assert.Equal("profile name", command.NotaryProfile);
// }
// protected override string GetRequiredDefaultOptions()
// {
// DirectoryInfo packDir = CreateTempDirectory();
// CreateTempFile(packDir);
// return $"-u Clowd.Squirrel -v 1.0.0 -p \"{packDir.FullName}\" ";
// }
// }
//}

View File

@@ -0,0 +1,121 @@
using System.CommandLine;
using Squirrel.Csq.Commands;
namespace Squirrel.CommandLine.Tests.Commands;
public abstract class S3CommandTests<T> : BaseCommandTests<T>
where T : S3BaseCommand, new()
{
[Fact]
public void Command_WithRequiredEndpointOptions_ParsesValue()
{
S3BaseCommand command = new T();
string cli = $"--keyId \"some key\" --secret \"shhhh\" --endpoint \"http://endpoint\" --bucket \"a-bucket\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Empty(parseResult.Errors);
Assert.Equal("some key", command.KeyId);
Assert.Equal("shhhh", command.Secret);
Assert.Equal("http://endpoint/", command.Endpoint);
Assert.Equal("a-bucket", command.Bucket);
}
[Fact]
public void Command_WithRequiredRegionOptions_ParsesValue()
{
S3BaseCommand command = new T();
string cli = $"--keyId \"some key\" --secret \"shhhh\" --region \"us-west-1\" --bucket \"a-bucket\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Empty(parseResult.Errors);
Assert.Equal("some key", command.KeyId);
Assert.Equal("shhhh", command.Secret);
Assert.Equal("us-west-1", command.Region);
Assert.Equal("a-bucket", command.Bucket);
}
[Fact]
public void Command_WithoutRegionArgumentValue_ShowsError()
{
S3BaseCommand command = new T();
string cli = $"--keyId \"some key\" --secret \"shhhh\" --bucket \"a-bucket\" --region \"\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Region, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("A region value is required", parseResult.Errors[0].Message);
}
[Fact]
public void Command_WithoutRegionAndEndpoint_ShowsError()
{
S3BaseCommand command = new T();
string cli = $"--keyId \"some key\" --secret \"shhhh\" --bucket \"a-bucket\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
Assert.StartsWith("At least one of the following options are required '--region' and '--endpoint'", parseResult.Errors[0].Message);
}
[Fact]
public void Command_WithBothRegionAndEndpoint_ShowsError()
{
S3BaseCommand command = new T();
string cli = $"--keyId \"some key\" --secret \"shhhh\" --region \"us-west-1\" --endpoint \"http://endpoint\" --bucket \"a-bucket\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
Assert.StartsWith("Cannot use '--region' and '--endpoint' options together", parseResult.Errors[0].Message);
}
[Fact]
public void PathPrefix_WithPath_ParsesValue()
{
S3BaseCommand command = new T();
string cli = GetRequiredDefaultOptions() + $"--pathPrefix \"sub-folder\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal("sub-folder", command.PathPrefix);
}
protected override string GetRequiredDefaultOptions()
{
return $"--keyId \"some key\" --secret \"shhhh\" --endpoint \"http://endpoint\" --bucket \"a-bucket\" ";
}
}
public class S3DownloadCommandTests : S3CommandTests<S3DownloadCommand>
{ }
public class S3UploadCommandTests : S3CommandTests<S3UploadCommand>
{
public override bool ShouldBeNonEmptyReleaseDir => true;
[Fact]
public void Overwrite_BareOption_SetsFlag()
{
var command = new S3UploadCommand();
string cli = GetRequiredDefaultOptions() + "--overwrite";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.True(command.Overwrite);
}
[Fact]
public void KeepMaxReleases_WithNumber_ParsesValue()
{
var command = new S3UploadCommand();
string cli = GetRequiredDefaultOptions() + "--keepMaxReleases 42";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(42, command.KeepMaxReleases);
}
}

View File

@@ -0,0 +1,507 @@

using System.CommandLine;
using Squirrel.Csq.Commands;
namespace Squirrel.CommandLine.Tests.Commands;
public abstract class ReleaseCommandTests<T> : BaseCommandTests<T>
where T : WindowsReleasifyCommand, new()
{
//[Fact]
//public void BaseUrl_WithNonHttpValue_ShowsError()
//{
// var command = new T();
// string cli = GetRequiredDefaultOptions() + $"--baseUrl \"file://clowd.squirrel.com\"";
// ParseResult parseResult = command.ParseAndApply(cli);
// Assert.Equal(1, parseResult.Errors.Count);
// //Assert.Equal(command.BaseUrl, parseResult.Errors[0].SymbolResult?.Symbol);
// Assert.StartsWith("--baseUrl must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
//}
//[Fact]
//public void BaseUrl_WithRelativeUrl_ShowsError()
//{
// var command = new T();
// string cli = GetRequiredDefaultOptions() + $"--baseUrl \"clowd.squirrel.com\"";
// ParseResult parseResult = command.ParseAndApply(cli);
// Assert.Equal(1, parseResult.Errors.Count);
// //Assert.Equal(command.BaseUrl, parseResult.Errors[0].SymbolResult?.Symbol);
// Assert.StartsWith("--baseUrl must contain an absolute Uri.", parseResult.Errors[0].Message);
//}
[Fact]
public void NoDelta_BareOption_SetsFlag()
{
var command = new T();
string cli = GetRequiredDefaultOptions() + "--delta none";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.True(command.Delta == Packaging.DeltaMode.None);
}
[Fact]
public void Runtime_WithValue_ParsesValue()
{
var command = new T();
string cli = GetRequiredDefaultOptions() + $"--framework \"net6,vcredist143\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal("net6,vcredist143", command.Runtimes);
}
[Fact]
public void SplashImage_WithValidFile_ParsesValue()
{
FileInfo fileInfo = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".ico"));
var command = new T();
string cli = GetRequiredDefaultOptions() + $"--splashImage \"{fileInfo.FullName}\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(fileInfo.FullName, command.SplashImage);
}
[Fact]
public void SplashImage_WithoutFile_ShowsError()
{
string file = Path.GetFullPath(Path.ChangeExtension(Path.GetRandomFileName(), ".ico"));
var command = new T();
string cli = GetRequiredDefaultOptions() + $"--splashImage \"{file}\"";
ParseResult parseResult = command.ParseAndApply(cli);
//Assert.Equal(1, parseResult.Errors.Count);
Assert.Contains("file is not found", parseResult.Errors[0].Message);
//Assert.Equal(command.SplashImage, parseResult.Errors[0].SymbolResult?.Symbol.Parents.Single());
//Assert.Contains(file, parseResult.Errors[0].Message);
}
[Fact]
public void Icon_WithValidFile_ParsesValue()
{
FileInfo fileInfo = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".ico"));
var command = new T();
string cli = GetRequiredDefaultOptions() + $"--icon \"{fileInfo.FullName}\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(fileInfo.FullName, command.Icon);
}
[Fact]
public void Icon_WithBadFileExtension_ShowsError()
{
FileInfo fileInfo = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".wrong"));
var command = new T();
string cli = GetRequiredDefaultOptions() + $"--icon \"{fileInfo.FullName}\"";
ParseResult parseResult = command.ParseAndApply(cli);
//Assert.Equal(1, parseResult.Errors.Count);
Assert.Contains(parseResult.Errors, e => e.Message.Equals($"--icon does not have an .ico extension"));
//Assert.Equal($"--icon does not have an .ico extension", parseResult.Errors[0].Message);
}
[Fact]
public void Icon_WithoutFile_ShowsError()
{
string file = Path.GetFullPath(Path.ChangeExtension(Path.GetRandomFileName(), ".ico"));
var command = new T();
string cli = GetRequiredDefaultOptions() + $"--icon \"{file}\"";
ParseResult parseResult = command.ParseAndApply(cli);
//Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Icon, parseResult.Errors[0].SymbolResult?.Symbol.Parents.Single());
Assert.Contains("file is not found", parseResult.Errors[0].Message);
}
//[Fact]
//public void SquirrelAwareExecutable_WithMultipleValues_ParsesValue()
//{
// var command = new T();
// string cli = GetRequiredDefaultOptions() + $"--mainExe \"MyApp1.exe\"";
// ParseResult parseResult = command.ParseAndApply(cli);
// string searchPaths = command.EntryExecutableName;
// Assert.Equal("MyApp1.exe", searchPaths);
//}
}
public class ReleasifyWindowsCommandTests : ReleaseCommandTests<WindowsReleasifyCommand>
{
[Fact]
public void Command_WithValidRequiredArguments_Parses()
{
FileInfo package = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".nupkg"));
var command = new WindowsReleasifyCommand();
ParseResult parseResult = command.ParseAndApply($"--package \"{package.FullName}\" -e main.exe");
Assert.Empty(parseResult.Errors);
Assert.Equal(package.FullName, command.Package);
}
[Fact]
public void Package_WithoutNupkgExtension_ShowsError()
{
FileInfo package = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".notpkg"));
var command = new WindowsReleasifyCommand();
ParseResult parseResult = command.ParseAndApply($"--package \"{package.FullName}\" -e main.exe");
//Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Package, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--package does not have an .nupkg extension", parseResult.Errors[0].Message);
}
[Fact]
public void Package_WithoutExistingFile_ShowsError()
{
string package = Path.ChangeExtension(Path.GetRandomFileName(), ".nupkg");
var command = new WindowsReleasifyCommand();
ParseResult parseResult = command.ParseAndApply($"--package \"{package}\" -e main.exe");
//Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Package, parseResult.Errors[0].SymbolResult?.Symbol.Parents.Single());
Assert.Contains("file is not found", parseResult.Errors[0].Message);
}
[Fact]
public void SignTemplate_WithTemplate_ParsesValue()
{
var command = new WindowsReleasifyCommand();
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool {{file}}\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal("signtool {{file}}", command.SignTemplate);
}
[Fact]
public void SignTemplate_WithoutFileParameter_ShowsError()
{
var command = new WindowsReleasifyCommand();
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool file\"";
ParseResult parseResult = command.ParseAndApply(cli);
//Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.SignTemplate, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--signTemplate must contain '{{file}}'", parseResult.Errors[0].Message);
}
[WindowsOnlyFact]
public void SignParameters_WithParameters_ParsesValue()
{
var command = new WindowsReleasifyCommand();
string cli = GetRequiredDefaultOptions() + "--signParams \"param1 param2\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal("param1 param2", command.SignParameters);
}
[WindowsOnlyFact]
public void SignParameters_WithSignTemplate_ShowsError()
{
var command = new WindowsReleasifyCommand();
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool {{file}}\" --signParams \"param1 param2\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
Assert.Contains("Cannot use", parseResult.Errors[0].Message);
Assert.Contains("options together", parseResult.Errors[0].Message);
}
[WindowsOnlyFact]
public void SignSkipDll_BareOption_SetsFlag()
{
var command = new WindowsReleasifyCommand();
string cli = GetRequiredDefaultOptions() + "--signSkipDll";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.True(command.SignSkipDll);
}
[WindowsOnlyFact]
public void SignParallel_WithValue_SetsFlag()
{
var command = new WindowsReleasifyCommand();
string cli = GetRequiredDefaultOptions() + "--signParallel 42";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(42, command.SignParallel);
}
//[WindowsOnlyTheory]
//[InlineData(-1)]
//[InlineData(0)]
//[InlineData(1001)]
//public void SignParallel_WithBadNumericValue_ShowsError(int value)
//{
// var command = new WindowsReleasifyCommand();
// string cli = GetRequiredDefaultOptions() + $"--signParallel {value}";
// ParseResult parseResult = command.ParseAndApply(cli);
// Assert.Equal(1, parseResult.Errors.Count);
// //Assert.Equal(command.SignParallel, parseResult.Errors[0].SymbolResult?.Symbol);
// Assert.Equal($"The value for --signParallel must be greater than 1 and less than 1000", parseResult.Errors[0].Message);
//}
//[WindowsOnlyFact]
//public void SignParallel_WithNonNumericValue_ShowsError()
//{
// var command = new WindowsReleasifyCommand();
// string cli = GetRequiredDefaultOptions() + $"--signParallel abc";
// ParseResult parseResult = command.ParseAndApply(cli);
// Assert.Equal(1, parseResult.Errors.Count);
// //Assert.Equal(command.SignParallel, parseResult.Errors[0].SymbolResult?.Symbol);
// Assert.Equal($"abc is not a valid integer for --signParallel", parseResult.Errors[0].Message);
//}
protected override string GetRequiredDefaultOptions()
{
FileInfo package = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".nupkg"));
return $"-p \"{package.FullName}\" -e main.exe ";
}
}
public class PackWindowsCommandTests : ReleaseCommandTests<WindowsPackCommand>
{
[Fact]
public void Command_WithValidRequiredArguments_Parses()
{
DirectoryInfo packDir = CreateTempDirectory();
CreateTempFile(packDir);
var command = new WindowsPackCommand();
ParseResult parseResult = command.ParseAndApply($"-u Clowd.Squirrel -v 1.2.3 -p \"{packDir.FullName}\" -e main.exe");
Assert.Empty(parseResult.Errors);
Assert.Equal("Clowd.Squirrel", command.PackId);
Assert.Equal("1.2.3", command.PackVersion);
Assert.Equal(packDir.FullName, command.PackDirectory);
}
[Fact]
public void PackId_WithInvalidNuGetId_ShowsError()
{
DirectoryInfo packDir = CreateTempDirectory();
CreateTempFile(packDir);
var command = new WindowsPackCommand();
ParseResult parseResult = command.ParseAndApply($"--packId $42@ -v 1.0.0 -p \"{packDir.FullName}\" -e main.exe");
Assert.Equal(1, parseResult.Errors.Count);
Assert.StartsWith("--packId is an invalid NuGet package id.", parseResult.Errors[0].Message);
Assert.Contains("$42@", parseResult.Errors[0].Message);
}
[Fact]
public void PackName_WithValue_ParsesValue()
{
DirectoryInfo packDir = CreateTempDirectory();
CreateTempFile(packDir);
var command = new WindowsPackCommand();
ParseResult parseResult = command.ParseAndApply($"-u Clowd.Squirrel --packTitle Clowd.Squirrel -v 1.0.0 -p \"{packDir.FullName}\" -e main.exe");
Assert.Equal("Clowd.Squirrel", command.PackTitle);
}
[Fact]
public void PackVersion_WithInvalidVersion_ShowsError()
{
DirectoryInfo packDir = CreateTempDirectory();
CreateTempFile(packDir);
var command = new WindowsPackCommand();
ParseResult parseResult = command.ParseAndApply($"-u Clowd.Squirrel --packVersion 1.a.c -p \"{packDir.FullName}\" -e main.exe");
Assert.Equal(1, parseResult.Errors.Count);
Assert.StartsWith("--packVersion contains an invalid package version", parseResult.Errors[0].Message);
Assert.Contains("1.a.c", parseResult.Errors[0].Message);
}
[Fact]
public void PackTitle_WithTitle_ParsesValue()
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + "--packTitle \"My Awesome Title\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal("My Awesome Title", command.PackTitle);
}
[Fact]
public void PackAuthors_WithMultipleAuthors_ParsesValue()
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + "--packAuthors Me,mysel,I";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal("Me,mysel,I", command.PackAuthors);
}
[Fact]
public void IncludePdb_BareOption_SetsFlag()
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + "--includePdb";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.True(command.IncludePdb);
}
[Fact]
public void ReleaseNotes_WithExistingFile_ParsesValue()
{
FileInfo releaseNotes = CreateTempFile();
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + $"--releaseNotes \"{releaseNotes.FullName}\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(releaseNotes.FullName, command.ReleaseNotes);
}
[Fact]
public void ReleaseNotes_WithoutFile_ShowsError()
{
string releaseNotes = Path.GetFullPath(Path.GetRandomFileName());
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + $"--releaseNotes \"{releaseNotes}\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
Assert.Contains("file is not found", parseResult.Errors[0].Message);
//Assert.Equal(command.ReleaseNotes, parseResult.Errors[0].SymbolResult?.Symbol.Parents.Single());
//Assert.Contains(releaseNotes, parseResult.Errors[0].Message);
}
[Fact]
public void SignTemplate_WithTemplate_ParsesValue()
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool {{file}}\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal("signtool {{file}}", command.SignTemplate);
}
[Fact]
public void SignTemplate_WithoutFileParameter_ShowsError()
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool file\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.SignTemplate, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.StartsWith("--signTemplate must contain '{{file}}'", parseResult.Errors[0].Message);
}
[WindowsOnlyFact]
public void SignParameters_WithParameters_ParsesValue()
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + "--signParams \"param1 param2\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal("param1 param2", command.SignParameters);
}
[WindowsOnlyFact]
public void SignParameters_WithSignTemplate_ShowsError()
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + "--signTemplate \"signtool {{file}}\" --signParams \"param1 param2\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
Assert.Contains("Cannot use", parseResult.Errors[0].Message);
Assert.Contains("options together", parseResult.Errors[0].Message);
}
[WindowsOnlyFact]
public void SignSkipDll_BareOption_SetsFlag()
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + "--signSkipDll";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.True(command.SignSkipDll);
}
[WindowsOnlyFact]
public void SignParallel_WithValue_SetsFlag()
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + "--signParallel 42";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(42, command.SignParallel);
}
[WindowsOnlyTheory]
[InlineData(-1)]
[InlineData(0)]
[InlineData(1001)]
public void SignParallel_WithBadNumericValue_ShowsError(int value)
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + $"--signParallel {value}";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.SignParallel, parseResult.Errors[0].SymbolResult?.Symbol);
Assert.Equal($"The value for --signParallel must be greater than 1 and less than 1000", parseResult.Errors[0].Message);
}
//[WindowsOnlyFact]
//public void SignParallel_WithNonNumericValue_ShowsError()
//{
// var command = new WindowsPackCommand();
// string cli = GetRequiredDefaultOptions() + $"--signParallel abc";
// ParseResult parseResult = command.ParseAndApply(cli);
// Assert.Equal(1, parseResult.Errors.Count);
// //Assert.Equal(command.SignParallel, parseResult.Errors[0].SymbolResult?.Symbol);
// Assert.Equal($"abc is not a valid integer for --signParallel", parseResult.Errors[0].Message);
//}
protected override string GetRequiredDefaultOptions()
{
DirectoryInfo packDir = CreateTempDirectory();
CreateTempFile(packDir);
return $"-u Clowd.Squirrel -v 1.0.0 -p \"{packDir.FullName}\" -e main.exe ";
}
}

View File

@@ -0,0 +1,99 @@
using System.Threading;
using Xunit.Sdk;
namespace Squirrel.CommandLine.Tests;
public abstract class TempFileTestBase : IDisposable
{
private readonly Lazy<DirectoryInfo> _WorkingDirectory = new(() => {
DirectoryInfo working = new(
Path.Combine(Path.GetTempPath(),
typeof(TempFileTestBase).Assembly.GetName().Name!,
Path.GetRandomFileName()));
if (working.Exists) {
working.Delete(recursive: true);
}
working.Create();
return working;
}, LazyThreadSafetyMode.ExecutionAndPublication);
private readonly List<FileInfo> _TempFiles = new();
private readonly List<DirectoryInfo> _TempDirectories = new();
protected DirectoryInfo TempDirectory => _WorkingDirectory.Value;
private bool _Disposed;
public FileInfo CreateTempFile(DirectoryInfo? directory = null, string? name = null)
{
var tempFile = new FileInfo(GetPath(directory, name));
tempFile.Create().Close();
_TempFiles.Add(tempFile);
return tempFile;
}
public DirectoryInfo CreateTempDirectory(DirectoryInfo? parent = null, string? name = null)
{
var tempDir = new DirectoryInfo(GetPath(parent, name));
tempDir.Create();
_TempDirectories.Add(tempDir);
return tempDir;
}
private string GetPath(DirectoryInfo? parentDirectory, string? name)
{
var directory = parentDirectory ?? _WorkingDirectory.Value;
var fileName = name ?? Path.GetRandomFileName();
return Path.Combine(directory.FullName, fileName);
}
protected virtual void Dispose(bool disposing)
{
if (_Disposed || !disposing) {
return;
}
_Disposed = true;
ExceptionAggregator aggregator = new();
var items = _TempFiles
.Cast<FileSystemInfo>()
.Concat(_TempDirectories)
.Concat(_WorkingDirectory.IsValueCreated ? new[] { _WorkingDirectory.Value } : Enumerable.Empty<DirectoryInfo>());
foreach (var fsi in items) {
fsi.Refresh();
if (!fsi.Exists) return;
Action? action = fsi switch {
FileInfo file => () => file.Delete(),
DirectoryInfo dir => () => dir.Delete(recursive: true),
_ => null,
};
if (action is null) return;
aggregator.Run(() => {
for (int i = 0; i < 100; i++) {
try {
action();
break;
} catch {
Thread.Sleep(TimeSpan.FromMilliseconds(10));
}
}
});
}
if (aggregator.HasExceptions) {
throw aggregator.ToException();
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Velopack.Vpk\Velopack.Vpk.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,13 @@
using System.Runtime.InteropServices;
namespace Squirrel.CommandLine.Tests;
public class WindowsOnlyFactAttribute : FactAttribute
{
public WindowsOnlyFactAttribute()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
Skip = "Only run on Windows";
}
}
}

View File

@@ -0,0 +1,13 @@
using System.Runtime.InteropServices;
namespace Squirrel.CommandLine.Tests;
public class WindowsOnlyTheoryAttribute : TheoryAttribute
{
public WindowsOnlyTheoryAttribute()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
Skip = "Only run on Windows";
}
}
}