Skip to content

Commit

Permalink
Move tests to net5.0 reference assemblies (#50486)
Browse files Browse the repository at this point in the history
* Move tests to net5.0 reference assemblies

This moves our tests to use the net5.0 reference assemblies.
  • Loading branch information
jaredpar authored Jan 22, 2021
1 parent a5e6335 commit 3323bf3
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 55 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<MicrosoftMSXMLVersion>8.0.0</MicrosoftMSXMLVersion>
<MicrosoftNETBuildExtensionsVersion>2.2.101</MicrosoftNETBuildExtensionsVersion>
<MicrosoftNETCorePlatformsVersion>2.1.2</MicrosoftNETCorePlatformsVersion>
<MicrosoftNETCoreAppRefVersion>3.1.0</MicrosoftNETCoreAppRefVersion>
<MicrosoftNETCoreAppRefVersion>5.0.0</MicrosoftNETCoreAppRefVersion>
<MicrosoftNETFrameworkReferenceAssembliesnet461Version>1.0.0</MicrosoftNETFrameworkReferenceAssembliesnet461Version>
<MicrosoftNETFrameworkReferenceAssembliesnet451Version>1.0.0</MicrosoftNETFrameworkReferenceAssembliesnet451Version>
<MicrosoftNETFrameworkReferenceAssembliesnet40Version>1.0.0</MicrosoftNETFrameworkReferenceAssembliesnet40Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ interface J { }

CheckEncLog(reader2,
Row(3, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
Row(8, TableIndex.TypeRef, EditAndContinueOperation.Default),
Row(10, TableIndex.TypeRef, EditAndContinueOperation.Default),
Row(2, TableIndex.Event, EditAndContinueOperation.Default),
Row(3, TableIndex.Event, EditAndContinueOperation.Default),
Row(1, TableIndex.Field, EditAndContinueOperation.Default),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141722,10 +141722,7 @@ public void Test()
}
}";
var comp = CreateCompilation(
new[]
{
source, MemberNotNullAttributeDefinition
},
new[] { source },
options: WithNonNullTypesTrue(),
targetFramework: TargetFramework.NetCoreApp,
parseOptions: TestOptions.Regular9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void PresentCorLib()

var knownMissingTypes = new HashSet<int>()
{
(int)SpecialType.System_Runtime_CompilerServices_PreserveBaseOverridesAttribute
};

for (int i = 1; i <= (int)SpecialType.Count; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#nullable disable

using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE;
Expand Down Expand Up @@ -54945,31 +54948,44 @@ private static string BuildAssemblyExternClause(PortableExecutableReference refe
Version version = assemblyIdentity.Version;
var publicKeyToken = assemblyIdentity.PublicKeyToken;

return @"
.assembly extern " + assemblyIdentity.Name + @"
{
.publickeytoken = (" +
publicKeyToken[0].ToString("X2") +
publicKeyToken[1].ToString("X2") +
publicKeyToken[2].ToString("X2") +
publicKeyToken[3].ToString("X2") +
publicKeyToken[4].ToString("X2") +
publicKeyToken[5].ToString("X2") +
publicKeyToken[6].ToString("X2") +
publicKeyToken[7].ToString("X2") +
@" )
.ver " + $"{version.Major}:{version.Minor}:{version.Build}:{version.Revision}" + @"
}
if (publicKeyToken.Length > 0)
{
return @"
.assembly extern " + assemblyIdentity.Name + @"
{
.publickeytoken = (" +
publicKeyToken[0].ToString("X2") +
publicKeyToken[1].ToString("X2") +
publicKeyToken[2].ToString("X2") +
publicKeyToken[3].ToString("X2") +
publicKeyToken[4].ToString("X2") +
publicKeyToken[5].ToString("X2") +
publicKeyToken[6].ToString("X2") +
publicKeyToken[7].ToString("X2") +
@" )
.ver " + $"{version.Major}:{version.Minor}:{version.Build}:{version.Revision}" + @"
}
";
}
else
{
return @"
.assembly extern " + assemblyIdentity.Name + @"
{
.ver " + $"{version.Major}:{version.Minor}:{version.Build}:{version.Revision}" + @"
}
";
}
}

[Fact]
[WorkItem(36532, "https://github.com/dotnet/roslyn/issues/36532")]
public void WindowsRuntimeEvent_01()
{
var windowsRuntimeRef = CompilationExtensions.CreateWindowsRuntimeMetadataReference();
var ilSource =
BuildAssemblyExternClause(TestMetadata.NetCoreApp.SystemRuntime) +
BuildAssemblyExternClause(TestMetadata.NetCoreApp.SystemRuntimeInteropServicesWindowsRuntime) +
BuildAssemblyExternClause(windowsRuntimeRef) +
@"
.class public auto ansi sealed Event
extends [System.Runtime]System.MulticastDelegate
Expand Down Expand Up @@ -55052,7 +55068,7 @@ class C1 : I1, Interface<int>
";
foreach (var options in new[] { TestOptions.DebugDll, TestOptions.DebugWinMD })
{
var comp = CreateCompilationWithIL(source, ilSource, options: options, targetFramework: TargetFramework.NetCoreApp);
var comp = CreateCompilationWithIL(source, ilSource, options: options, targetFramework: TargetFramework.NetCoreApp, references: new[] { windowsRuntimeRef });

void Validate(ModuleSymbol m)
{
Expand Down Expand Up @@ -55125,7 +55141,7 @@ class C1 : I1
{
}
";
var comp = CreateCompilation(source, options: TestOptions.DebugWinMD, targetFramework: TargetFramework.NetCoreApp);
var comp = CreateCompilation(source, options: TestOptions.DebugWinMD, targetFramework: TargetFramework.NetCoreApp, references: new[] { CompilationExtensions.CreateWindowsRuntimeMetadataReference() });

void Validate(ModuleSymbol m)
{
Expand Down Expand Up @@ -55178,7 +55194,7 @@ event System.Action Interface.WinRT
class C1 : I1, Interface
{}
";
var comp = CreateCompilation(source, options: TestOptions.DebugWinMD, targetFramework: TargetFramework.NetCoreApp);
var comp = CreateCompilation(source, options: TestOptions.DebugWinMD, targetFramework: TargetFramework.NetCoreApp, references: new[] { CompilationExtensions.CreateWindowsRuntimeMetadataReference() });

void Validate(ModuleSymbol m)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ interface i
[ModuleInitializer]
internal void M2() { }
}
namespace System.Runtime.CompilerServices { class ModuleInitializerAttribute : System.Attribute { } }
";
var compilation = CreateCompilation(source, parseOptions: s_parseOptions, targetFramework: TargetFramework.NetCoreApp);
compilation.VerifyEmitDiagnostics(
Expand Down
1 change: 0 additions & 1 deletion src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void SpecialTypeIsValueType()

var knownMissingTypes = new HashSet<SpecialType>()
{
SpecialType.System_Runtime_CompilerServices_PreserveBaseOverridesAttribute
};

for (var specialType = SpecialType.None + 1; specialType <= SpecialType.Count; specialType++)
Expand Down
67 changes: 67 additions & 0 deletions src/Compilers/Test/Core/Compilation/CompilationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.FlowAnalysis;
using Microsoft.CodeAnalysis.Operations;
Expand Down Expand Up @@ -96,6 +97,13 @@ public static MemoryStream EmitToStream(this Compilation compilation, EmitOption
}

public static MetadataReference EmitToImageReference(
this Compilation comp,
EmitOptions options = null,
bool embedInteropTypes = false,
ImmutableArray<string> aliases = default,
DiagnosticDescription[] expectedWarnings = null) => EmitToPortableExecutableReference(comp, options, embedInteropTypes, aliases, expectedWarnings);

public static PortableExecutableReference EmitToPortableExecutableReference(
this Compilation comp,
EmitOptions options = null,
bool embedInteropTypes = false,
Expand Down Expand Up @@ -361,5 +369,64 @@ void checkControlFlowGraph(IOperation root)
}
}
}

/// <summary>
/// The reference assembly System.Runtime.InteropServices.WindowsRuntime was removed in net5.0. This builds
/// up <see cref="CompilationReference"/> which contains all of the well known types that were used from that
/// reference by the compiler.
/// </summary>
public static PortableExecutableReference CreateWindowsRuntimeMetadataReference()
{
var source = @"
namespace System.Runtime.InteropServices.WindowsRuntime
{
public struct EventRegistrationToken { }
public sealed class EventRegistrationTokenTable<T> where T : class
{
public T InvocationList { get; set; }
public static EventRegistrationTokenTable<T> GetOrCreateEventRegistrationTokenTable(ref EventRegistrationTokenTable<T> refEventTable)
{
throw null;
}
public void RemoveEventHandler(EventRegistrationToken token)
{
}
public void RemoveEventHandler(T handler)
{
}
}
public static class WindowsRuntimeMarshal
{
public static void AddEventHandler<T>(Func<T, EventRegistrationToken> addMethod, Action<EventRegistrationToken> removeMethod, T handler)
{
}
public static void RemoveAllEventHandlers(Action<EventRegistrationToken> removeMethod)
{
}
public static void RemoveEventHandler<T>(Action<EventRegistrationToken> removeMethod, T handler)
{
}
}
}
";

// The actual System.Runtime.InteropServices.WindowsRuntime DLL has a public key of
// b03f5f7f11d50a3a and version 4.0.4.0. The compiler just looks at these via
// WellKnownTypes and WellKnownMembers so it can be safely skipped here.
var compilation = CSharpCompilation.Create(
"System.Runtime.InteropServices.WindowsRuntime",
new[] { CSharpSyntaxTree.ParseText(source) },
references: TargetFrameworkUtil.GetReferences(TargetFramework.NetCoreApp),
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
compilation.VerifyEmitDiagnostics();
return compilation.EmitToPortableExecutableReference();
}
}
}
3 changes: 1 addition & 2 deletions src/Compilers/Test/Core/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Add-TargetFramework "Net461" '$(PkgMicrosoft_NETFramework_ReferenceAssemblies_ne
'Microsoft.VisualBasic.dll'
)

Add-TargetFramework "NetCoreApp" '$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1' @(
Add-TargetFramework "NetCoreApp" '$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0' @(
'mscorlib.dll',
'System.dll',
'System.Core.dll',
Expand All @@ -154,7 +154,6 @@ Add-TargetFramework "NetCoreApp" '$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp
'System.Linq.Expressions.dll',
'System.Runtime.dll',
'System.Runtime.InteropServices.dll',
'System.Runtime.InteropServices.WindowsRuntime.dll',
'System.Threading.Tasks.dll',
'netstandard.dll',
'Microsoft.CSharp.dll',
Expand Down
3 changes: 0 additions & 3 deletions src/Compilers/Test/Core/Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ public static class ResourcesNetCoreApp
public static byte[] SystemRuntime => ResourceLoader.GetOrCreateResource(ref _SystemRuntime, "netcoreapp.System.Runtime.dll");
private static byte[] _SystemRuntimeInteropServices;
public static byte[] SystemRuntimeInteropServices => ResourceLoader.GetOrCreateResource(ref _SystemRuntimeInteropServices, "netcoreapp.System.Runtime.InteropServices.dll");
private static byte[] _SystemRuntimeInteropServicesWindowsRuntime;
public static byte[] SystemRuntimeInteropServicesWindowsRuntime => ResourceLoader.GetOrCreateResource(ref _SystemRuntimeInteropServicesWindowsRuntime, "netcoreapp.System.Runtime.InteropServices.WindowsRuntime.dll");
private static byte[] _SystemThreadingTasks;
public static byte[] SystemThreadingTasks => ResourceLoader.GetOrCreateResource(ref _SystemThreadingTasks, "netcoreapp.System.Threading.Tasks.dll");
private static byte[] _netstandard;
Expand All @@ -198,7 +196,6 @@ public static class NetCoreApp
public static PortableExecutableReference SystemLinqExpressions { get; } = AssemblyMetadata.CreateFromImage(ResourcesNetCoreApp.SystemLinqExpressions).GetReference(display: "System.Linq.Expressions.dll (netcoreapp)");
public static PortableExecutableReference SystemRuntime { get; } = AssemblyMetadata.CreateFromImage(ResourcesNetCoreApp.SystemRuntime).GetReference(display: "System.Runtime.dll (netcoreapp)");
public static PortableExecutableReference SystemRuntimeInteropServices { get; } = AssemblyMetadata.CreateFromImage(ResourcesNetCoreApp.SystemRuntimeInteropServices).GetReference(display: "System.Runtime.InteropServices.dll (netcoreapp)");
public static PortableExecutableReference SystemRuntimeInteropServicesWindowsRuntime { get; } = AssemblyMetadata.CreateFromImage(ResourcesNetCoreApp.SystemRuntimeInteropServicesWindowsRuntime).GetReference(display: "System.Runtime.InteropServices.WindowsRuntime.dll (netcoreapp)");
public static PortableExecutableReference SystemThreadingTasks { get; } = AssemblyMetadata.CreateFromImage(ResourcesNetCoreApp.SystemThreadingTasks).GetReference(display: "System.Threading.Tasks.dll (netcoreapp)");
public static PortableExecutableReference netstandard { get; } = AssemblyMetadata.CreateFromImage(ResourcesNetCoreApp.netstandard).GetReference(display: "netstandard.dll (netcoreapp)");
public static PortableExecutableReference MicrosoftCSharp { get; } = AssemblyMetadata.CreateFromImage(ResourcesNetCoreApp.MicrosoftCSharp).GetReference(display: "Microsoft.CSharp.dll (netcoreapp)");
Expand Down
30 changes: 13 additions & 17 deletions src/Compilers/Test/Core/Generated.targets
Original file line number Diff line number Diff line change
Expand Up @@ -152,59 +152,55 @@
<LogicalName>net461.Microsoft.VisualBasic.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\net461\Microsoft.VisualBasic.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\mscorlib.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\mscorlib.dll">
<LogicalName>netcoreapp.mscorlib.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\mscorlib.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\System.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\System.dll">
<LogicalName>netcoreapp.System.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\System.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\System.Core.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\System.Core.dll">
<LogicalName>netcoreapp.System.Core.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\System.Core.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\System.Collections.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\System.Collections.dll">
<LogicalName>netcoreapp.System.Collections.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\System.Collections.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\System.Console.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\System.Console.dll">
<LogicalName>netcoreapp.System.Console.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\System.Console.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\System.Linq.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\System.Linq.dll">
<LogicalName>netcoreapp.System.Linq.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\System.Linq.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\System.Linq.Expressions.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\System.Linq.Expressions.dll">
<LogicalName>netcoreapp.System.Linq.Expressions.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\System.Linq.Expressions.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\System.Runtime.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\System.Runtime.dll">
<LogicalName>netcoreapp.System.Runtime.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\System.Runtime.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\System.Runtime.InteropServices.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\System.Runtime.InteropServices.dll">
<LogicalName>netcoreapp.System.Runtime.InteropServices.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\System.Runtime.InteropServices.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\System.Runtime.InteropServices.WindowsRuntime.dll">
<LogicalName>netcoreapp.System.Runtime.InteropServices.WindowsRuntime.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\System.Runtime.InteropServices.WindowsRuntime.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\System.Threading.Tasks.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\System.Threading.Tasks.dll">
<LogicalName>netcoreapp.System.Threading.Tasks.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\System.Threading.Tasks.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\netstandard.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\netstandard.dll">
<LogicalName>netcoreapp.netstandard.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\netstandard.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\Microsoft.CSharp.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\Microsoft.CSharp.dll">
<LogicalName>netcoreapp.Microsoft.CSharp.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\Microsoft.CSharp.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\netcoreapp3.1\Microsoft.VisualBasic.dll">
<EmbeddedResource Include="$(PkgMicrosoft_NETCore_App_Ref)\ref\net5.0\Microsoft.VisualBasic.dll">
<LogicalName>netcoreapp.Microsoft.VisualBasic.dll</LogicalName>
<Link>Resources\ReferenceAssemblies\netcoreapp\Microsoft.VisualBasic.dll</Link>
</EmbeddedResource>
Expand Down
Loading

0 comments on commit 3323bf3

Please sign in to comment.