Skip to content

Commit

Permalink
Merge branch 'refactoring-during-alc' into assemblyloadcontext
Browse files Browse the repository at this point in the history
  • Loading branch information
rainersigwald committed Nov 15, 2019
2 parents d775c0c + 863ec20 commit f38c2f2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/Build.UnitTests/BackEnd/TaskBuilder_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public void NullMetadataOnOutputItems()
</Target>
</Project>";

MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents);
MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents, _testOutput);
logger.AssertLogContains("[foo: ]");
}

Expand All @@ -513,7 +513,7 @@ public void NullMetadataOnLegacyOutputItems()
</Target>
</Project>";

MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents);
MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents, _testOutput);
logger.AssertLogContains("[foo: ]");
}

Expand Down Expand Up @@ -554,7 +554,7 @@ public void NullMetadataOnOutputItems_InlineTask()
</Target>
</Project>";

MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents);
MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents, _testOutput);
logger.AssertLogContains("[foo: ]");
}

Expand Down Expand Up @@ -595,7 +595,7 @@ public void NullMetadataOnLegacyOutputItems_InlineTask()
</Target>
</Project>";

MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents);
MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents, _testOutput);
logger.AssertLogContains("[foo: ]");
}
#endif
Expand Down
27 changes: 19 additions & 8 deletions src/Build.UnitTests/Evaluation/Evaluator_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4275,6 +4275,8 @@ public void VerifyDTDProcessingIsDisabled()
}

#if FEATURE_HTTP_LISTENER
private Exception _httpListenerThreadException = null;

/// <summary>
/// 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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
/// </summary>
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -74,4 +71,4 @@ private static void TranslateTargetFinishedEvent(ITranslator translator, TargetF
}
}
}
}
}
3 changes: 3 additions & 0 deletions src/Shared/AssemblyLoadInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.BackEnd;
using System.Diagnostics;

namespace Microsoft.Build.Shared
{
Expand Down Expand Up @@ -117,6 +118,7 @@ static public AssemblyLoadInfo FactoryForTranslation(ITranslator translator)
/// <summary>
/// Assembly represented by name
/// </summary>
[DebuggerDisplay("{AssemblyName}")]
private sealed class AssemblyLoadInfoWithName : AssemblyLoadInfo
{
/// <summary>
Expand Down Expand Up @@ -160,6 +162,7 @@ internal override string AssemblyLocation
/// <summary>
/// Assembly info that uses a file path
/// </summary>
[DebuggerDisplay("{AssemblyFile}")]
private sealed class AssemblyLoadInfoWithFile : AssemblyLoadInfo
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Shared/TypeLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -227,6 +228,7 @@ private LoadedType GetLoadedType(ConcurrentDictionary<Func<Type, object, bool>,
///
/// This type represents a combination of a type filter and an assemblyInfo object.
/// </summary>
[DebuggerDisplay("Types in {_assemblyLoadInfo} matching {_isDesiredType}")]
private class AssemblyInfoToLoadedTypes
{
/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Shared/UnitTests/ObjectModelHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,11 @@ string toolsVersion /* may be null */
/// <returns></returns>
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;
}
Expand All @@ -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();
}

/// <summary>
Expand Down
25 changes: 13 additions & 12 deletions src/Shared/UnitTests/TypeLoader_Dependencies_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using Microsoft.Build.Shared;
using Microsoft.Build.UnitTests.Shared;
using Shouldly;
using Xunit;

namespace Microsoft.Build.UnitTests
Expand All @@ -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);

Expand All @@ -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);
}
Expand All @@ -66,27 +67,27 @@ 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
{
File.Move(originalTaskDllPath, newTaskDllPath);
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;
Expand All @@ -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);
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
}

0 comments on commit f38c2f2

Please sign in to comment.