From 1c7278f8e457ab09bdd8d7c7897bc2daffbc66d4 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Fri, 19 Apr 2024 12:10:36 +0200 Subject: [PATCH 1/3] Get life proc output in integration tests --- src/UnitTests.Shared/RunnerUtilities.cs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/UnitTests.Shared/RunnerUtilities.cs b/src/UnitTests.Shared/RunnerUtilities.cs index 6310534a391..4794505b438 100644 --- a/src/UnitTests.Shared/RunnerUtilities.cs +++ b/src/UnitTests.Shared/RunnerUtilities.cs @@ -112,6 +112,7 @@ public static string RunProcessAndGetOutput(string process, string parameters, o { if (args != null) { + WriteOutput(args.Data); output += args.Data + "\r\n"; } }; @@ -119,9 +120,8 @@ public static string RunProcessAndGetOutput(string process, string parameters, o p.OutputDataReceived += handler; p.ErrorDataReceived += handler; - outputHelper?.WriteLine("Executing [{0} {1}]", process, parameters); - Console.WriteLine("Executing [{0} {1}]", process, parameters); - + WriteOutput( $"Executing [{process} {parameters}]"); + WriteOutput("==== OUTPUT ===="); p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); @@ -148,18 +148,17 @@ public static string RunProcessAndGetOutput(string process, string parameters, o successfulExit = p.ExitCode == 0; } - outputHelper?.WriteLine("==== OUTPUT ===="); - outputHelper?.WriteLine(output); - outputHelper?.WriteLine("Process ID is " + pid + "\r\n"); - outputHelper?.WriteLine("=============="); - - Console.WriteLine("==== OUTPUT ===="); - Console.WriteLine(output); - Console.WriteLine("Process ID is " + pid + "\r\n"); - Console.WriteLine("=============="); + WriteOutput("Process ID is " + pid + "\r\n"); + WriteOutput("=============="); output += "Process ID is " + pid + "\r\n"; return output; + + void WriteOutput(string data) + { + outputHelper?.WriteLine(data); + Console.WriteLine(data); + } } } } From 17b0f9c14e4a9a4f0e0cf1b268f36ff60038d5df Mon Sep 17 00:00:00 2001 From: Gang Wang Date: Mon, 22 Apr 2024 09:27:18 +0000 Subject: [PATCH 2/3] Pass test output helper to runner utilities --- src/BuildCheck.UnitTests/EndToEndTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BuildCheck.UnitTests/EndToEndTests.cs b/src/BuildCheck.UnitTests/EndToEndTests.cs index a0007d2c103..9351612060f 100644 --- a/src/BuildCheck.UnitTests/EndToEndTests.cs +++ b/src/BuildCheck.UnitTests/EndToEndTests.cs @@ -121,7 +121,7 @@ public void SampleAnalyzerIntegrationTest(bool buildInOutOfProcessNode, bool ana _env.SetEnvironmentVariable("MSBUILDLOGPROPERTIESANDITEMSAFTEREVALUATION", "1"); string output = RunnerUtilities.ExecBootstrapedMSBuild( $"{Path.GetFileName(projectFile.Path)} /m:1 -nr:False -restore" + - (analysisRequested ? " -analyze" : string.Empty), out bool success); + (analysisRequested ? " -analyze" : string.Empty), out bool success, false, _env.Output); _env.Output.WriteLine(output); success.ShouldBeTrue(); // The conflicting outputs warning appears - but only if analysis was requested From 2ac6100bc0db2b24018de9e028a8fee88f9896b3 Mon Sep 17 00:00:00 2001 From: Gang Wang Date: Mon, 22 Apr 2024 11:09:07 +0000 Subject: [PATCH 3/3] Fix the crash caused by null data of event arguments --- src/UnitTests.Shared/RunnerUtilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UnitTests.Shared/RunnerUtilities.cs b/src/UnitTests.Shared/RunnerUtilities.cs index 4794505b438..a61f1a9fb4c 100644 --- a/src/UnitTests.Shared/RunnerUtilities.cs +++ b/src/UnitTests.Shared/RunnerUtilities.cs @@ -110,7 +110,7 @@ public static string RunProcessAndGetOutput(string process, string parameters, o { DataReceivedEventHandler handler = delegate (object sender, DataReceivedEventArgs args) { - if (args != null) + if (args != null && args.Data != null) { WriteOutput(args.Data); output += args.Data + "\r\n";