Skip to content

Commit

Permalink
Bug: pre-formatting messages causes re-formatting exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Jul 17, 2024
1 parent 59b2a63 commit 0978d60
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/xunit.runner.visualstudio/Sinks/VsExecutionSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,13 @@ void LogError(
string assemblyPath,
string format,
params object?[] args) =>
logger.SendMessage(TestMessageLevel.Error, assemblyPath, string.Format(format, args));
logger.SendMessage(TestMessageLevel.Error, assemblyPath, format, args);

public void LogWarning(
TestAssemblyMessage msg,
string format,
params object?[] args) =>
logger.SendMessage(TestMessageLevel.Warning, TestAssemblyPath(msg), string.Format(format, args));
logger.SendMessage(TestMessageLevel.Warning, TestAssemblyPath(msg), format, args);

VsTestResult? MakeVsTestResult(
TestOutcome outcome,
Expand Down
23 changes: 15 additions & 8 deletions src/xunit.runner.visualstudio/Utility/LoggerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,57 @@ public class LoggerHelper(IMessageLogger? logger, Stopwatch stopwatch)

public void Log(
string format,
object? first,
params object?[] args) =>
SendMessage(InnerLogger, TestMessageLevel.Informational, null, string.Format(format, args));
SendMessage(InnerLogger, TestMessageLevel.Informational, null, format, [first, .. args]);

public void LogWithSource(
string? source,
string format,
object? first,
params object?[] args) =>
SendMessage(InnerLogger, TestMessageLevel.Informational, source, string.Format(format, args));
SendMessage(InnerLogger, TestMessageLevel.Informational, source, format, [first, .. args]);

public void LogError(
string format,
object? first,
params object?[] args) =>
SendMessage(InnerLogger, TestMessageLevel.Error, null, string.Format(format, args));
SendMessage(InnerLogger, TestMessageLevel.Error, null, format, [first, .. args]);

public void LogErrorWithSource(
string? source,
string format,
object? first,
params object?[] args) =>
SendMessage(InnerLogger, TestMessageLevel.Error, source, string.Format(format, args));
SendMessage(InnerLogger, TestMessageLevel.Error, source, format, [first, .. args]);

public void LogWarning(
string format,
object? first,
params object?[] args) =>
SendMessage(InnerLogger, TestMessageLevel.Warning, null, string.Format(format, args));
SendMessage(InnerLogger, TestMessageLevel.Warning, null, format, [first, .. args]);

public void LogWarningWithSource(
string? source,
string format,
object? first,
params object?[] args) =>
SendMessage(InnerLogger, TestMessageLevel.Warning, source, string.Format(format, args));
SendMessage(InnerLogger, TestMessageLevel.Warning, source, format, [first, .. args]);

public void SendMessage(
TestMessageLevel level,
string? assemblyName,
string format,
object? first,
params object?[] args) =>
SendMessage(InnerLogger, level, assemblyName, format, args);
SendMessage(InnerLogger, level, assemblyName, format, [first, .. args]);

void SendMessage(
IMessageLogger? logger,
TestMessageLevel level,
string? assemblyName,
string format,
params object?[] args)
object?[] args)
{
if (logger is null)
return;
Expand Down
4 changes: 2 additions & 2 deletions src/xunit.runner.visualstudio/VsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ static IList<DiscoveredTestCase> GetVsTestCases(
static void PrintHeader(LoggerHelper loggerHelper)
{
if (Interlocked.Exchange(ref printedHeader, 1) == 0)
loggerHelper.Log($"xUnit.net VSTest Adapter v{ThisAssembly.AssemblyInformationalVersion} ({IntPtr.Size * 8}-bit {RuntimeInformation.FrameworkDescription})");
loggerHelper.Log("xUnit.net VSTest Adapter v{0} ({1}-bit {2})", ThisAssembly.AssemblyInformationalVersion, IntPtr.Size * 8, RuntimeInformation.FrameworkDescription);
}

public void RunTests(
Expand Down Expand Up @@ -613,7 +613,7 @@ await DiscoverTestsInAssembly(

if ((resultsSink.ExecutionSummary.Failed != 0 || resultsSink.ExecutionSummary.Errors != 0) && executionOptions.GetStopOnTestFailOrDefault())
{
logger.Log("Canceling due to test failure...");
logger.Log("{0}", "Canceling due to test failure...");
cancelled = true;
}
}
Expand Down

0 comments on commit 0978d60

Please sign in to comment.