Fixing tests

This commit is contained in:
Caelan Sayler
2023-12-19 17:42:48 +00:00
parent a1d9734a93
commit 9fe57de8f9
7 changed files with 102 additions and 126 deletions

View File

@@ -9,7 +9,7 @@ public abstract class GitHubBaseCommand : BaseCommand
protected GitHubBaseCommand(string name, string description)
: base(name, description)
{
AddOption<Uri>((v) => RepoUrl = v.ToAbsoluteOrNull(), "--repoUrl")
var repoUrl = AddOption<Uri>((v) => RepoUrl = v.ToAbsoluteOrNull(), "--repoUrl")
.SetDescription("Full url to the github repository (eg. 'https://github.com/myname/myrepo').")
.SetRequired()
.MustBeValidHttpUri();

View File

@@ -56,6 +56,7 @@ internal static class SystemCommandLineExtensions
public static CliOption<Uri> MustBeValidHttpUri(this CliOption<Uri> option)
{
option.CustomParser = (v) => new Uri(v.Tokens.Single().Value, UriKind.RelativeOrAbsolute);
option.RequiresScheme(Uri.UriSchemeHttp, Uri.UriSchemeHttps).RequiresAbsolute();
return option;
}

View File

@@ -144,7 +144,7 @@ public class WindowsReleasifyCommandRunner
ReleaseEntry.WriteReleaseFile(releaseEntries, releaseFilePath);
var bundledzp = new ZipPackage(package);
var targetSetupExe = Path.Combine(targetDir, $"{bundledzp.Id}-Setup-[{options.TargetRuntime.ToDisplay(RidDisplayType.ShortVersion)}].exe");
var targetSetupExe = Path.Combine(targetDir, $"{bundledzp.Id}-Setup-[{options.TargetRuntime.ToDisplay(RidDisplayType.NoVersion)}].exe");
File.Copy(HelperExe.SetupPath, targetSetupExe, true);
if (SquirrelRuntimeInfo.IsWindows) {

View File

@@ -444,36 +444,36 @@ namespace Squirrel
// return Path.Combine(PackageDirectoryForAppDir(rootAppDirectory), "RELEASES");
//}
public static IEnumerable<ReleaseEntry> LoadLocalReleases(string localReleaseFile)
{
var file = File.OpenRead(localReleaseFile);
//public static IEnumerable<ReleaseEntry> LoadLocalReleases(string localReleaseFile)
//{
// var file = File.OpenRead(localReleaseFile);
// NB: sr disposes file
using (var sr = new StreamReader(file, Encoding.UTF8)) {
return ReleaseEntry.ParseReleaseFile(sr.ReadToEnd());
}
}
// // NB: sr disposes file
// using (var sr = new StreamReader(file, Encoding.UTF8)) {
// return ReleaseEntry.ParseReleaseFile(sr.ReadToEnd());
// }
//}
public static ReleaseEntry FindLatestFullVersion(IEnumerable<ReleaseEntry> localReleases, RID compatibleRid)
{
return FindCompatibleVersions(localReleases, compatibleRid).FirstOrDefault(f => !f.IsDelta);
}
//public static ReleaseEntry FindLatestFullVersion(IEnumerable<ReleaseEntry> localReleases, RID compatibleRid)
//{
// return FindCompatibleVersions(localReleases, compatibleRid).FirstOrDefault(f => !f.IsDelta);
//}
public static IEnumerable<ReleaseEntry> FindCompatibleVersions(IEnumerable<ReleaseEntry> localReleases, RID compatibleRid)
{
if (!localReleases.Any()) {
return null;
}
//public static IEnumerable<ReleaseEntry> FindCompatibleVersions(IEnumerable<ReleaseEntry> localReleases, RID compatibleRid)
//{
// if (!localReleases.Any()) {
// return null;
// }
if (compatibleRid == null || !compatibleRid.IsValid) {
return localReleases.OrderByDescending(x => x.Version);
}
// if (compatibleRid == null || !compatibleRid.IsValid) {
// return localReleases.OrderByDescending(x => x.Version);
// }
return localReleases
.Where(r => r.Rid.BaseRID == compatibleRid.BaseRID)
.Where(r => r.Rid.Architecture == compatibleRid.Architecture)
.OrderByDescending(x => x.Version);
}
// return localReleases
// .Where(r => r.Rid.BaseRID == compatibleRid.BaseRID)
// .Where(r => r.Rid.Architecture == compatibleRid.Architecture)
// .OrderByDescending(x => x.Version);
//}
public static string GetAppUserModelId(string packageId, string exeName)
{

View File

@@ -7,30 +7,30 @@ 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();
//[Fact]
//public void BaseUrl_WithNonHttpValue_ShowsError()
//{
// var command = new T();
string cli = GetRequiredDefaultOptions() + $"--baseUrl \"file://clowd.squirrel.com\"";
ParseResult parseResult = command.ParseAndApply(cli);
// 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);
}
// 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);
//[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);
}
// 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()
@@ -115,7 +115,7 @@ public abstract class ReleaseCommandTests<T> : BaseCommandTests<T>
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.Icon, parseResult.Errors[0].SymbolResult?.Symbol.Parents.Single());
Assert.Contains(file, parseResult.Errors[0].Message);
Assert.Contains("File does not exist", parseResult.Errors[0].Message);
}
[Fact]
@@ -129,33 +129,6 @@ public abstract class ReleaseCommandTests<T> : BaseCommandTests<T>
string searchPaths = command.EntryExecutableName;
Assert.Equal("MyApp1.exe", searchPaths);
}
[Fact]
public void AppIcon_WithBadFileExtension_ShowsError()
{
FileInfo fileInfo = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".wrong"));
var command = new T();
string cli = GetRequiredDefaultOptions() + $"--appIcon \"{fileInfo.FullName}\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
Assert.Equal($"--appIcon does not have an .ico extension", parseResult.Errors[0].Message);
}
[Fact]
public void AppIcon_WithoutFile_ShowsError()
{
string file = Path.GetFullPath(Path.ChangeExtension(Path.GetRandomFileName(), ".ico"));
var command = new T();
string cli = GetRequiredDefaultOptions() + $"--appIcon \"{file}\"";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.Equal(1, parseResult.Errors.Count);
//Assert.Equal(command.AppIcon, parseResult.Errors[0].SymbolResult?.Symbol.Parents.Single());
Assert.Contains(file, parseResult.Errors[0].Message);
}
}
public class ReleasifyWindowsCommandTests : ReleaseCommandTests<WindowsReleasifyCommand>
@@ -166,7 +139,7 @@ public class ReleasifyWindowsCommandTests : ReleaseCommandTests<WindowsReleasify
FileInfo package = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".nupkg"));
var command = new WindowsReleasifyCommand();
ParseResult parseResult = command.ParseAndApply($"--package \"{package.FullName}\"");
ParseResult parseResult = command.ParseAndApply($"--package \"{package.FullName}\" -e main.exe");
Assert.Empty(parseResult.Errors);
Assert.Equal(package.FullName, command.Package);
@@ -301,7 +274,7 @@ public class ReleasifyWindowsCommandTests : ReleaseCommandTests<WindowsReleasify
{
FileInfo package = CreateTempFile(name: Path.ChangeExtension(Path.GetRandomFileName(), ".nupkg"));
return $"-p \"{package.FullName}\" ";
return $"-p \"{package.FullName}\" -e main.exe ";
}
}
@@ -314,7 +287,7 @@ public class PackWindowsCommandTests : ReleaseCommandTests<WindowsPackCommand>
CreateTempFile(packDir);
var command = new WindowsPackCommand();
ParseResult parseResult = command.ParseAndApply($"-u Clowd.Squirrel -v 1.2.3 -p \"{packDir.FullName}\"");
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);
@@ -329,7 +302,7 @@ public class PackWindowsCommandTests : ReleaseCommandTests<WindowsPackCommand>
CreateTempFile(packDir);
var command = new WindowsPackCommand();
ParseResult parseResult = command.ParseAndApply($"--packId $42@ -v 1.0.0 -p \"{packDir.FullName}\"");
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);
@@ -343,7 +316,7 @@ public class PackWindowsCommandTests : ReleaseCommandTests<WindowsPackCommand>
CreateTempFile(packDir);
var command = new WindowsPackCommand();
ParseResult parseResult = command.ParseAndApply($"--packTitle Clowd.Squirrel -v 1.0.0 -p \"{packDir.FullName}\"");
ParseResult parseResult = command.ParseAndApply($"--packTitle Clowd.Squirrel -v 1.0.0 -p \"{packDir.FullName}\" -e main.exe");
Assert.Equal("Clowd.Squirrel", command.PackTitle);
}
@@ -355,7 +328,7 @@ public class PackWindowsCommandTests : ReleaseCommandTests<WindowsPackCommand>
CreateTempFile(packDir);
var command = new WindowsPackCommand();
ParseResult parseResult = command.ParseAndApply($"-u Clowd.Squirrel --packVersion 1.a.c -p \"{packDir.FullName}\"");
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);
@@ -526,6 +499,6 @@ public class PackWindowsCommandTests : ReleaseCommandTests<WindowsPackCommand>
DirectoryInfo packDir = CreateTempDirectory();
CreateTempFile(packDir);
return $"-u Clowd.Squirrel -v 1.0.0 -p \"{packDir.FullName}\" ";
return $"-u Clowd.Squirrel -v 1.0.0 -p \"{packDir.FullName}\" -e main.exe ";
}
}

