diff --git a/src/Build.UnitTests/BackEnd/TaskBuilder_Tests.cs b/src/Build.UnitTests/BackEnd/TaskBuilder_Tests.cs index cccff4990ea..002c0128256 100644 --- a/src/Build.UnitTests/BackEnd/TaskBuilder_Tests.cs +++ b/src/Build.UnitTests/BackEnd/TaskBuilder_Tests.cs @@ -488,7 +488,7 @@ public void NullMetadataOnOutputItems() "; - MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents); + MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents, _testOutput); logger.AssertLogContains("[foo: ]"); } @@ -513,7 +513,7 @@ public void NullMetadataOnLegacyOutputItems() "; - MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents); + MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents, _testOutput); logger.AssertLogContains("[foo: ]"); } @@ -554,7 +554,7 @@ public void NullMetadataOnOutputItems_InlineTask() "; - MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents); + MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents, _testOutput); logger.AssertLogContains("[foo: ]"); } @@ -595,7 +595,7 @@ public void NullMetadataOnLegacyOutputItems_InlineTask() "; - MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents); + MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents, _testOutput); logger.AssertLogContains("[foo: ]"); } #endif diff --git a/src/Build.UnitTests/Evaluation/Evaluator_Tests.cs b/src/Build.UnitTests/Evaluation/Evaluator_Tests.cs index 18cf50d67cc..272dba2e0fb 100644 --- a/src/Build.UnitTests/Evaluation/Evaluator_Tests.cs +++ b/src/Build.UnitTests/Evaluation/Evaluator_Tests.cs @@ -4275,6 +4275,8 @@ public void VerifyDTDProcessingIsDisabled() } #if FEATURE_HTTP_LISTENER + private Exception _httpListenerThreadException = null; + /// /// Verify that DTD processing is disabled when loading a project /// We create an HTTP server that waits for a request and load a project containing DTD code making reference to a fictitious file in the server. @@ -4326,7 +4328,8 @@ public void VerifyDTDProcessingIsDisabled2() Thread.Sleep(500); // Expect server to be alive and hung up unless a request originating from DTD processing was sent - Assert.True(t.IsAlive); + _httpListenerThreadException.ShouldBeNull(); + t.IsAlive.ShouldBeTrue(); } } #endif @@ -4560,16 +4563,24 @@ public void VerifyMSBuildLogsAMessageWhenLocalPropertyCannotOverrideValueOfGloba /// If a connection request is received, this thread will terminate, if not, the server will remain alive until /// "VerifyDTDProcessingIsDisabled" returns. /// - static private void HttpServerThread() + private void HttpServerThread() { - HttpListener listener = new HttpListener(); - listener.Prefixes.Add("http://localhost:51111/"); - listener.Start(); + try + { + HttpListener listener = new HttpListener(); + listener.Prefixes.Add("http://localhost:51111/"); + listener.Start(); - HttpListenerContext context = listener.GetContext(); + HttpListenerContext context = listener.GetContext(); - // if reached this point it means the server answered a request triggered during DTD processing - listener.Stop(); + // if reached this point it means the server answered a request triggered during DTD processing + listener.Stop(); + } + catch (Exception e) + { + // don't crash the test process; save the exception and check for it in the test + _httpListenerThreadException = e; + } } #endif diff --git a/src/Build/BackEnd/Components/Communications/LogMessagePacket.cs b/src/Build/BackEnd/Components/Communications/LogMessagePacket.cs index 0f8c519f635..83c02205f23 100644 --- a/src/Build/BackEnd/Components/Communications/LogMessagePacket.cs +++ b/src/Build/BackEnd/Components/Communications/LogMessagePacket.cs @@ -10,9 +10,6 @@ using Microsoft.Build.Framework; using Microsoft.Build.Shared; using TaskItem = Microsoft.Build.Execution.ProjectItemInstance.TaskItem; -#if FEATURE_APPDOMAIN -using TaskEngineAssemblyResolver = Microsoft.Build.BackEnd.Logging.TaskEngineAssemblyResolver; -#endif namespace Microsoft.Build.BackEnd { @@ -74,4 +71,4 @@ private static void TranslateTargetFinishedEvent(ITranslator translator, TargetF } } } -} \ No newline at end of file +} diff --git a/src/Shared/AssemblyLoadInfo.cs b/src/Shared/AssemblyLoadInfo.cs index 15d468b99b4..8284c1a1f5e 100644 --- a/src/Shared/AssemblyLoadInfo.cs +++ b/src/Shared/AssemblyLoadInfo.cs @@ -5,6 +5,7 @@ using System.IO; using Microsoft.Build.Framework; using Microsoft.Build.BackEnd; +using System.Diagnostics; namespace Microsoft.Build.Shared { @@ -117,6 +118,7 @@ static public AssemblyLoadInfo FactoryForTranslation(ITranslator translator) /// /// Assembly represented by name /// + [DebuggerDisplay("{AssemblyName}")] private sealed class AssemblyLoadInfoWithName : AssemblyLoadInfo { /// @@ -160,6 +162,7 @@ internal override string AssemblyLocation /// /// Assembly info that uses a file path /// + [DebuggerDisplay("{AssemblyFile}")] private sealed class AssemblyLoadInfoWithFile : AssemblyLoadInfo { /// diff --git a/src/Shared/TypeLoader.cs b/src/Shared/TypeLoader.cs index 53ed7e01fb3..d0cb1bf1aa6 100644 --- a/src/Shared/TypeLoader.cs +++ b/src/Shared/TypeLoader.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Reflection; @@ -248,6 +249,7 @@ private LoadedType GetLoadedType(ConcurrentDictionary, /// /// This type represents a combination of a type filter and an assemblyInfo object. /// + [DebuggerDisplay("Types in {_assemblyLoadInfo} matching {_isDesiredType}")] private class AssemblyInfoToLoadedTypes { /// diff --git a/src/Shared/UnitTests/ObjectModelHelpers.cs b/src/Shared/UnitTests/ObjectModelHelpers.cs index d9b81efcb2f..55e60e857e4 100644 --- a/src/Shared/UnitTests/ObjectModelHelpers.cs +++ b/src/Shared/UnitTests/ObjectModelHelpers.cs @@ -695,10 +695,11 @@ string toolsVersion /* may be null */ /// internal static MockLogger BuildProjectExpectSuccess ( - string projectContents + string projectContents, + ITestOutputHelper testOutputHelper = null ) { - MockLogger logger = new MockLogger(); + MockLogger logger = new MockLogger(testOutputHelper); BuildProjectExpectSuccess(projectContents, logger); return logger; } @@ -710,8 +711,7 @@ params ILogger[] loggers ) { Project project = CreateInMemoryProject(projectContents, logger: null); // logger is null so we take care of loggers ourselves - bool success = project.Build(loggers); - Assert.True(success); + project.Build(loggers).ShouldBeTrue(); } /// diff --git a/src/Shared/UnitTests/TypeLoader_Dependencies_Tests.cs b/src/Shared/UnitTests/TypeLoader_Dependencies_Tests.cs index 03f9b0e9b0f..26cf742803d 100644 --- a/src/Shared/UnitTests/TypeLoader_Dependencies_Tests.cs +++ b/src/Shared/UnitTests/TypeLoader_Dependencies_Tests.cs @@ -6,6 +6,7 @@ using System.IO; using Microsoft.Build.Shared; using Microsoft.Build.UnitTests.Shared; +using Shouldly; using Xunit; namespace Microsoft.Build.UnitTests @@ -26,7 +27,7 @@ public void LoadAssemblyAndDependency_InsideProjectFolder() bool successfulExit; string output = RunnerUtilities.ExecMSBuild(projectFilePath + " /v:diag", out successfulExit); - Assert.True(successfulExit); + successfulExit.ShouldBeTrue(output); string dllPath = Path.Combine(dir.Path, TaskDllFileName); @@ -46,7 +47,7 @@ public void LoadAssemblyAndDependency_OutsideProjectFolder() bool successfulExit; string output = RunnerUtilities.ExecMSBuild(projectFilePath + " /v:diag /p:AssemblyPath=" + newTaskDllPath, out successfulExit); - Assert.True(successfulExit); + successfulExit.ShouldBeTrue(output); CheckIfCorrectAssemblyLoaded(output, newTaskDllPath); } @@ -66,16 +67,16 @@ private string MoveOrCopyDllsToTempDir(string originalDirectory, bool copy) var newTaskDllPath = Path.Combine(temporaryDirectory, TaskDllFileName); var newDependencyDllPath = Path.Combine(temporaryDirectory, DependencyDllFileName); - Assert.True(File.Exists(originalTaskDllPath)); - Assert.True(File.Exists(originalDependencyDllPath)); + File.Exists(originalTaskDllPath).ShouldBeTrue(); + File.Exists(originalDependencyDllPath).ShouldBeTrue(); if (copy) { File.Copy(originalTaskDllPath, newTaskDllPath); File.Copy(originalDependencyDllPath, newDependencyDllPath); - Assert.True(File.Exists(newTaskDllPath)); - Assert.True(File.Exists(newDependencyDllPath)); + File.Exists(newTaskDllPath).ShouldBeTrue(); + File.Exists(newDependencyDllPath).ShouldBeTrue(); } else { @@ -83,10 +84,10 @@ private string MoveOrCopyDllsToTempDir(string originalDirectory, bool copy) File.Move(originalDependencyDllPath, newDependencyDllPath); - Assert.True(File.Exists(newTaskDllPath)); - Assert.True(File.Exists(newDependencyDllPath)); - Assert.False(File.Exists(originalTaskDllPath)); - Assert.False(File.Exists(originalDependencyDllPath)); + File.Exists(newTaskDllPath).ShouldBeTrue(); + File.Exists(newDependencyDllPath).ShouldBeTrue(); + File.Exists(originalTaskDllPath).ShouldBeFalse(); + File.Exists(originalDependencyDllPath).ShouldBeFalse(); } return temporaryDirectory; @@ -98,11 +99,11 @@ private void CheckIfCorrectAssemblyLoaded(string scriptOutput, string expectedAs if (expectedSuccess) { - Assert.Contains(successfulMessage, scriptOutput, StringComparison.OrdinalIgnoreCase); + scriptOutput.ShouldContain(successfulMessage, Case.Insensitive); } else { - Assert.DoesNotContain(successfulMessage, scriptOutput, StringComparison.OrdinalIgnoreCase); + scriptOutput.ShouldNotContain(successfulMessage, Case.Insensitive); } } } diff --git a/src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs b/src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs index 2a59c952462..aebcd578141 100644 --- a/src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs +++ b/src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs @@ -4,7 +4,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using Microsoft.Build.Framework; +using Microsoft.Build.Shared; using Microsoft.Build.UnitTests; using Microsoft.Build.Utilities; using Shouldly; @@ -732,8 +734,16 @@ private void TryLoadTaskBodyAndExpectSuccess( if (expectedSourceCode != null) { - taskInfo.SourceCode.ShouldBe(expectedSourceCode, StringCompareShould.IgnoreLineEndings); + NormalizeRuntime(taskInfo.SourceCode) + .ShouldBe(NormalizeRuntime(expectedSourceCode), StringCompareShould.IgnoreLineEndings); } } + + private static readonly Regex RuntimeVersionLine = new Regex("Runtime Version:.*"); + + private static string NormalizeRuntime(string input) + { + return RuntimeVersionLine.Replace(input, "Runtime Version:SOMETHING"); + } } }