Skip to content

Commit

Permalink
All output in terminal logger (#5083)
Browse files Browse the repository at this point in the history
* output as important

* All

* Write output
  • Loading branch information
nohwnd authored Jun 6, 2024
1 parent d84e6e4 commit d25f969
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/Microsoft.TestPlatform.Build/Tasks/TestTaskUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public static string CreateCommandLineArguments(ITestTask task)
if (task.VSTestNoLogo)
{
builder.AppendSwitch("--nologo");
Environment.SetEnvironmentVariable("VSTEST_MSBUILD_NOLOGO", "1");
}

if (string.Equals(task.VSTestArtifactsProcessingMode, "collect", StringComparison.OrdinalIgnoreCase))
Expand Down
39 changes: 29 additions & 10 deletions src/Microsoft.TestPlatform.Build/Tasks/VSTestTask2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class VSTestTask2 : ToolTask, ITestTask
public string? VSTestBlameHangDumpType { get; set; }
public string? VSTestBlameHangTimeout { get; set; }
public ITaskItem? VSTestTraceDataCollectorDirectoryPath { get; set; }
public bool VSTestNoLogo { get; set; }
public bool VSTestNoLogo { get; set; } = true;
public string? VSTestArtifactsProcessingMode { get; set; }
public string? VSTestSessionCorrelationId { get; set; }

Expand All @@ -59,7 +59,7 @@ public VSTestTask2()
// Unless user opted out, use UTF encoding, which we force in vstest.console.
_disableUtf8ConsoleEncoding = Environment.GetEnvironmentVariable("VSTEST_DISABLE_UTF8_CONSOLE_ENCODING") == "1";
LogStandardErrorAsError = false;
StandardOutputImportance = "Normal";
StandardOutputImportance = "High";
}

protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
Expand All @@ -73,14 +73,30 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport
{
// Forward the output we receive as messages.
case "output-info":
Log.LogMessage(MessageImportance.Low, data[0]);
if (data[0] != null)
{
LogMSBuildOutputMessage(data[0]!);
}
break;
case "output-warning":
Log.LogWarning(data[0]);
break;
case "output-error":
Log.LogError(data[0]);
break;
{
var error = data[0];
if (error != null && error.StartsWith("[xUnit.net", StringComparison.OrdinalIgnoreCase))
{
// Downgrade errors from xunit, because they will end up being duplicated on screen with assertion errors.
// And we end up with more errors in summary which is hard to figure out for users.
LogMSBuildOutputMessage(error);
}
else
{
Log.LogError(data[0]);
}

break;
}

case "run-cancel":
case "run-abort":
Expand Down Expand Up @@ -210,14 +226,17 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport
// DO NOT call the base, it parses out the output, and if it sees "error" in any place it will log it as error
// we don't want this, we only want to log errors from the text messages we receive that start error splitter.
// base.LogEventsFromTextOutput(singleLine, messageImportance);

if (!StringUtils.IsNullOrWhiteSpace(singleLine))
{
Log.LogMessage(MessageImportance.Low, singleLine);
}
LogMSBuildOutputMessage(singleLine);
}
}

private void LogMSBuildOutputMessage(string singleLine)
{

var message = new ExtendedBuildMessageEventArgs("TLTESTOUTPUT", singleLine, null, null, MessageImportance.High);
BuildEngine.LogMessageEvent(message);
}

private bool TryGetMessage(string singleLine, out string name, out string?[] data)
{
if (singleLine.StartsWith(_messageSplitter))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ public ArgumentProcessorResult Execute()
/// <param name="sources"> Test source assemblies paths. </param>
private void DiscoverTestsAndSelectSpecified(IEnumerable<string> sources)
{
Output.WriteLine(CommandLineResources.StartingDiscovery, OutputLevel.Information);
if (Environment.GetEnvironmentVariable("VSTEST_MSBUILD_NOLOGO") != "1")
{
Output.WriteLine(CommandLineResources.StartingDiscovery, OutputLevel.Information);
}

if (!StringUtils.IsNullOrEmpty(EqtTrace.LogFile))
{
Output.Information(false, CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile);
Expand Down
6 changes: 5 additions & 1 deletion src/vstest.console/Processors/RunTestsArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ public ArgumentProcessorResult Execute()
throw new CommandLineException(CommandLineResources.MissingTestSourceFile);
}

Output.WriteLine(CommandLineResources.StartingExecution, OutputLevel.Information);
if (Environment.GetEnvironmentVariable("VSTEST_MSBUILD_NOLOGO") != "1")
{
Output.WriteLine(CommandLineResources.StartingExecution, OutputLevel.Information);
}

if (!StringUtils.IsNullOrEmpty(EqtTrace.LogFile))
{
Output.Information(false, CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile);
Expand Down

0 comments on commit d25f969

Please sign in to comment.