View File

@@ -51,9 +51,11 @@ public class WindowsPackTests
runner.Pack(options);
var nupkgPath = Path.Combine(tmpReleaseDir, $"{id}-{version}-win-x64-full.nupkg");
Assert.True(File.Exists(nupkgPath));
var setupPath = Path.Combine(tmpReleaseDir, $"{id}-Setup-[win-x64].exe");
Assert.True(File.Exists(setupPath));
EasyZip.ExtractZipToDirectory(logger, nupkgPath, unzipDir);
// does nuspec exist and is it valid
@@ -67,7 +69,7 @@ public class WindowsPackTests
Assert.Equal("Test Squirrel App", xml.Root.ElementsNoNamespace("metadata").Single().ElementsNoNamespace("title").Single().Value);
Assert.Equal("author", xml.Root.ElementsNoNamespace("metadata").Single().ElementsNoNamespace("authors").Single().Value);
Assert.Equal("x64", xml.Root.ElementsNoNamespace("metadata").Single().ElementsNoNamespace("machineArchitecture").Single().Value);
Assert.Equal("net6.0-x64-desktop", xml.Root.ElementsNoNamespace("metadata").Single().ElementsNoNamespace("runtimeDependencies").Single().Value);
Assert.Equal("net6-x64-desktop", xml.Root.ElementsNoNamespace("metadata").Single().ElementsNoNamespace("runtimeDependencies").Single().Value);
Assert.Equal("win", xml.Root.ElementsNoNamespace("metadata").Single().ElementsNoNamespace("os").Single().Value);
Assert.Equal("10.0.19043", xml.Root.ElementsNoNamespace("metadata").Single().ElementsNoNamespace("osMinVersion").Single().Value);

