Skip to content

Commit

Permalink
Immediately display logs on tests to see progress in real time (xoofx…
Browse files Browse the repository at this point in the history
…#333)

* Immediately display logs on tests to see progress in real time

* WIP
a
* WIP

---------

Co-authored-by: Borja Domínguez Vázquez <[email protected]>
  • Loading branch information
bdovaz and bdominguez authored Feb 13, 2024
1 parent 9170ecc commit ad10241
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
dotnet-version: '8.0.x'

- name: Build & test (Release)
run: dotnet test src -c Release
run: dotnet test src -c Release --logger "console;verbosity=normal"

- name: Should Deploy?
if: github.event_name == 'push'
Expand Down
2 changes: 1 addition & 1 deletion src/UnityNuGet.Tests/NativeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task TestBuild()
new() { Name = "netstandard2.1", DefineConstraints = ["UNITY_2021_2_OR_NEWER"] },
new() { Name = "netstandard2.0", DefineConstraints = ["!UNITY_2021_2_OR_NEWER"] },
],
new NuGetConsoleLogger())
new NuGetConsoleTestLogger())
{
Filter = "rhino3dm",
OnError = message =>
Expand Down
27 changes: 27 additions & 0 deletions src/UnityNuGet.Tests/NuGetConsoleTestLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Threading.Tasks;
using NuGet.Common;
using NUnit.Framework;

namespace UnityNuGet.Tests
{
public class NuGetConsoleTestLogger : LoggerBase
{
public override void Log(ILogMessage message)
{
if (message.Level == LogLevel.Error)
{
TestContext.Error.WriteLine(message);
}
else
{
TestContext.Progress.WriteLine(message);
}
}

public override Task LogAsync(ILogMessage message)
{
Log(message);
return Task.CompletedTask;
}
}
}
2 changes: 1 addition & 1 deletion src/UnityNuGet.Tests/RegistryCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task TestBuild()
new() { Name = "netstandard2.1", DefineConstraints = ["UNITY_2021_2_OR_NEWER"] },
new() { Name = "netstandard2.0", DefineConstraints = ["!UNITY_2021_2_OR_NEWER"] },
],
new NuGetConsoleLogger())
new NuGetConsoleTestLogger())
{
OnError = message =>
{
Expand Down
7 changes: 3 additions & 4 deletions src/UnityNuGet.Tests/RegistryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Configuration;
using NuGet.PackageManagement;
using NuGet.Packaging.Core;
Expand Down Expand Up @@ -40,7 +39,7 @@ public void Ensure_That_Packages_Already_Included_In_Net_Standard_Are_not_Includ
[Test]
public async Task CanParse_PackageWithRuntimes()
{
var logger = NullLogger.Instance;
var logger = new NuGetConsoleTestLogger();
var cancellationToken = CancellationToken.None;

var cache = new SourceCacheContext();
Expand Down Expand Up @@ -98,7 +97,7 @@ public async Task Ensure_Min_Version_Is_Correct_Ignoring_Analyzers_And_Native_Li
{
var registry = Registry.GetInstance();

var logger = NullLogger.Instance;
var logger = new NuGetConsoleTestLogger();
var cancellationToken = CancellationToken.None;

var cache = new SourceCacheContext();
Expand Down Expand Up @@ -196,7 +195,7 @@ public async Task Ensure_Do_Not_Exceed_The_Maximum_Number_Of_Allowed_Versions()

var registry = Registry.GetInstance();

var logger = NullLogger.Instance;
var logger = new NuGetConsoleTestLogger();
var cancellationToken = CancellationToken.None;

var cache = new SourceCacheContext();
Expand Down

0 comments on commit ad10241

Please sign in to comment.