Skip to content

Commit 3671494

Browse files
authored
Adjust tests with terminal logger enabled (#9995)
* Make terminal logger print messages in the tests * Clear the environment variables about terminal logger during instantiating TestEnvironment to avoid affecting the tests * Reverting variants should be in reverse order to get back to original state * Improve resetting variants in reverse order to get back to original state
1 parent 4ec9575 commit 3671494

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public TerminalLoggerConfiguration_Tests(ITestOutputHelper output)
2828
{
2929
_env = TestEnvironment.Create(output);
3030

31-
// Ignore environment variables that may have been set by the environment where the tests are running.
32-
_env.SetEnvironmentVariable("MSBUILDLIVELOGGER", null);
33-
_env.SetEnvironmentVariable("MSBUILDTERMINALLOGGER", null);
34-
3531
TransientTestFolder logFolder = _env.CreateFolder(createFolder: true);
3632
TransientTestFile projectFile = _env.CreateFile(logFolder, "myProj.proj", $"""
3733
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Hello">

src/MSBuild.UnitTests/MSBuildServer_Tests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class MSBuildServer_Tests : IDisposable
6868
<ProcessIdTask>
6969
<Output PropertyName=""PID"" TaskParameter=""Pid"" />
7070
</ProcessIdTask>
71-
<Message Text=""Server ID is $(PID)"" Importance=""High"" />
71+
<Message Text=""[Work around Github issue #9667 with --interactive]Server ID is $(PID)"" Importance=""High"" />
7272
</Target>
7373
</Project>";
7474
private static string sleepingTaskContentsFormat = @$"
@@ -313,8 +313,8 @@ public void PropertyMSBuildStartupDirectoryOnServer()
313313
<ProcessIdTask>
314314
<Output PropertyName=""PID"" TaskParameter=""Pid"" />
315315
</ProcessIdTask>
316-
<Message Text=""Server ID is $(PID)"" Importance=""High"" />
317-
<Message Text="":MSBuildStartupDirectory:$(MSBuildStartupDirectory):"" Importance=""high"" />
316+
<Message Text=""[Work around Github issue #9667 with --interactive]Server ID is $(PID)"" Importance=""High"" />
317+
<Message Text=""[Work around Github issue #9667 with --interactive]:MSBuildStartupDirectory:$(MSBuildStartupDirectory):"" Importance=""high"" />
318318
</Target>
319319
</Project>";
320320

src/UnitTests.Shared/TestEnvironment.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public static TestEnvironment Create(ITestOutputHelper output = null, bool ignor
5353
env.WithInvariant(new BuildFailureLogInvariant());
5454
}
5555

56+
// Clear these two environment variables first in case pre-setting affects the test.
57+
env.SetEnvironmentVariable("MSBUILDLIVELOGGER", null);
58+
env.SetEnvironmentVariable("MSBUILDTERMINALLOGGER", null);
59+
5660
return env;
5761
}
5862

@@ -83,10 +87,10 @@ private void Cleanup()
8387
{
8488
_disposed = true;
8589

86-
// Reset test variants
87-
foreach (var variant in _variants)
90+
// Reset test variants in reverse order to get back to original state.
91+
for (int i = _variants.Count - 1; i >= 0; i--)
8892
{
89-
variant.Revert();
93+
_variants[i].Revert();
9094
}
9195

9296
// Assert invariants

0 commit comments

Comments
 (0)