Skip to content

Commit 4d3059d

Browse files
committed
Some errors shouldn't break tests
1 parent 54a37bc commit 4d3059d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Formatting_NetFx/FormattingTestBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
1616
using Microsoft.AspNetCore.Razor.Test.Common;
1717
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
18+
using Microsoft.AspNetCore.Razor.Test.Common.Logging;
1819
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
1920
using Microsoft.AspNetCore.Razor.Threading;
2021
using Microsoft.CodeAnalysis;
@@ -46,6 +47,8 @@ public abstract class FormattingTestBase : RazorToolingIntegrationTestBase
4647
private protected FormattingTestBase(FormattingTestContext context, HtmlFormattingService htmlFormattingService, ITestOutputHelper testOutput)
4748
: base(testOutput)
4849
{
50+
TestOutputLogger.ThrowOnErrorLogged = true;
51+
4952
_htmlFormattingService = htmlFormattingService;
5053
_context = context;
5154
}

src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Logging/TestOutputLogger.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Microsoft.AspNetCore.Razor.Test.Common.Logging;
99

1010
internal partial class TestOutputLogger(TestOutputLoggerProvider provider, string categoryName, LogLevel logLevel = LogLevel.Trace) : ILogger
1111
{
12+
public static bool ThrowOnErrorLogged { get; set; } = false;
13+
1214
private readonly TestOutputLoggerProvider _provider = provider;
1315
private readonly string _categoryName = categoryName;
1416
private readonly LogLevel _logLevel = logLevel;
@@ -18,7 +20,7 @@ public bool IsEnabled(LogLevel logLevel)
1820

1921
public void Log(LogLevel logLevel, string message, Exception? exception)
2022
{
21-
if (logLevel == LogLevel.Error)
23+
if (ThrowOnErrorLogged && logLevel == LogLevel.Error)
2224
{
2325
throw exception ?? new InvalidOperationException(message);
2426
}

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost/Formatting/FormattingTestBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNetCore.Razor;
88
using Microsoft.AspNetCore.Razor.Language;
99
using Microsoft.AspNetCore.Razor.Test.Common;
10+
using Microsoft.AspNetCore.Razor.Test.Common.Logging;
1011
using Microsoft.CodeAnalysis;
1112
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
1213
using Microsoft.CodeAnalysis.ExternalAccess.Razor.Features;
@@ -30,6 +31,8 @@ public abstract class FormattingTestBase : CohostEndpointTestBase
3031
private protected FormattingTestBase(FormattingTestContext context, HtmlFormattingService htmlFormattingService, ITestOutputHelper testOutputHelper)
3132
: base(testOutputHelper)
3233
{
34+
TestOutputLogger.ThrowOnErrorLogged = true;
35+
3336
_context = context;
3437
_htmlFormattingService = htmlFormattingService;
3538
}

0 commit comments

Comments
 (0)