Skip to content

Commit d25f969

Browse files
authored
All output in terminal logger (#5083)
* output as important * All * Write output
1 parent d84e6e4 commit d25f969

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

src/Microsoft.TestPlatform.Build/Tasks/TestTaskUtils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public static string CreateCommandLineArguments(ITestTask task)
215215
if (task.VSTestNoLogo)
216216
{
217217
builder.AppendSwitch("--nologo");
218+
Environment.SetEnvironmentVariable("VSTEST_MSBUILD_NOLOGO", "1");
218219
}
219220

220221
if (string.Equals(task.VSTestArtifactsProcessingMode, "collect", StringComparison.OrdinalIgnoreCase))

src/Microsoft.TestPlatform.Build/Tasks/VSTestTask2.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class VSTestTask2 : ToolTask, ITestTask
4040
public string? VSTestBlameHangDumpType { get; set; }
4141
public string? VSTestBlameHangTimeout { get; set; }
4242
public ITaskItem? VSTestTraceDataCollectorDirectoryPath { get; set; }
43-
public bool VSTestNoLogo { get; set; }
43+
public bool VSTestNoLogo { get; set; } = true;
4444
public string? VSTestArtifactsProcessingMode { get; set; }
4545
public string? VSTestSessionCorrelationId { get; set; }
4646

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

6565
protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
@@ -73,14 +73,30 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport
7373
{
7474
// Forward the output we receive as messages.
7575
case "output-info":
76-
Log.LogMessage(MessageImportance.Low, data[0]);
76+
if (data[0] != null)
77+
{
78+
LogMSBuildOutputMessage(data[0]!);
79+
}
7780
break;
7881
case "output-warning":
7982
Log.LogWarning(data[0]);
8083
break;
8184
case "output-error":
82-
Log.LogError(data[0]);
83-
break;
85+
{
86+
var error = data[0];
87+
if (error != null && error.StartsWith("[xUnit.net", StringComparison.OrdinalIgnoreCase))
88+
{
89+
// Downgrade errors from xunit, because they will end up being duplicated on screen with assertion errors.
90+
// And we end up with more errors in summary which is hard to figure out for users.
91+
LogMSBuildOutputMessage(error);
92+
}
93+
else
94+
{
95+
Log.LogError(data[0]);
96+
}
97+
98+
break;
99+
}
84100

85101
case "run-cancel":
86102
case "run-abort":
@@ -210,14 +226,17 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport
210226
// DO NOT call the base, it parses out the output, and if it sees "error" in any place it will log it as error
211227
// we don't want this, we only want to log errors from the text messages we receive that start error splitter.
212228
// base.LogEventsFromTextOutput(singleLine, messageImportance);
213-
214-
if (!StringUtils.IsNullOrWhiteSpace(singleLine))
215-
{
216-
Log.LogMessage(MessageImportance.Low, singleLine);
217-
}
229+
LogMSBuildOutputMessage(singleLine);
218230
}
219231
}
220232

233+
private void LogMSBuildOutputMessage(string singleLine)
234+
{
235+
236+
var message = new ExtendedBuildMessageEventArgs("TLTESTOUTPUT", singleLine, null, null, MessageImportance.High);
237+
BuildEngine.LogMessageEvent(message);
238+
}
239+
221240
private bool TryGetMessage(string singleLine, out string name, out string?[] data)
222241
{
223242
if (singleLine.StartsWith(_messageSplitter))

src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ public ArgumentProcessorResult Execute()
209209
/// <param name="sources"> Test source assemblies paths. </param>
210210
private void DiscoverTestsAndSelectSpecified(IEnumerable<string> sources)
211211
{
212-
Output.WriteLine(CommandLineResources.StartingDiscovery, OutputLevel.Information);
212+
if (Environment.GetEnvironmentVariable("VSTEST_MSBUILD_NOLOGO") != "1")
213+
{
214+
Output.WriteLine(CommandLineResources.StartingDiscovery, OutputLevel.Information);
215+
}
216+
213217
if (!StringUtils.IsNullOrEmpty(EqtTrace.LogFile))
214218
{
215219
Output.Information(false, CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile);

src/vstest.console/Processors/RunTestsArgumentProcessor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ public ArgumentProcessorResult Execute()
141141
throw new CommandLineException(CommandLineResources.MissingTestSourceFile);
142142
}
143143

144-
Output.WriteLine(CommandLineResources.StartingExecution, OutputLevel.Information);
144+
if (Environment.GetEnvironmentVariable("VSTEST_MSBUILD_NOLOGO") != "1")
145+
{
146+
Output.WriteLine(CommandLineResources.StartingExecution, OutputLevel.Information);
147+
}
148+
145149
if (!StringUtils.IsNullOrEmpty(EqtTrace.LogFile))
146150
{
147151
Output.Information(false, CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile);

0 commit comments

Comments
 (0)