Test project builds again

This commit is contained in:
Caelan Sayler
2022-05-14 20:22:50 +01:00
parent 51d3cbb9f4
commit d5774bb5c0
12 changed files with 245 additions and 241 deletions

View File

@@ -17,30 +17,11 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# - name: Install NGBV
# run: dotnet tool install --tool-path . nbgv
- name: Build
shell: pwsh
run: .\build.ps1
# - name: Create NuGet Package
# shell: pwsh
# run: .\pack.ps1
# - name: Test
# run: dotnet test test\Squirrel.Tests.csproj -l "console;verbosity=detailed"
# - name: "Upload Tools"
# uses: actions/upload-artifact@v3
# with:
# path: .\build\SquirrelTools*.zip
# if-no-files-found: error
# https://stackoverflow.com/questions/63817052/github-actions-run-step-only-for-certain-pull-request-base-branches
# - name: "Upload NuGet Package"
# uses: actions/upload-artifact@v3
# with:
# path: .\build\Clowd.Squirrel*.nupkg
# if-no-files-found: error
# - name: Publish to GitHub Packages
# if: ${{ github.ref == 'ref/head/develop' }}
# run: dotnet nuget push .\build\Clowd.Squirrel*.nupkg
- name: Test
run: dotnet test test\Squirrel.Tests.csproj -l "console;verbosity=detailed"
- name: Upload Windows Artifacts
uses: actions/upload-artifact@v3
with:
@@ -76,6 +57,7 @@ jobs:
name: osx-build
path: ./publish/*
# https://docs.github.com/en/actions/deployment/deploying-xcode-applications/installing-an-apple-certificate-on-macos-runners-for-xcode-development
package-macos:
name: Package OSX
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/cs/xplat' }}
@@ -123,7 +105,6 @@ jobs:
name: tools
path: squirrel-osx-x64.zip
# https://docs.github.com/en/actions/deployment/deploying-xcode-applications/installing-an-apple-certificate-on-macos-runners-for-xcode-development
deploy:
name: "Deploy"
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/cs/xplat' }}

View File

@@ -275,12 +275,36 @@ namespace Squirrel
/// Creates a new Platform and tries to auto-detect the application details from
/// the current context.
/// </summary>
public AppDescWindows()
public AppDescWindows() : this(SquirrelRuntimeInfo.EntryExePath)
{
}
/// <summary>
/// Creates a new windows application platform at the specified app directory.
/// </summary>
/// <param name="appDir">The location of the application.</param>
/// <param name="appId">The unique ID of the application.</param>
public AppDescWindows(string appDir, string appId)
{
if (!SquirrelRuntimeInfo.IsWindows)
throw new NotSupportedException("Cannot instantiate AppDescWindows on a non-Windows system.");
AppId = appId;
RootAppDir = appDir;
var updateExe = Path.Combine(appDir, "Update.exe");
var ver = GetLatestVersion();
if (File.Exists(updateExe) && ver != null) {
UpdateExePath = updateExe;
CurrentlyInstalledVersion = ver.Version;
}
}
internal AppDescWindows(string ourPath)
{
if (!SquirrelRuntimeInfo.IsWindows)
throw new NotSupportedException("Cannot instantiate AppDescWindows on a non-Windows system.");
var ourPath = SquirrelRuntimeInfo.EntryExePath;
var myDir = Path.GetDirectoryName(ourPath);
// Am I update.exe at the application root?
@@ -320,24 +344,6 @@ namespace Squirrel
}
}
}
/// <summary>
/// Creates a new windows application platform at the specified app directory.
/// </summary>
/// <param name="appDir">The location of the application.</param>
/// <param name="appId">The unique ID of the application.</param>
public AppDescWindows(string appDir, string appId)
{
AppId = appId;
RootAppDir = appDir;
var updateExe = Path.Combine(appDir, "Update.exe");
var ver = GetLatestVersion();
if (File.Exists(updateExe) && ver != null) {
UpdateExePath = updateExe;
CurrentlyInstalledVersion = ver.Version;
}
}
}
/// <summary>

View File

@@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Squirrel.Bsdiff;
using Squirrel.SimpleSplat;
namespace Squirrel
{
internal class DeltaPackage : IEnableLogger
{
private readonly string _baseTempDir;
public DeltaPackage(string baseTempDir = null)
{
_baseTempDir = baseTempDir ?? Utility.GetDefaultTempBaseDirectory();
}
public string ApplyDeltaPackage(string basePackageZip, string deltaPackageZip, string outputFile, Action<int> progress = null)
{
progress = progress ?? (x => { });
Contract.Requires(deltaPackageZip != null);
Contract.Requires(!String.IsNullOrEmpty(outputFile) && !File.Exists(outputFile));
using (Utility.GetTempDirectory(out var deltaPath, _baseTempDir))
using (Utility.GetTempDirectory(out var workingPath, _baseTempDir)) {
EasyZip.ExtractZipToDirectory(deltaPackageZip, deltaPath);
progress(25);
EasyZip.ExtractZipToDirectory(basePackageZip, workingPath);
progress(50);
var pathsVisited = new List<string>();
var deltaPathRelativePaths = new DirectoryInfo(deltaPath).GetAllFilesRecursively()
.Select(x => x.FullName.Replace(deltaPath + Path.DirectorySeparatorChar, ""))
.ToArray();
// Apply all of the .diff files
deltaPathRelativePaths
.Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase))
.Where(x => !x.EndsWith(".shasum", StringComparison.InvariantCultureIgnoreCase))
.Where(x => !x.EndsWith(".diff", StringComparison.InvariantCultureIgnoreCase) ||
!deltaPathRelativePaths.Contains(x.Replace(".diff", ".bsdiff")))
.ForEach(file => {
pathsVisited.Add(Regex.Replace(file, @"\.(bs)?diff$", "").ToLowerInvariant());
applyDiffToFile(deltaPath, file, workingPath);
});
progress(75);
// Delete all of the files that were in the old package but
// not in the new one.
new DirectoryInfo(workingPath).GetAllFilesRecursively()
.Select(x => x.FullName.Replace(workingPath + Path.DirectorySeparatorChar, "").ToLowerInvariant())
.Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase) && !pathsVisited.Contains(x))
.ForEach(x => {
this.Log().Info("{0} was in old package but not in new one, deleting", x);
File.Delete(Path.Combine(workingPath, x));
});
progress(80);
// Update all the files that aren't in 'lib' with the delta
// package's versions (i.e. the nuspec file, etc etc).
deltaPathRelativePaths
.Where(x => !x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase))
.ForEach(x => {
this.Log().Info("Updating metadata file: {0}", x);
File.Copy(Path.Combine(deltaPath, x), Path.Combine(workingPath, x), true);
});
this.Log().Info("Repacking into full package: {0}", outputFile);
EasyZip.CreateZipFromDirectory(outputFile, workingPath);
progress(100);
}
return outputFile;
}
void applyDiffToFile(string deltaPath, string relativeFilePath, string workingDirectory)
{
var inputFile = Path.Combine(deltaPath, relativeFilePath);
var finalTarget = Path.Combine(workingDirectory, Regex.Replace(relativeFilePath, @"\.(bs)?diff$", ""));
using var _d = Utility.GetTempFileName(out var tempTargetFile, _baseTempDir);
// NB: Zero-length diffs indicate the file hasn't actually changed
if (new FileInfo(inputFile).Length == 0) {
this.Log().Info("{0} exists unchanged, skipping", relativeFilePath);
return;
}
if (relativeFilePath.EndsWith(".bsdiff", StringComparison.InvariantCultureIgnoreCase)) {
using (var of = File.OpenWrite(tempTargetFile))
using (var inf = File.OpenRead(finalTarget)) {
this.Log().Info("Applying bsdiff to {0}", relativeFilePath);
BinaryPatchUtility.Apply(inf, () => File.OpenRead(inputFile), of);
}
verifyPatchedFile(relativeFilePath, inputFile, tempTargetFile);
} else if (relativeFilePath.EndsWith(".diff", StringComparison.InvariantCultureIgnoreCase)) {
this.Log().Info("Applying msdiff to {0}", relativeFilePath);
if (SquirrelRuntimeInfo.IsWindows) {
MsDeltaCompression.ApplyDelta(inputFile, finalTarget, tempTargetFile);
} else {
throw new InvalidOperationException("msdiff is not supported on non-windows platforms.");
}
verifyPatchedFile(relativeFilePath, inputFile, tempTargetFile);
} else {
using (var of = File.OpenWrite(tempTargetFile))
using (var inf = File.OpenRead(inputFile)) {
this.Log().Info("Adding new file: {0}", relativeFilePath);
inf.CopyTo(of);
}
}
if (File.Exists(finalTarget)) File.Delete(finalTarget);
var targetPath = Directory.GetParent(finalTarget);
if (!targetPath.Exists) targetPath.Create();
File.Move(tempTargetFile, finalTarget);
}
void verifyPatchedFile(string relativeFilePath, string inputFile, string tempTargetFile)
{
var shaFile = Regex.Replace(inputFile, @"\.(bs)?diff$", ".shasum");
var expectedReleaseEntry = ReleaseEntry.ParseReleaseEntry(File.ReadAllText(shaFile, Encoding.UTF8));
var actualReleaseEntry = ReleaseEntry.GenerateFromFile(tempTargetFile);
if (expectedReleaseEntry.Filesize != actualReleaseEntry.Filesize) {
this.Log().Warn("Patched file {0} has incorrect size, expected {1}, got {2}", relativeFilePath,
expectedReleaseEntry.Filesize, actualReleaseEntry.Filesize);
throw new ChecksumFailedException() { Filename = relativeFilePath };
}
if (expectedReleaseEntry.SHA1 != actualReleaseEntry.SHA1) {
this.Log().Warn("Patched file {0} has incorrect SHA1, expected {1}, got {2}", relativeFilePath,
expectedReleaseEntry.SHA1, actualReleaseEntry.SHA1);
throw new ChecksumFailedException() { Filename = relativeFilePath };
}
}
}
}

View File

@@ -277,8 +277,8 @@ namespace Squirrel
private static string GetNextTempName(string tempDir)
{
for (int i = 1; i < 100; i++) {
string name = "temp" + i;
for (int i = 1; i < 10000; i++) {
string name = "temp." + i;
var target = Path.Combine(tempDir, name);
FileSystemInfo info = null;
@@ -301,7 +301,7 @@ namespace Squirrel
}
throw new Exception(
"Unable to find free temp path. Has the temp directory exceeded it's maximum number of items?");
"Unable to find free temp path. Has the temp directory exceeded it's maximum number of items? (10000)");
}
public static IDisposable GetTempDirectory(out string newTempDirectory)

View File

@@ -27,7 +27,7 @@ namespace Squirrel.NuGet
throw new ArgumentException($"Invalid package Id '{id}', it must contain only alphanumeric characters, underscores, dashes, and dots.");
}
public static void ThrowIfVersionNotSemverCompliant(string version, bool allowTags)
public static void ThrowIfVersionNotSemverCompliant(string version, bool allowTags = true)
{
if (SemanticVersion.TryParse(version, out var parsed)) {
if (parsed < new SemanticVersion(0, 0, 1)) {

View File

@@ -4,12 +4,10 @@ using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Squirrel.SimpleSplat;
using System.Threading;
using Squirrel.Bsdiff;
using System.Runtime.Versioning;
using Squirrel.NuGet;
@@ -193,7 +191,7 @@ namespace Squirrel
var basePkg = Path.Combine(_config.PackagesDir, currentVersion.Filename);
var deltaPkg = Path.Combine(_config.PackagesDir, releasesToApply.First().Filename);
return ApplyDeltaPackage(basePkg, deltaPkg,
return new DeltaPackage(_config.AppTempDir).ApplyDeltaPackage(basePkg, deltaPkg,
Regex.Replace(deltaPkg, @"-delta.nupkg$", ".nupkg", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant),
x => progress.ReportReleaseProgress(x));
}).ConfigureAwait(false);
@@ -367,135 +365,5 @@ namespace Squirrel
{
return File.Exists(Path.Combine(appFolderPath, ".dead"));
}
internal string ApplyDeltaPackage(string basePackageZip, string deltaPackageZip, string outputFile, Action<int> progress = null)
{
progress = progress ?? (x => { });
Contract.Requires(deltaPackageZip != null);
Contract.Requires(!String.IsNullOrEmpty(outputFile) && !File.Exists(outputFile));
using (Utility.GetTempDirectory(out var deltaPath, _config.AppTempDir))
using (Utility.GetTempDirectory(out var workingPath, _config.AppTempDir)) {
EasyZip.ExtractZipToDirectory(deltaPackageZip, deltaPath);
progress(25);
EasyZip.ExtractZipToDirectory(basePackageZip, workingPath);
progress(50);
var pathsVisited = new List<string>();
var deltaPathRelativePaths = new DirectoryInfo(deltaPath).GetAllFilesRecursively()
.Select(x => x.FullName.Replace(deltaPath + Path.DirectorySeparatorChar, ""))
.ToArray();
// Apply all of the .diff files
deltaPathRelativePaths
.Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase))
.Where(x => !x.EndsWith(".shasum", StringComparison.InvariantCultureIgnoreCase))
.Where(x => !x.EndsWith(".diff", StringComparison.InvariantCultureIgnoreCase) ||
!deltaPathRelativePaths.Contains(x.Replace(".diff", ".bsdiff")))
.ForEach(file => {
pathsVisited.Add(Regex.Replace(file, @"\.(bs)?diff$", "").ToLowerInvariant());
applyDiffToFile(deltaPath, file, workingPath);
});
progress(75);
// Delete all of the files that were in the old package but
// not in the new one.
new DirectoryInfo(workingPath).GetAllFilesRecursively()
.Select(x => x.FullName.Replace(workingPath + Path.DirectorySeparatorChar, "").ToLowerInvariant())
.Where(x => x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase) && !pathsVisited.Contains(x))
.ForEach(x => {
this.Log().Info("{0} was in old package but not in new one, deleting", x);
File.Delete(Path.Combine(workingPath, x));
});
progress(80);
// Update all the files that aren't in 'lib' with the delta
// package's versions (i.e. the nuspec file, etc etc).
deltaPathRelativePaths
.Where(x => !x.StartsWith("lib", StringComparison.InvariantCultureIgnoreCase))
.ForEach(x => {
this.Log().Info("Updating metadata file: {0}", x);
File.Copy(Path.Combine(deltaPath, x), Path.Combine(workingPath, x), true);
});
this.Log().Info("Repacking into full package: {0}", outputFile);
EasyZip.CreateZipFromDirectory(outputFile, workingPath);
progress(100);
}
return outputFile;
}
void applyDiffToFile(string deltaPath, string relativeFilePath, string workingDirectory)
{
var inputFile = Path.Combine(deltaPath, relativeFilePath);
var finalTarget = Path.Combine(workingDirectory, Regex.Replace(relativeFilePath, @"\.(bs)?diff$", ""));
using var _d = Utility.GetTempFileName(out var tempTargetFile, _config.AppTempDir);
// NB: Zero-length diffs indicate the file hasn't actually changed
if (new FileInfo(inputFile).Length == 0) {
this.Log().Info("{0} exists unchanged, skipping", relativeFilePath);
return;
}
if (relativeFilePath.EndsWith(".bsdiff", StringComparison.InvariantCultureIgnoreCase)) {
using (var of = File.OpenWrite(tempTargetFile))
using (var inf = File.OpenRead(finalTarget)) {
this.Log().Info("Applying bsdiff to {0}", relativeFilePath);
BinaryPatchUtility.Apply(inf, () => File.OpenRead(inputFile), of);
}
verifyPatchedFile(relativeFilePath, inputFile, tempTargetFile);
} else if (relativeFilePath.EndsWith(".diff", StringComparison.InvariantCultureIgnoreCase)) {
this.Log().Info("Applying msdiff to {0}", relativeFilePath);
if (SquirrelRuntimeInfo.IsWindows) {
MsDeltaCompression.ApplyDelta(inputFile, finalTarget, tempTargetFile);
} else {
throw new InvalidOperationException("msdiff is not supported on non-windows platforms.");
}
verifyPatchedFile(relativeFilePath, inputFile, tempTargetFile);
} else {
using (var of = File.OpenWrite(tempTargetFile))
using (var inf = File.OpenRead(inputFile)) {
this.Log().Info("Adding new file: {0}", relativeFilePath);
inf.CopyTo(of);
}
}
if (File.Exists(finalTarget)) File.Delete(finalTarget);
var targetPath = Directory.GetParent(finalTarget);
if (!targetPath.Exists) targetPath.Create();
File.Move(tempTargetFile, finalTarget);
}
void verifyPatchedFile(string relativeFilePath, string inputFile, string tempTargetFile)
{
var shaFile = Regex.Replace(inputFile, @"\.(bs)?diff$", ".shasum");
var expectedReleaseEntry = ReleaseEntry.ParseReleaseEntry(File.ReadAllText(shaFile, Encoding.UTF8));
var actualReleaseEntry = ReleaseEntry.GenerateFromFile(tempTargetFile);
if (expectedReleaseEntry.Filesize != actualReleaseEntry.Filesize) {
this.Log().Warn("Patched file {0} has incorrect size, expected {1}, got {2}", relativeFilePath,
expectedReleaseEntry.Filesize, actualReleaseEntry.Filesize);
throw new ChecksumFailedException() { Filename = relativeFilePath };
}
if (expectedReleaseEntry.SHA1 != actualReleaseEntry.SHA1) {
this.Log().Warn("Patched file {0} has incorrect SHA1, expected {1}, got {2}", relativeFilePath,
expectedReleaseEntry.SHA1, actualReleaseEntry.SHA1);
throw new ChecksumFailedException() { Filename = relativeFilePath };
}
}
}
}

View File

@@ -200,7 +200,9 @@ namespace Squirrel.Tests
//Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "app-0.1.0")));
Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "current")));
var version = Utility.GetAppVersionDirectories(Path.Combine(tempDir, pkgName)).Single();
var info = new AppDescWindows(Path.Combine(tempDir, pkgName), pkgName);
var version = info.GetVersions().Single();
Assert.True(version.IsCurrent);
Assert.Equal(new SemanticVersion(0, 1, 0), version.Manifest.Version);
@@ -216,9 +218,9 @@ namespace Squirrel.Tests
await fixture.UpdateApp();
}
Utility.UpdateAndRetrieveCurrentFolder(Path.Combine(tempDir, pkgName), false);
info.UpdateAndRetrieveCurrentFolder(false);
var versions = Utility.GetAppVersionDirectories(Path.Combine(tempDir, pkgName)).ToArray();
var versions = info.GetVersions().ToArray();
Assert.Equal(2, versions.Count());
Assert.Equal(new SemanticVersion(0, 2, 0), versions.Single(s => s.IsCurrent).Version);

View File

@@ -9,6 +9,7 @@ using Squirrel.Tests.TestHelpers;
using Xunit;
using Xunit.Abstractions;
using NuGet.Versioning;
using Squirrel.CommandLine;
namespace Squirrel.Tests
{
@@ -21,13 +22,13 @@ namespace Squirrel.Tests
[Fact]
public void ApplyDeltaPackageSmokeTest()
{
var basePackage = new ReleasePackage(IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0-full.nupkg"));
var deltaPackage = new ReleasePackage(IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-delta.nupkg"));
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0-full.nupkg");
var deltaPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-delta.nupkg");
var expectedPackageFile = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-full.nupkg");
var outFile = Path.GetTempFileName() + ".nupkg";
try {
var deltaBuilder = new DeltaPackageBuilder();
var deltaBuilder = new DeltaPackage();
deltaBuilder.ApplyDeltaPackage(basePackage, deltaPackage, outFile);
var result = new ZipPackage(outFile);
@@ -57,12 +58,12 @@ namespace Squirrel.Tests
[Fact]
public void ApplyDeltaWithBothBsdiffAndNormalDiffDoesntFail()
{
var basePackage = new ReleasePackage(IntegrationTestHelper.GetPath("fixtures", "slack-1.1.8-full.nupkg"));
var deltaPackage = new ReleasePackage(IntegrationTestHelper.GetPath("fixtures", "slack-1.2.0-delta.nupkg"));
var basePackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.1.8-full.nupkg");
var deltaPackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.2.0-delta.nupkg");
var outFile = Path.GetTempFileName() + ".nupkg";
try {
var deltaBuilder = new DeltaPackageBuilder();
var deltaBuilder = new DeltaPackage();
deltaBuilder.ApplyDeltaPackage(basePackage, deltaPackage, outFile);
var result = new ZipPackage(outFile);
@@ -91,8 +92,8 @@ namespace Squirrel.Tests
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
var baseFixture = new ReleasePackage(basePackage);
var fixture = new ReleasePackage(newPackage);
var baseFixture = new ReleasePackageBuilder(basePackage);
var fixture = new ReleasePackageBuilder(newPackage);
var tempFiles = Enumerable.Range(0, 3)
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
@@ -173,8 +174,8 @@ namespace Squirrel.Tests
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
var baseFixture = new ReleasePackage(basePackage);
var fixture = new ReleasePackage(newPackage);
var baseFixture = new ReleasePackageBuilder(basePackage);
var fixture = new ReleasePackageBuilder(newPackage);
var tempFiles = Enumerable.Range(0, 3)
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
@@ -205,8 +206,8 @@ namespace Squirrel.Tests
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
(new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
var baseFixture = new ReleasePackage(basePackage);
var fixture = new ReleasePackage(newPackage);
var baseFixture = new ReleasePackageBuilder(basePackage);
var fixture = new ReleasePackageBuilder(newPackage);
var tempFile = Path.GetTempPath() + Guid.NewGuid() + ".nupkg";
@@ -226,8 +227,8 @@ namespace Squirrel.Tests
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
var baseFixture = new ReleasePackage(basePackage);
var fixture = new ReleasePackage(newPackage);
var baseFixture = new ReleasePackageBuilder(basePackage);
var fixture = new ReleasePackageBuilder(newPackage);
var tempFiles = Enumerable.Range(0, 3)
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
@@ -258,8 +259,8 @@ namespace Squirrel.Tests
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
var baseFixture = new ReleasePackage(basePackage);
var fixture = new ReleasePackage(newPackage);
var baseFixture = new ReleasePackageBuilder(basePackage);
var fixture = new ReleasePackageBuilder(newPackage);
var tempFiles = Enumerable.Range(0, 3)
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")

View File

@@ -6,6 +6,7 @@ using Squirrel.Tests.TestHelpers;
using Xunit;
using Squirrel.NuGet;
using NuGet.Versioning;
using Squirrel.CommandLine;
namespace Squirrel.Tests
{
@@ -173,26 +174,26 @@ namespace Squirrel.Tests
[Fact]
public void GetLatestReleaseWithNullCollectionReturnsNull()
{
Assert.Null(ReleaseEntry.GetPreviousRelease(
Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
null, null, null));
}
[Fact]
public void GetLatestReleaseWithEmptyCollectionReturnsNull()
{
Assert.Null(ReleaseEntry.GetPreviousRelease(
Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
Enumerable.Empty<ReleaseEntry>(), null, null));
}
[Fact]
public void WhenCurrentReleaseMatchesLastReleaseReturnNull()
{
var package = new ReleasePackage("Espera-1.7.6-beta.nupkg");
var package = new ReleasePackageBuilder("Espera-1.7.6-beta.nupkg");
var releaseEntries = new[] {
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg"))
};
Assert.Null(ReleaseEntry.GetPreviousRelease(
Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
releaseEntries, package, @"C:\temp\somefolder"));
}
@@ -200,14 +201,14 @@ namespace Squirrel.Tests
public void WhenMultipleReleaseMatchesReturnEarlierResult()
{
var expected = SemanticVersion.Parse("1.7.5-beta");
var package = new ReleasePackage("Espera-1.7.6-beta.nupkg");
var package = new ReleasePackageBuilder("Espera-1.7.6-beta.nupkg");
var releaseEntries = new[] {
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg"))
};
var actual = ReleaseEntry.GetPreviousRelease(
var actual = ReleasePackageBuilder.GetPreviousRelease(
releaseEntries,
package,
@"C:\temp\");
@@ -219,14 +220,14 @@ namespace Squirrel.Tests
public void WhenMultipleReleasesFoundReturnPreviousVersion()
{
var expected = SemanticVersion.Parse("1.7.6-beta");
var input = new ReleasePackage("Espera-1.7.7-beta.nupkg");
var input = new ReleasePackageBuilder("Espera-1.7.7-beta.nupkg");
var releaseEntries = new[] {
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg"))
};
var actual = ReleaseEntry.GetPreviousRelease(
var actual = ReleasePackageBuilder.GetPreviousRelease(
releaseEntries,
input,
@"C:\temp\");
@@ -238,14 +239,14 @@ namespace Squirrel.Tests
public void WhenMultipleReleasesFoundInOtherOrderReturnPreviousVersion()
{
var expected = SemanticVersion.Parse("1.7.6-beta");
var input = new ReleasePackage("Espera-1.7.7-beta.nupkg");
var input = new ReleasePackageBuilder("Espera-1.7.7-beta.nupkg");
var releaseEntries = new[] {
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg")),
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg"))
};
var actual = ReleaseEntry.GetPreviousRelease(
var actual = ReleasePackageBuilder.GetPreviousRelease(
releaseEntries,
input,
@"C:\temp\");

View File

@@ -13,6 +13,7 @@ using Xunit;
using Squirrel.NuGet;
using Xunit.Abstractions;
using NuGet.Versioning;
using Squirrel.CommandLine;
namespace Squirrel.Tests
{
@@ -55,7 +56,7 @@ namespace Squirrel.Tests
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
var outputPackage = Path.GetTempFileName() + ".nupkg";
var fixture = new ReleasePackage(inputPackage);
var fixture = new ReleasePackageBuilder(inputPackage);
try {
fixture.CreateReleasePackage(outputPackage);
@@ -88,7 +89,7 @@ namespace Squirrel.Tests
{
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.NoDependencies.1.0.0.0.nupkg");
var outputPackage = Path.GetTempFileName() + ".nupkg";
var fixture = new ReleasePackage(inputPackage);
var fixture = new ReleasePackageBuilder(inputPackage);
try {
fixture.CreateReleasePackage(outputPackage);
} finally {
@@ -101,7 +102,7 @@ namespace Squirrel.Tests
{
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectDependsOnJsonDotNet.1.0.nupkg");
var outputPackage = Path.GetTempFileName() + ".nupkg";
var fixture = new ReleasePackage(inputPackage);
var fixture = new ReleasePackageBuilder(inputPackage);
try {
Assert.Throws<InvalidOperationException>(() => fixture.CreateReleasePackage(outputPackage));
} finally {
@@ -115,7 +116,7 @@ namespace Squirrel.Tests
{
var dontcare = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nupkg");
var inputSpec = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nuspec");
var fixture = new ReleasePackage(dontcare);
var fixture = new ReleasePackageBuilder(dontcare);
var targetFile = Path.GetTempFileName();
File.Copy(inputSpec, targetFile, true);
@@ -148,7 +149,7 @@ namespace Squirrel.Tests
{
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectWithContent.1.0.0.0-beta.nupkg");
var outputPackage = Path.GetTempFileName() + ".zip";
var fixture = new ReleasePackage(inputPackage);
var fixture = new ReleasePackageBuilder(inputPackage);
try {
fixture.CreateReleasePackage(outputPackage);

View File

@@ -72,7 +72,8 @@ namespace Squirrel.Tests
"Squirrel.Core.1.1.0.0-full.nupkg",
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(tempDir, "theApp", "packages", x)));
ReleaseEntry.BuildReleasesFile(Utility.PackageDirectoryForAppDir(appDir));
var info = new AppDescWindows(appDir, "theApp");
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
var releasePath = Path.Combine(packageDir.FullName, "RELEASES");
File.Exists(releasePath).ShouldBeTrue();
@@ -162,7 +163,8 @@ namespace Squirrel.Tests
});
// sync both release files
ReleaseEntry.BuildReleasesFile(Utility.PackageDirectoryForAppDir(appDir));
var info = new AppDescWindows(appDir, "theApp");
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
ReleaseEntry.BuildReleasesFile(remotePackages);
// check for an update
@@ -205,7 +207,8 @@ namespace Squirrel.Tests
});
// sync both release files
ReleaseEntry.BuildReleasesFile(Utility.PackageDirectoryForAppDir(appDir));
var info = new AppDescWindows(appDir, "theApp");
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
ReleaseEntry.BuildReleasesFile(remotePackages);
UpdateInfo updateInfo;
@@ -244,7 +247,8 @@ namespace Squirrel.Tests
});
// sync both release files
ReleaseEntry.BuildReleasesFile(Utility.PackageDirectoryForAppDir(appDir));
var info = new AppDescWindows(appDir, "theApp");
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
ReleaseEntry.BuildReleasesFile(remotePackages);
using (var mgr = new UpdateManager(remotePackages, "theApp", tempDir, new FakeDownloader())) {
@@ -317,10 +321,11 @@ namespace Squirrel.Tests
Directory.CreateDirectory(Path.Combine(tempDir, "theApp", "wrongDir"));
File.WriteAllText(Path.Combine(tempDir, "theApp", "Update.exe"), "1");
using (var fixture = new UpdateManager("http://lol", "theApp", tempDir)) {
Assert.Null(fixture.CurrentlyInstalledVersion(Path.Combine(tempDir, "app.exe")));
Assert.Null(fixture.CurrentlyInstalledVersion(Path.Combine(tempDir, "theApp", "app.exe")));
Assert.Null(fixture.CurrentlyInstalledVersion(Path.Combine(tempDir, "theApp", "wrongDir", "app.exe")));
Assert.Equal(new SemanticVersion(1, 0, 9), fixture.CurrentlyInstalledVersion(Path.Combine(tempDir, "theApp", "app-1.0.9", "app.exe")));
Assert.Null(new AppDescWindows(Path.Combine(tempDir, "app.exe")).CurrentlyInstalledVersion);
Assert.Null(new AppDescWindows(Path.Combine(tempDir, "theApp", "app.exe")).CurrentlyInstalledVersion);
Assert.Null(new AppDescWindows(Path.Combine(tempDir, "theApp", "wrongDir", "app.exe")).CurrentlyInstalledVersion);
Assert.Equal(new SemanticVersion(1, 0, 9),
new AppDescWindows(Path.Combine(tempDir, "theApp", "app-1.0.9", "app.exe")).CurrentlyInstalledVersion);
}
}
}

View File

@@ -65,19 +65,6 @@ namespace Squirrel.Tests
Console.WriteLine("Saved to " + path);
}
[Theory]
[InlineData(10, 1)]
[InlineData(100, 1)]
[InlineData(0, 1)]
[InlineData(30000, 2)]
[InlineData(50000, 2)]
[InlineData(10000000, 3)]
public void TestTempNameGeneration(int index, int expectedLength)
{
string result = Utility.tempNameForIndex(index, "");
Assert.Equal(result.Length, expectedLength);
}
[Fact]
public void RemoveByteOrderMarkerIfPresent()
{