Fix logging when running unit tests

This commit is contained in:
Caelan Sayler
2022-03-19 21:34:05 +00:00
parent 801b086d39
commit da4d64abfb
7 changed files with 75 additions and 8 deletions

View File

@@ -20,7 +20,7 @@ jobs:
shell: pwsh
run: .\pack.ps1
- name: Test
run: dotnet test test\Squirrel.Tests.csproj --verbosity normal
run: dotnet test test\Squirrel.Tests.csproj -l "console;verbosity=detailed"
- name: "Upload Tools"
uses: actions/upload-artifact@v3
with:

View File

@@ -8,15 +8,18 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Squirrel.NuGet;
using Squirrel.SimpleSplat;
using Squirrel;
using Squirrel.Tests.TestHelpers;
using Xunit;
using Xunit.Abstractions;
namespace Squirrel.Tests
{
public class ApplyReleasesTests : IEnableLogger
public class ApplyReleasesTests : TestLoggingBase
{
public ApplyReleasesTests(ITestOutputHelper log) : base(log)
{
}
[Fact]
public async Task CleanInstallRunsSquirrelAwareAppsWithInstallFlag()
{

View File

@@ -7,11 +7,16 @@ using Squirrel;
using Squirrel.SimpleSplat;
using Squirrel.Tests.TestHelpers;
using Xunit;
using Xunit.Abstractions;
namespace Squirrel.Tests
{
public class ApplyDeltaPackageTests : IEnableLogger
public class ApplyDeltaPackageTests : TestLoggingBase
{
public ApplyDeltaPackageTests(ITestOutputHelper log) : base(log)
{
}
[Fact]
public void ApplyDeltaPackageSmokeTest()
{

View File

@@ -11,7 +11,7 @@ using Xunit;
namespace Squirrel.Tests
{
public class DownloadReleasesTests : IEnableLogger
public class DownloadReleasesTests
{
[Fact(Skip = "Rewrite this to be an integration test")]
public void ChecksumShouldFailIfFilesAreMissing()

View File

@@ -11,11 +11,16 @@ using System.Xml.Linq;
using Squirrel.SimpleSplat;
using Xunit;
using Squirrel.NuGet;
using Xunit.Abstractions;
namespace Squirrel.Tests
{
public class CreateReleasePackageTests : IEnableLogger
public class CreateReleasePackageTests : TestLoggingBase
{
public CreateReleasePackageTests(ITestOutputHelper log) : base(log)
{
}
[Theory]
[InlineData("1.2.3")]
[InlineData("1.2.3-alpha13")]

View File

@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Squirrel.SimpleSplat;
using Xunit.Abstractions;
namespace Squirrel.Tests
{
public interface ITestLogging
{
IFullLogger Log();
}
public class TestLogger : ILogger
{
public LogLevel Level { get; set; }
public ITestOutputHelper OutputHelper { get; }
public TestLogger(ITestOutputHelper outputHelper)
{
OutputHelper = outputHelper;
}
public void Write([Localizable(false)] string message, LogLevel logLevel)
{
OutputHelper.WriteLine(message);
}
}
public abstract class TestLoggingBase : ITestLogging
{
public ITestOutputHelper OutputHelper { get; }
public IFullLogger Logger { get; }
public TestLoggingBase(ITestOutputHelper log)
{
OutputHelper = log;
Logger = new WrappingFullLogger(new TestLogger(OutputHelper), typeof(TestLogger));
}
public IFullLogger Log()
{
return Logger;
}
}
}

View File

@@ -10,11 +10,16 @@ using Squirrel.Tests.TestHelpers;
using Xunit;
using Squirrel.Shell;
using System.Collections.Generic;
using Xunit.Abstractions;
namespace Squirrel.Tests
{
public class UtilityTests : IEnableLogger
public class UtilityTests : TestLoggingBase
{
public UtilityTests(ITestOutputHelper log) : base(log)
{
}
[Theory]
[InlineData("file.txt", "file.txt")]
[InlineData("file", "file")]