Standardize our test references#45690
Conversation
5d28894 to
d4f227f
Compare
This changes our test utilities library to use the standard reference assemblies for the desktop target frameworks that we support in our unit tests. This also upgrades us to a new version of the proprietary library where the duplicate references are removed
These were changes which were less mechanical or involevd re-targeting. These should be given a more thorough inspection than the more mechanical changes in the pull request
|
@dotnet/roslyn-compiler PTAL |
| Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(14, 22), | ||
| // warning CS1685: The predefined type 'ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' | ||
| Diagnostic(ErrorCode.WRN_MultiplePredefTypes).WithArguments("System.Runtime.CompilerServices.ExtensionAttribute", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089").WithLocation(1, 1) | ||
| Diagnostic(ErrorCode.ERR_EscapeLocal, "local").WithArguments("local").WithLocation(14, 22) |
There was a problem hiding this comment.
The diagnostics removed in this file all just appear to be a result of mixing incorrect references. This changed fixed up the code to have the correct System.Core.dll reference and hence the diagnostics were removed.
| "SRETW"); | ||
| "SRETW", | ||
| "Outer", | ||
| "Microsoft"); |
There was a problem hiding this comment.
This appears to just be a result of the diff between the ref and impl assemblies we were using. Wanted someone else to look at this to verify though.
| Assert.Equal(8, type1.Interfaces().Length); | ||
| Assert.Equal(10, type1.Interfaces().Length); | ||
|
|
||
| var fullName = "System.Collections.Generic.Dictionary<TKey, TValue>"; |
There was a problem hiding this comment.
This are just differences between the frankenstein mscorlib we were using and the correct reference assembly.
| } | ||
|
|
||
| [Fact] | ||
| [Fact(Skip = "PROTOTYPE")] |
There was a problem hiding this comment.
I'm unsure what to do with this test. The test here revolves around the type EventingTestBase. That is a type that only exists in the beta version of the .NET Framework, it was never shipped in any RTM release. Hence there is no direct port of this to the standard reference assemblies.
Is there an equivalent to this type that I can use in this test? Or if there isn't should we just delete the test? I'd much prefer finding an equivalent type to test against.
@AlekseyTs as you're most likely to have the context here.
There was a problem hiding this comment.
Is there an equivalent to this type that I can use in this test? Or if there isn't should we just delete the test? I'd much prefer finding an equivalent type to test against.
From reading the original test, I believe it wasn't really intended to test something special about the EventProviderBase. It looks like the goal was to verify the API behaviors around array types imported from metadata, and the EventProviderBase type conveniently referenced types like that. I think we can simply define the EventProviderBase, as it used to be, in source in a separate compilation, then emit the compilation as image reference, add the reference, and test against that type instead.
In reply to: 450993234 [](ancestors = 450993234)
There was a problem hiding this comment.
Took that approach and it looks to have worked out well. Thanks.
| Dim ns = DirectCast(info.Symbol, NamespaceSymbol) | ||
|
|
||
| Assert.Equal(NamespaceKind.Compilation, ns.NamespaceKind) | ||
| Assert.Equal(NamespaceKind.Module, ns.NamespaceKind) |
There was a problem hiding this comment.
Wanted to make sure this change was reviewed and signed off on.
| <EmbeddedResource Include="$(Pkgjnm2_ReferenceAssemblies_net35)\build\.NETFramework\v3.5\\System.Core.dll"> | ||
| <LogicalName>net35.System.Core.dll</LogicalName> | ||
| </EmbeddedResource> | ||
| <EmbeddedResource Include="$(PkgMicrosoft_NETFramework_ReferenceAssemblies_net40)\build\.NETFramework\v4.0\\mscorlib.dll"> |
There was a problem hiding this comment.
\ [](start = 114, length = 1)
Extra \
| public void CreateFromImage() | ||
| { | ||
| var r = MetadataReference.CreateFromImage(TestResources.NetFX.v4_0_30319.mscorlib); | ||
| var r = MetadataReference.CreateFromImage(ResourcesNet451.mscorlib); |
There was a problem hiding this comment.
ResourcesNet451 [](start = 54, length = 15)
Why not keep the original TestResources static class? E.g. TestResources.Net451
There was a problem hiding this comment.
I initially tried that but eventually moved away because I wanted a clean separation between what was coming from the proprietary resource DLL and what was coming from the "new" approach.
There was a problem hiding this comment.
How about TestMetadata? Or some other container type like that. Having it directly under Utilities namespace puts names like BuildExtensions and ValueTask out of context.
|
Note: I will have a follow up change to do the same flip for our .NET Standard and .NET Core app references. This change was already getting unweildy though hence wanted to separate the efforts |
| private static byte[] _NetStandard461; | ||
| public static byte[] NetStandard461 => ResourceLoader.GetOrCreateResource(ref _NetStandard461, "BuildExtensions.netstandard.dll"); | ||
| } | ||
| public static class BuildExtensions |
There was a problem hiding this comment.
BuildExtensions [](start = 24, length = 15)
This name does not indicate that it's a PE reference created for metadata in a resource.
There was a problem hiding this comment.
Have a better suggestion here? I'd prefer one that we could apply as a pattern to these one off reference cases. There are two right now but looking forward there will likely be 1-2 more. Hence if we had a nice prefix or suffix it could be applied to all of them.
There was a problem hiding this comment.
As noted above I'd encapsulate all of these types in something like TestMetadata static class. Then the names are ok as nested types.
|
@tmat addressed your feedback |
| compilation1.VerifyDiagnostics(); | ||
|
|
||
| var source2 = "public class A {}"; | ||
| var compilation2 = CreateEmptyCompilation(source2, new MetadataReference[] { TestMetadata.Net40.mscorlib, TestMetadata.Net40.SystemCore, compilation1.ToMetadataReference() }, |
There was a problem hiding this comment.
ToMetadataReference [](start = 162, length = 19)
This should be EmitToImageReference in order to test metadata types #Closed
This change standardizes the reference assemblies we use for compilation in our unit test to be the actual .NET Framework reference assemblies.
Prior to this change they were a mix of reference and implementation assemblies from non-RTM versions of the .NET Framework. In order to map the existing assemblies to their respective target framework version I worked with the servicing team and we mapped them to the closest possible TFM based on their file versions. The bulk of the change is essentially mechanically moving from names like
mscorlib.v4_30319_17929toNet451.mscorlib.Unfortunately in several cases the non-RTM assemblies didn't cleanly map to a RTM TFM. This was particularly problematic when migrating the
v4_30319references as this is a mix of anet40andnet451versions. This caused issues in our code base because these references were freely mixed with actualnet40andnet451references in the code base. Most of the time this went unnoticed because the test didn't expose the gaps in the APIs. In a lot of cases though, particularly when mixing a version ofSystem.Corethat did or didn't haveExtensionsAttribute, this required some manual inspection on my part and a fix. In pretty much every case this was a straight forward fix but it did mean the change was less mechanical than I would have preferred.To make this change easier to review I've broken it up into three commits:
Roslyn.Test.Utilitiesthat move us to the new references.The benefits of this change are the following:
The internal PR is here https://github.com/dotnet/roslyn-internal/pull/1954
Note: I will be making more changes in this area in future PRs. But I wanted to keep the mechanical portion of this change into its own PR. Further PRs will be smaller but less mechanical.