提交 9fbed0b6 编写于 作者: J Jared Parsons

Re-arranging portable TestUtilities part 1

The TestUtilities project should be our portable unit test helper.  This is part one of rearranging our sources to reflect that reality.  I'm separating it out because it involves a significant code move that
will make the actual rework part harder to review.
上级 6167bb2d
......@@ -77,8 +77,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CscCore", "src\Compilers\CS
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VbcCore", "src\Compilers\VisualBasic\VbcCore\VbcCore.csproj", "{8CE3A581-2969-4864-A803-013E9D977C3A}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "TestUtilities.Shared", "src\Test\Utilities\Shared\TestUtilities.Shared.shproj", "{6FF42825-5464-4151-AC55-ED828168C192}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSBuildTaskTests", "src\Compilers\Core\MSBuildTaskTests\MSBuildTaskTests.csproj", "{1DFEA9C5-973C-4179-9B1B-0F32288E1EF2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server", "Server", "{E35DA3D1-16C0-4318-9187-6B664F12A870}"
......@@ -147,8 +145,6 @@ Global
src\Compilers\VisualBasic\BasicAnalyzerDriver\BasicAnalyzerDriver.projitems*{2523d0e6-df32-4a3e-8ae0-a19bffae2ef6}*SharedItemsImports = 4
src\Compilers\Server\ServerShared\ServerShared.projitems*{32691768-af9c-4cae-9d0f-10721091b9aa}*SharedItemsImports = 13
src\Compilers\Core\CommandLine\CommandLine.projitems*{4b45ca0c-03a0-400f-b454-3d4bcb16af38}*SharedItemsImports = 4
src\Test\Utilities\Shared\TestUtilities.projitems*{6ff42825-5464-4151-ac55-ed828168c192}*SharedItemsImports = 13
src\Test\Utilities\Shared\TestUtilities.projitems*{76c6f005-c89d-4348-bb4a-391898dbeb52}*SharedItemsImports = 4
src\Compilers\Core\CommandLine\CommandLine.projitems*{7ad4fe65-9a30-41a6-8004-aa8f89bcb7f3}*SharedItemsImports = 4
src\Compilers\Core\CommandLine\CommandLine.projitems*{8ce3a581-2969-4864-a803-013e9d977c3a}*SharedItemsImports = 4
src\Compilers\Core\CommandLine\CommandLine.projitems*{9508f118-f62e-4c16-a6f4-7c3b56e166ad}*SharedItemsImports = 4
......@@ -158,7 +154,6 @@ Global
src\Dependencies\PooledObjects\Microsoft.CodeAnalysis.PooledObjects.projitems*{afde6bea-5038-4a4a-a88e-dbd2e4088eed}*SharedItemsImports = 4
src\Compilers\CSharp\CSharpAnalyzerDriver\CSharpAnalyzerDriver.projitems*{b501a547-c911-4a05-ac6e-274a50dff30e}*SharedItemsImports = 4
src\Dependencies\PooledObjects\Microsoft.CodeAnalysis.PooledObjects.projitems*{c1930979-c824-496b-a630-70f5369a636f}*SharedItemsImports = 13
src\Test\Utilities\Shared\TestUtilities.projitems*{ccbd3438-3e84-40a9-83ad-533f23bcfca5}*SharedItemsImports = 4
src\Compilers\Core\AnalyzerDriver\AnalyzerDriver.projitems*{d0bc9be7-24f6-40ca-8dc6-fcb93bd44b34}*SharedItemsImports = 13
src\Dependencies\CodeAnalysis.Metadata\Microsoft.CodeAnalysis.Metadata.projitems*{d73adf7d-2c1c-42ae-b2ab-edc9497e4b71}*SharedItemsImports = 13
src\Compilers\Core\CommandLine\CommandLine.projitems*{e3cd2895-76a8-4d11-a316-ea67cb5ea42c}*SharedItemsImports = 4
......@@ -1241,7 +1236,6 @@ Global
{E58EE9D7-1239-4961-A0C1-F9EC3952C4C1} = {C65C6143-BED3-46E6-869E-9F0BE6E84C37}
{E3CD2895-76A8-4D11-A316-EA67CB5EA42C} = {32A48625-F0AD-419D-828B-A50BDABA38EA}
{8CE3A581-2969-4864-A803-013E9D977C3A} = {C65C6143-BED3-46E6-869E-9F0BE6E84C37}
{6FF42825-5464-4151-AC55-ED828168C192} = {6F016299-BA96-45BA-9BFF-6C0793979177}
{1DFEA9C5-973C-4179-9B1B-0F32288E1EF2} = {A41D1B99-F489-4C43-BBDF-96D61B19A6B9}
{AD6F474E-E6D4-4217-91F3-B7AF1BE31CCC} = {A41D1B99-F489-4C43-BBDF-96D61B19A6B9}
{06B26DCB-7A12-48EF-AE50-708593ABD05F} = {E35DA3D1-16C0-4318-9187-6B664F12A870}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.Test.Utilities
{
}
......@@ -4,7 +4,7 @@
<Import Project="..\..\..\..\build\Targets\Settings.props" />
<PropertyGroup>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
<ProjectGuid>{67ca3eee-37f1-4edf-bd9b-c11911748f37}</ProjectGuid>
<ProjectGuid>{67CA3EEE-37F1-4EDF-BD9B-C11911748F37}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>Roslyn.Test.Utilities.CoreClr</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
......@@ -67,7 +67,8 @@
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="Temp.cs" />
<Compile Include="CoreCLRRuntimeEnvironment.cs" />
<Compile Include="Exceptions.cs" />
</ItemGroup>
<Import Project="..\..\..\..\build\Targets\Imports.targets" />
</Project>
</Project>
\ No newline at end of file
......@@ -8,13 +8,6 @@
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public class SignatureDescription
{
public string FullyQualifiedTypeName { get; set; }
public string MemberName { get; set; }
public string ExpectedSignature { get; set; }
}
internal class MetadataSignatureUnitTestHelper
{
/// <summary>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.Emit;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public static class ModuleExtension
{
public static readonly string EXE = ".exe";
public static readonly string DLL = ".dll";
public static readonly string NETMODULE = ".netmodule";
}
[Serializable]
public struct ModuleDataId
{
public string SimpleName { get; }
public string FullName { get; }
public Guid Mvid { get; }
public ModuleDataId(Assembly assembly)
{
SimpleName = assembly.GetName().Name;
FullName = assembly.FullName;
Mvid = assembly.ManifestModule.ModuleVersionId;
}
public ModuleDataId(string simpleName, string fullName, Guid mvid)
{
SimpleName = simpleName;
FullName = fullName;
Mvid = mvid;
}
public override string ToString()
{
return $"{FullName} - {Mvid}";
}
}
[Serializable, DebuggerDisplay("{GetDebuggerDisplay()}")]
public sealed class ModuleData : ISerializable
{
public readonly ModuleDataId Id;
public readonly OutputKind Kind;
public readonly ImmutableArray<byte> Image;
public readonly ImmutableArray<byte> Pdb;
public readonly bool InMemoryModule;
public string SimpleName => Id.SimpleName;
public string FullName => Id.FullName;
public Guid Mvid => Id.Mvid;
public ModuleData(string netModuleName, ImmutableArray<byte> image, ImmutableArray<byte> pdb, bool inMemoryModule)
{
this.Id = new ModuleDataId(netModuleName, netModuleName, GetMvid(image));
this.Kind = OutputKind.NetModule;
this.Image = image;
this.Pdb = pdb;
this.InMemoryModule = inMemoryModule;
}
public ModuleData(AssemblyIdentity identity, OutputKind kind, ImmutableArray<byte> image, ImmutableArray<byte> pdb, bool inMemoryModule)
{
this.Id = new ModuleDataId(identity.Name, identity.GetDisplayName(), GetMvid(image));
this.Kind = kind;
this.Image = image;
this.Pdb = pdb;
this.InMemoryModule = inMemoryModule;
}
private static Guid GetMvid(ImmutableArray<byte> image)
{
using (var metadata = ModuleMetadata.CreateFromImage(image))
{
return metadata.GetModuleVersionId();
}
}
private string GetDebuggerDisplay()
{
return FullName + " {" + Mvid + "}";
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(Id), this.Id);
info.AddValue(nameof(Kind), (int)this.Kind);
info.AddByteArray(nameof(Image), this.Image);
info.AddByteArray(nameof(Pdb), this.Pdb);
info.AddValue(nameof(InMemoryModule), this.InMemoryModule);
}
private ModuleData(SerializationInfo info, StreamingContext context)
{
this.Id = (ModuleDataId)info.GetValue(nameof(Id), typeof(ModuleDataId));
this.Kind = (OutputKind)info.GetInt32(nameof(Kind));
this.Image = info.GetByteArray(nameof(Image));
this.Pdb = info.GetByteArray(nameof(Pdb));
this.InMemoryModule = info.GetBoolean(nameof(InMemoryModule));
}
}
}
......@@ -37,6 +37,10 @@
<Project>{afde6bea-5038-4a4a-a88e-dbd2e4088eed}</Project>
<Name>PdbUtilities</Name>
</ProjectReference>
<ProjectReference Include="..\Portable\TestUtilities.csproj">
<Project>{ccbd3438-3e84-40a9-83ad-533f23bcfca5}</Project>
<Name>TestUtilities</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
......@@ -90,7 +94,6 @@
<Compile Include="ProcessUtilities.cs" />
<Compile Include="AppDomainAssemblyCache.cs" />
<Compile Include="Exceptions.cs" />
<Compile Include="ModuleData.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="RuntimeAssemblyManager.cs" />
<Compile Include="SharedResourceHelpers.cs" />
......@@ -102,7 +105,6 @@
<Compile Include="HostedRuntimeEnvironment.cs" />
<Compile Include="MetadataSignatureHelper.cs" />
<Compile Include="MetadataSignatureUnitTestHelper.cs" />
<Compile Include="ProcessResult.cs" />
<Compile Include="..\Portable\ReflectionAssert.cs">
<Link>ReflectionAssert.cs</Link>
</Compile>
......@@ -164,6 +166,5 @@
<CustomToolNamespace>Roslyn.Test.Utilities</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>
<Import Project="..\Shared\TestUtilities.projitems" Label="Shared" />
<Import Project="..\..\..\..\build\Targets\Imports.targets" />
</Project>
\ No newline at end of file
......@@ -14,17 +14,17 @@
namespace Roslyn.Test.Utilities
{
public class RuntimeEnvironmentFactory
{
private static readonly Lazy<Func<IRuntimeEnvironment>> s_lazyFactory = new Lazy<Func<IRuntimeEnvironment>>(GetFactoryFunc);
internal static IRuntimeEnvironment Create(IEnumerable<ModuleData> additionalDependencies = null)
{
{
}
#if DNX
return new CoreCLRRuntimeEnvironment(additionalDependencies);
#else
return new HostedRuntimeEnvironment(additionalDependencies);
#endif
private static Func<IRuntimeEnvironment> GetFactoryFunc()
{
throw new Exception();
}
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public class SignatureDescription
{
public string FullyQualifiedTypeName { get; set; }
public string MemberName { get; set; }
public string ExpectedSignature { get; set; }
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.Emit;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public static class ModuleExtension
{
public static readonly string EXE = ".exe";
public static readonly string DLL = ".dll";
public static readonly string NETMODULE = ".netmodule";
}
public struct ModuleDataId
{
public string SimpleName { get; }
public string FullName { get; }
public Guid Mvid { get; }
public ModuleDataId(Assembly assembly)
{
SimpleName = assembly.GetName().Name;
FullName = assembly.FullName;
// TODO: Use S.R.M to load mvid
Mvid = new Guid();
}
public ModuleDataId(string simpleName, string fullName, Guid mvid)
{
SimpleName = simpleName;
FullName = fullName;
Mvid = mvid;
}
public override string ToString()
{
return $"{FullName} - {Mvid}";
}
}
[DebuggerDisplay("{GetDebuggerDisplay()}")]
public sealed class ModuleData
{
public readonly ModuleDataId Id;
public readonly OutputKind Kind;
public readonly ImmutableArray<byte> Image;
public readonly ImmutableArray<byte> Pdb;
public readonly bool InMemoryModule;
public string SimpleName => Id.SimpleName;
public string FullName => Id.FullName;
public Guid Mvid => Id.Mvid;
public ModuleData(string netModuleName, ImmutableArray<byte> image, ImmutableArray<byte> pdb, bool inMemoryModule)
{
this.Id = new ModuleDataId(netModuleName, netModuleName, GetMvid(image));
this.Kind = OutputKind.NetModule;
this.Image = image;
this.Pdb = pdb;
this.InMemoryModule = inMemoryModule;
}
public ModuleData(AssemblyIdentity identity, OutputKind kind, ImmutableArray<byte> image, ImmutableArray<byte> pdb, bool inMemoryModule)
{
this.Id = new ModuleDataId(identity.Name, identity.GetDisplayName(), GetMvid(image));
this.Kind = kind;
this.Image = image;
this.Pdb = pdb;
this.InMemoryModule = inMemoryModule;
}
private static Guid GetMvid(ImmutableArray<byte> image)
{
using (var metadata = ModuleMetadata.CreateFromImage(image))
{
return metadata.GetModuleVersionId();
}
}
private string GetDebuggerDisplay()
{
return FullName + " {" + Mvid + "}";
}
}
}
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册