Align System.Reflection.Metadata CustomAttributeDecoder tests with embedded-resource scheme#127224
Align System.Reflection.Metadata CustomAttributeDecoder tests with embedded-resource scheme#127224
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-reflection-metadata |
- Add Resources/Decoding/CustomAttributeDecoder.cs: source for helper assembly with all types and custom attributes needed by the decoder tests - Add Resources/Decoding/CustomAttributeDecoder.dll: pre-compiled helper assembly embedded as a test resource - Update TestResources.cs to expose the new resource via Decoding.CustomAttributeDecoder - Update System.Reflection.Metadata.Tests.csproj to include the new resource files - Rewrite CustomAttributeDecoderTests.cs to load metadata from the embedded resource instead of introspecting the running test assembly: - Remove ConditionalFact(NotSingleFile) / ConditionalFact(HasAssemblyFiles) guards - Remove assembly-identity workarounds (RuntimeAssemblyName, TypeToString, etc.) - Remove inline type definitions (HasAttributes, TestAttribute, enums, GenericAttribute, etc.) - Add comprehensive assertions covering all 82 attributes on HasAttributes, 8 on HasGenericAttributes, and 2 on HasGenericArrayAttributes - Add FindTestType helper that looks up types by namespace+name in the embedded metadata - Simplify CustomAttributeTypeProvider with hardcoded type mappings for the resource assembly's enum types Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8f883665-1cac-472f-81aa-5074b5ff4f1c Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/8f883665-1cac-472f-81aa-5074b5ff4f1c Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
| break; | ||
|
|
||
| case 2: | ||
| case 2: // [Test(StringField = "0", Int32Field = 1, SByteEnumArrayProperty = new[] { SByteEnum.Value })] |
There was a problem hiding this comment.
@copilot Revert all unnecessary test updates and refactorings. Keep the changes limited to the objective of this PR
There was a problem hiding this comment.
Done in ca6c958. Reverted TestCustomAttributeDecoder back to the original 3-case structure with default: break, removing the 79 extra cases that were unnecessarily added. The remaining changes are the minimum needed to switch from FileStream + AssemblyPathHelper.GetAssemblyLocation to the embedded-resource scheme: loading via MemoryStream, updated type lookup, and a CustomAttributeTypeProvider that uses hardcoded type names instead of Type.GetType() / MetadataReaderTestHelpers.RuntimeAssemblyName.
- Restore TestCustomAttributeDecoder to original 3-case structure with default: break - Remove cases 3-81 that were added unnecessarily - Keep all other necessary changes: loading via embedded resource, FindTestType helper, updated CustomAttributeTypeProvider, TestCustomAttributeDecoderGeneric, TestCustomAttributeDecoderGenericArray Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/139c63c4-491a-4ab0-81cc-432ef0e7b479 Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
|
This does not look like an improvement. |
CustomAttributeDecoderTestswas introspecting the running test assembly instead of using the embedded-resource pattern used by the rest ofSystem.Reflection.Metadata.Tests. This made the tests incompatible with single-file, trimming, and NativeAOT, and sensitive to BCL assembly-identity differences (e.g.System.RuntimevsSystem.Private.CoreLib), requiringConditionalFact(NotSingleFile)guards and assembly-identity workarounds.Changes
Resources/Decoding/CustomAttributeDecoder.cs+.dll): self-contained source + pre-compiled binary containingTestAttribute, all enum types,HasAttributes,GenericAttribute<T>,GenericAttribute2<K,V>,HasGenericAttributes, andHasGenericArrayAttributesTestResources.cs: addedinternal static class DecodingexposingCustomAttributeDecodervia the existingResourceHelperpatternSystem.Reflection.Metadata.Tests.csproj: registered the new.cs(asNone) and.dll(asEmbeddedResource)CustomAttributeDecoderTests.cs: minimal changes to switch from disk-based loading to embedded-resource loading:FileStream + AssemblyPathHelper.GetAssemblyLocationwithMemoryStreamover the embedded DLL bytesConditionalFact(HasAssemblyFiles)/ActiveIssueguards — tests are now plain[Fact]TestMetadataResolver.FindTestType(reader, typeof(HasAttributes))to aFindTestTypehelper that searches by namespace and name in the embedded metadataTestCustomAttributeDecoderUsingReflection(relied ontype.GetCustomAttributesData()which requires the types to be in the running assembly)CustomAttributeTypeProviderto use hardcoded"[System.Runtime]System.Type"and aswitchon type names instead ofMetadataReaderTestHelpers.RuntimeAssemblyName/Type.GetType()TestCustomAttributeDecoderretains its original 3-case structure withdefault: break#if NET && !TARGET_BROWSERNote
This PR description was generated with AI assistance (GitHub Copilot).