Skip to content

Commit 8aedec0

Browse files
Disable JSON polymorphism source-gen tests on NativeAOT
The 12 test methods (6 [Fact] and 6 [Theory]) in PolymorphicTests.CustomTypeHierarchies.cs that use CustomPolymorphismResolver rely on runtime reflection-based type resolution which is not supported on NativeAOT. Replace [Fact] with [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))] and [Theory] with [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))] on those 12 methods. The skip applies to all 4 SourceGeneration subclasses (PolymorphicTests_Metadata, PolymorphicTests_Metadata_AsyncStream, PolymorphicTests_Default, PolymorphicTests_Default_AsyncStream) since they all inherit from the same abstract base class. Tests verified: 549 total pass on CoreCLR (including the 12 affected methods' 56 theory cases), 0 failures. Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
1 parent 306499b commit 8aedec0

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/libraries/System.Text.Json/tests/Common/PolymorphicTests.CustomTypeHierarchies.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public async Task PolymorphicClass_AllowOutOfOrderMetadata_RejectsInvalidInputs(
129129

130130
//--
131131

132-
[Theory]
132+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
133133
[MemberData(nameof(Get_PolymorphicClass_CustomConfigWithBaseTypeFallback_TestData_Serialization))]
134134
public Task PolymorphicClass_CustomConfigWithBaseTypeFallback_TestData_Serialization(PolymorphicClass.TestData testData)
135135
=> TestMultiContextSerialization(
@@ -142,7 +142,7 @@ public Task PolymorphicClass_CustomConfigWithBaseTypeFallback_TestData_Serializa
142142
public static IEnumerable<object[]> Get_PolymorphicClass_CustomConfigWithBaseTypeFallback_TestData_Serialization()
143143
=> PolymorphicClass.GetSerializeTestData_CustomConfigWithBaseTypeFallback().Select(entry => new object[] { entry });
144144

145-
[Theory]
145+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
146146
[MemberData(nameof(Get_PolymorphicClass_CustomConfigWithBaseTypeFallback_TestData_Deserialization))]
147147
public Task PolymorphicClass_CustomConfigWithBaseTypeFallback_TestData_Deserialization(PolymorphicClass.TestData testData)
148148
=> TestMultiContextDeserialization<PolymorphicClass>(
@@ -157,7 +157,7 @@ public static IEnumerable<object[]> Get_PolymorphicClass_CustomConfigWithBaseTyp
157157
.Where(entry => entry.ExpectedJson != null)
158158
.Select(entry => new object[] { entry });
159159

160-
[Fact]
160+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
161161
public async Task PolymorphicClass_CustomConfigWithBaseTypeFallback_TestDataArray_Serialization()
162162
{
163163
IEnumerable<(PolymorphicClass Value, string ExpectedJson)> inputs =
@@ -168,7 +168,7 @@ public async Task PolymorphicClass_CustomConfigWithBaseTypeFallback_TestDataArra
168168
await TestMultiContextSerialization(inputs, options: PolymorphicClass.CustomConfigWithBaseTypeFallback);
169169
}
170170

171-
[Fact]
171+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
172172
public async Task PolymorphicClass_CustomConfigWithBaseTypeFallbacks_TestDataArray_Deserialization()
173173
{
174174
IEnumerable<(string ExpectedJson, PolymorphicClass ExpectedRoundtripValue)> inputs =
@@ -182,7 +182,7 @@ await TestMultiContextDeserialization(
182182
options: PolymorphicClass.CustomConfigWithBaseTypeFallback);
183183
}
184184

185-
[Theory]
185+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
186186
[InlineData("$['$type']", """{ "$type" : "derivedClass1", "Number" : 42 }""")]
187187
[InlineData("$._case", """{ "_case" : "derivedClass1", "_case" : "derivedClass1", "Number" : 42 }""")]
188188
[InlineData("$._case", """{ "_case" : "derivedClass1", "Number" : 42, "_case" : "derivedClass1"}""")]
@@ -206,7 +206,7 @@ public async Task PolymorphicClass_CustomConfigWithBaseTypeFallback_InvalidTypeD
206206

207207
//---
208208

209-
[Theory]
209+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
210210
[MemberData(nameof(Get_PolymorphicClass_CustomConfigWithNearestAncestorFallback_TestData_Serialization))]
211211
public Task PolymorphicClass_CustomConfigWithNearestAncestorFallback_TestData_Serialization(PolymorphicClass.TestData testData)
212212
=> TestMultiContextSerialization(
@@ -219,7 +219,7 @@ public Task PolymorphicClass_CustomConfigWithNearestAncestorFallback_TestData_Se
219219
public static IEnumerable<object[]> Get_PolymorphicClass_CustomConfigWithNearestAncestorFallback_TestData_Serialization()
220220
=> PolymorphicClass.GetSerializeTestData_CustomConfigWithNearestAncestorFallback().Select(entry => new object[] { entry });
221221

222-
[Theory]
222+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
223223
[MemberData(nameof(Get_PolymorphicClass_CustomConfigWithNearestAncestorFallback_TestData_Deserialization))]
224224
public Task PolymorphicClass_CustomConfigWithNearestAncestorFallback_TestData_Deserialization(PolymorphicClass.TestData testData)
225225
=> TestMultiContextDeserialization<PolymorphicClass>(
@@ -234,7 +234,7 @@ public static IEnumerable<object[]> Get_PolymorphicClass_CustomConfigWithNearest
234234
.Where(entry => entry.ExpectedJson != null)
235235
.Select(entry => new object[] { entry });
236236

237-
[Fact]
237+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
238238
public async Task PolymorphicClass_CustomConfigWithNearestAncestorFallback_TestDataArray_Serialization()
239239
{
240240
IEnumerable<(PolymorphicClass Value, string ExpectedJson)> inputs =
@@ -245,7 +245,7 @@ public async Task PolymorphicClass_CustomConfigWithNearestAncestorFallback_TestD
245245
await TestMultiContextSerialization(inputs, options: PolymorphicClass.CustomConfigWithNearestAncestorFallback);
246246
}
247247

248-
[Fact]
248+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
249249
public async Task PolymorphicClass_CustomConfigWithNearestAncestorFallback_TestDataArray_Deserialization()
250250
{
251251
IEnumerable<(string ExpectedJson, PolymorphicClass ExpectedRoundtripValue)> inputs =
@@ -259,7 +259,7 @@ await TestMultiContextDeserialization(
259259
options: PolymorphicClass.CustomConfigWithNearestAncestorFallback);
260260
}
261261

262-
[Theory]
262+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
263263
[InlineData("$['$type']", """{ "$type" : "derivedClass1", "Number" : 42 }""")]
264264
[InlineData("$._case", """{ "_case" : "derivedClass1", "_case" : "derivedClass1", "Number" : 42 }""")]
265265
[InlineData("$._case", """{ "_case" : "derivedClass1", "Number" : 42, "_case" : "derivedClass1"}""")]
@@ -1944,7 +1944,7 @@ public static IEnumerable<TestData> GetSerializeTestData()
19441944
public record TestData(PolymorphicDictionary Value, string ExpectedJson, PolymorphicDictionary ExpectedRoundtripValue);
19451945
}
19461946

1947-
[Fact]
1947+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
19481948
public async Task PolymorphicDictionaryInterface_Serialization()
19491949
{
19501950
var values = new IEnumerable<KeyValuePair<int, object>>[]
@@ -1968,7 +1968,7 @@ public async Task PolymorphicDictionaryInterface_Serialization()
19681968
JsonTestHelper.AssertJsonEqual(expectedJson, actualJson);
19691969
}
19701970

1971-
[Fact]
1971+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]
19721972
public async Task PolymorphicDictionaryInterface_Deserialization()
19731973
{
19741974
string json =

0 commit comments

Comments
 (0)