Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get life proc output in integration tests #10040

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BuildCheck.UnitTests/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 12 additions & 13 deletions src/UnitTests.Shared/RunnerUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ 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";
}
};

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();
Expand All @@ -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);
}
}
}
}