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

Adjust tests with terminal logger enabled #9995

Merged
merged 4 commits into from
Apr 16, 2024

Conversation

GangWang01
Copy link
Member

Fixes #9796

Context

With terminal logger enabled by SET MSBUILDLIVELOGGER=auto, current tests has the following problems.

  • Message is ignored by terminal logger currently and this causes tests depending on the message fail. Though Some way to opt specific messages into printing in TerminalLogger #9667 could get messages ptinted in terminal logger, it is a way to opt. To make messages output in console logger and terminal logger both, we need the workaround for printing messages in terminal logger. Affected tests: Microsoft.Build.Engine.UnitTests.MSBuildServer_Tests.
  • The environment variable MSBUILDLIVELOGGER/MSBUILDTERMINALLOGGER affects tests for these two environment variables. Affected tests: Microsoft.Build.UnitTests.TerminalLoggerConfiguration_Tests.TerminalLoggerOnByEnv.
  • Enabling terminal logger by the environment variable gets extra more build events than other loggers by

    msbuild/src/MSBuild/XMake.cs

    Lines 2854 to 2855 in bb7846e

    s_globalMessagesToLogInBuildLoggers.Add(
    new BuildManager.DeferredBuildMessage($"The environment variable MSBUILDTERMINALLOGGER was set to {terminalLoggerArg}.", MessageImportance.Low));
    . Affected test: Microsoft.Build.UnitTests.TerminalLogger_Tests.TestTerminalLoggerTogetherWithOtherLoggers.

In addition, cleaning up created TestEnvironment should revert variants in reverse order.

Changes Made

  • For Message, use the workaround adding --interactive for terminal logger to make messages output in console logger and terminal logger both.
  • Clear pre-setting environment variables of terminal logger to affect the tests.
  • Reverting variants in reverse order while cleaning up created TestEnvironment.

Testing

Run existing tests locally with setting the environment variable. Also verified in CI through #9957.

Notes

@GangWang01 GangWang01 marked this pull request as ready for review April 11, 2024 09:17
@GangWang01 GangWang01 merged commit 3671494 into dotnet:main Apr 16, 2024
9 checks passed
@GangWang01 GangWang01 deleted the tests-with-tl-enabled branch April 16, 2024 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Several MSBuild unit tests are failing with terminal logger enabled
3 participants