Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKrivanek committed Jun 18, 2024
1 parent 2f36633 commit 38ed72a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Build.UnitTests/BackEnd/BuildManager_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -760,14 +760,16 @@ public void OutOfProcNodeForwardCertainpropertiesAlsoGetResultsFromCache()
_env.SetEnvironmentVariable("MsBuildForwardPropertiesFromChild", "InitialProperty3;IAMNOTREAL");
_env.SetEnvironmentVariable("MSBUILDNOINPROCNODE", "1");

_env.SetEnvironmentVariable("MSBUILDLOGPROPERTIESANDITEMSAFTEREVALUATION", "0");

var project = CreateProject(contents, null, _projectCollection, false);
var data = new BuildRequestData(project.FullPath, new Dictionary<string, string>(),
MSBuildDefaultToolsVersion, Array.Empty<string>(), null);

BuildResult result = _buildManager.Build(_parameters, data);
Assert.Equal(BuildResultCode.Success, result.OverallResult);
_logger.AssertLogContains("[success]");
Assert.Equal(3, _logger.EvaluationFinishedEvents.Count);
Assert.Equal(3, _logger.ProjectStartedEvents.Count);

ProjectStartedEventArgs projectStartedEvent = _logger.ProjectStartedEvents[1];

Expand All @@ -785,7 +787,8 @@ public void OutOfProcNodeForwardCertainpropertiesAlsoGetResultsFromCache()
Assert.Equal("InitialProperty3", propertyValue);

projectStartedEvent = _logger.ProjectStartedEvents[2];
Assert.Null(projectStartedEvent.Properties);
properties = ExtractProjectStartedPropertyList(projectStartedEvent.Properties);
(properties == null || properties.Count == 0).ShouldBeTrue();
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Shared/UnitTests/TestAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public MSBuildTestAssemblyFixture()
var runningTestsField = testInfoType.GetField("s_runningTests", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
runningTestsField.SetValue(null, true);

// Set the field in BuildEnvironmentState - as it might have been already preintialized by the data preparation of data driven tests
testInfoType = frameworkAssembly.GetType("Microsoft.Build.Framework.BuildEnvironmentState");
runningTestsField = testInfoType.GetField("s_runningTests", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
runningTestsField.SetValue(null, true);


// Note: build error files will be initialized in test environments for particular tests, also we don't have output to report error files into anyway...
_testEnvironment = TestEnvironment.Create(output: null, ignoreBuildErrorFiles: true);

Expand Down

0 comments on commit 38ed72a

Please sign in to comment.