View File

@@ -489,56 +489,56 @@ namespace Squirrel.Tests
Assert.True(ReleaseEntry.ParseReleaseFile(null).Count() == 0);
}
[Fact]
public void FindCurrentVersionWithExactRidMatch()
{
string _ridReleaseEntries = """
0000000000000000000000000000000000000000 MyApp-1.3-win-x86.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4-win-x64.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4-win-x86.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4-osx-x86.nupkg 123
""";
// [Fact]
// public void FindCurrentVersionWithExactRidMatch()
// {
// string _ridReleaseEntries = """
//0000000000000000000000000000000000000000 MyApp-1.3-win-x86.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4-win-x64.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4-win-x86.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4-osx-x86.nupkg 123
//""";
var entries = ReleaseEntry.ParseReleaseFile(_ridReleaseEntries);
// var entries = ReleaseEntry.ParseReleaseFile(_ridReleaseEntries);
var e = Utility.FindLatestFullVersion(entries, RID.Parse("win-x86"));
Assert.Equal("MyApp-1.4-win-x86.nupkg", e.OriginalFilename);
}
// var e = Utility.FindLatestFullVersion(entries, RID.Parse("win-x86"));
// Assert.Equal("MyApp-1.4-win-x86.nupkg", e.OriginalFilename);
// }
[Fact]
public void FindCurrentVersionWithExactRidMatchNotLatest()
{
string _ridReleaseEntries = """
0000000000000000000000000000000000000000 MyApp-1.3-win-x86.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4-win-x64.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4-win.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4-osx-x86.nupkg 123
""";
// [Fact]
// public void FindCurrentVersionWithExactRidMatchNotLatest()
// {
// string _ridReleaseEntries = """
//0000000000000000000000000000000000000000 MyApp-1.3-win-x86.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4-win-x64.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4-win.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4-osx-x86.nupkg 123
//""";
var entries = ReleaseEntry.ParseReleaseFile(_ridReleaseEntries);
// var entries = ReleaseEntry.ParseReleaseFile(_ridReleaseEntries);
var e = Utility.FindLatestFullVersion(entries, RID.Parse("win-x86"));
Assert.Equal("MyApp-1.3-win.nupkg", e.OriginalFilename);
}
// var e = Utility.FindLatestFullVersion(entries, RID.Parse("win-x86"));
// Assert.Equal("MyApp-1.3-win.nupkg", e.OriginalFilename);
// }
[Fact]
public void FindCurrentVersionWithExactRidMatchOnlyArchitecture()
{
string _ridReleaseEntries = """
0000000000000000000000000000000000000000 MyApp-1.3-win-x86.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4-win-x64.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4-win.nupkg 123
0000000000000000000000000000000000000000 MyApp-1.4-osx-x86.nupkg 123
""";
// [Fact]
// public void FindCurrentVersionWithExactRidMatchOnlyArchitecture()
// {
// string _ridReleaseEntries = """
//0000000000000000000000000000000000000000 MyApp-1.3-win-x86.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4-win-x64.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4-win.nupkg 123
//0000000000000000000000000000000000000000 MyApp-1.4-osx-x86.nupkg 123
//""";
var entries = ReleaseEntry.ParseReleaseFile(_ridReleaseEntries);
// var entries = ReleaseEntry.ParseReleaseFile(_ridReleaseEntries);
var e = Utility.FindLatestFullVersion(entries, RID.Parse("win-x86"));
Assert.Equal("MyApp-1.3-win.nupkg", e.OriginalFilename);
}
// var e = Utility.FindLatestFullVersion(entries, RID.Parse("win-x86"));
// Assert.Equal("MyApp-1.3-win.nupkg", e.OriginalFilename);
// }
static string MockReleaseEntry(string name, float? percentage = null)
{