Skip to content

Commit 34794bc

Browse files
authored
Enable System.Text.Json tests on netfx (dotnet#63803)
* Enable System.Text.Json tests on netfx * use NETFRAMEWORK define * disable another two test cases after rebase * disable last test case which repros only on CI for me * add p2p only on netfx
1 parent e54df94 commit 34794bc

File tree

13 files changed

+43
-6
lines changed

13 files changed

+43
-6
lines changed

docs/coding-guidelines/project-guidelines.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Pure netstandard configuration:
5252
All supported targets with unique windows/unix build for netcoreapp:
5353
```
5454
<PropertyGroup>
55-
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetFrameworkCurrent)</TargetFrameworks>
55+
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetFrameworkMinimum)</TargetFrameworks>
5656
<PropertyGroup>
5757
```
5858

src/libraries/System.Text.Json/tests/Common/PropertyVisibilityTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,7 @@ public async Task JsonIgnoreAttribute_UnsupportedCollection()
12271227
}
12281228

12291229
[Fact]
1230+
[ActiveIssue("https://github.com/dotnet/runtime/issues/63802", TargetFrameworkMonikers.NetFramework)]
12301231
public async Task JsonIgnoreAttribute_UnsupportedBigInteger()
12311232
{
12321233
string json = @"{""MyBigInteger"":1}";

src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/ContextClasses.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections.Generic;
5-
using System.Reflection;
65
using System.Text.Json.Serialization;
76
using System.Text.Json.Serialization.Metadata;
87

@@ -11,7 +10,7 @@ namespace System.Text.Json.SourceGeneration.Tests
1110
public interface ITestContext
1211
{
1312
public JsonSourceGenerationMode JsonSourceGenerationMode { get; }
14-
public bool IsIncludeFieldsEnabled => GetType().GetCustomAttribute<JsonSourceGenerationOptionsAttribute>()?.IncludeFields ?? false;
13+
public bool IsIncludeFieldsEnabled { get; }
1514

1615
public JsonTypeInfo<Location> Location { get; }
1716
public JsonTypeInfo<NumberTypes> NumberTypes { get; }

src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/JsonSerializerContextTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static void VariousNestingAndVisibilityLevelsAreSupported()
2121
}
2222

2323
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
24+
[ActiveIssue("https://github.com/dotnet/runtime/issues/63802", TargetFrameworkMonikers.NetFramework)]
2425
public static void Converters_AndTypeInfoCreator_NotRooted_WhenMetadataNotPresent()
2526
{
2627
RemoteExecutor.Invoke(

src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/MetadataAndSerializationContextTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Text.Json.Serialization;
5+
using System.Reflection;
56
using Xunit;
67

78
namespace System.Text.Json.SourceGeneration.Tests
@@ -44,6 +45,7 @@ namespace System.Text.Json.SourceGeneration.Tests
4445
internal partial class MetadataAndSerializationContext : JsonSerializerContext, ITestContext
4546
{
4647
public JsonSourceGenerationMode JsonSourceGenerationMode => JsonSourceGenerationMode.Default;
48+
public bool IsIncludeFieldsEnabled => GetType().GetCustomAttribute<JsonSourceGenerationOptionsAttribute>()?.IncludeFields ?? false;
4749
}
4850

4951
public sealed class MetadataAndSerializationContextTests : RealWorldContextTests

src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/MetadataContextTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Text.Json.Serialization;
5+
using System.Reflection;
56
using Xunit;
67

78
namespace System.Text.Json.SourceGeneration.Tests
@@ -43,6 +44,7 @@ namespace System.Text.Json.SourceGeneration.Tests
4344
internal partial class MetadataWithPerTypeAttributeContext : JsonSerializerContext, ITestContext
4445
{
4546
public JsonSourceGenerationMode JsonSourceGenerationMode => JsonSourceGenerationMode.Metadata;
47+
public bool IsIncludeFieldsEnabled => GetType().GetCustomAttribute<JsonSourceGenerationOptionsAttribute>()?.IncludeFields ?? false;
4648
}
4749

4850
public sealed class MetadataWithPerTypeAttributeContextTests : RealWorldContextTests
@@ -127,6 +129,7 @@ public override void EnsureFastPathGeneratedAsExpected()
127129
internal partial class MetadataContext : JsonSerializerContext, ITestContext
128130
{
129131
public JsonSourceGenerationMode JsonSourceGenerationMode => JsonSourceGenerationMode.Metadata;
132+
public bool IsIncludeFieldsEnabled => GetType().GetCustomAttribute<JsonSourceGenerationOptionsAttribute>()?.IncludeFields ?? false;
130133
}
131134

132135
[JsonConverter(typeof(JsonStringEnumConverter))]

src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/MixedModeContextTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Text.Json.Serialization;
5+
using System.Reflection;
56
using Xunit;
67

78
namespace System.Text.Json.SourceGeneration.Tests
@@ -44,6 +45,7 @@ namespace System.Text.Json.SourceGeneration.Tests
4445
internal partial class MixedModeContext : JsonSerializerContext, ITestContext
4546
{
4647
public JsonSourceGenerationMode JsonSourceGenerationMode => JsonSourceGenerationMode.Metadata | JsonSourceGenerationMode.Serialization;
48+
public bool IsIncludeFieldsEnabled => GetType().GetCustomAttribute<JsonSourceGenerationOptionsAttribute>()?.IncludeFields ?? false;
4749
}
4850

4951
public sealed class MixedModeContextTests : RealWorldContextTests

src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/Serialization/PropertyVisibilityTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,12 @@ public override async Task HonorJsonPropertyName_PrivateSetter()
249249
[JsonSerializable(typeof(ClassWithNewSlotAttributedDecimalProperty))]
250250
[JsonSerializable(typeof(ClassWithNewSlotDecimalProperty))]
251251
[JsonSerializable(typeof(LargeStructWithValueAndReferenceTypes))]
252+
#if !NETFRAMEWORK
252253
[JsonSerializable(typeof(ClassWithUnsupportedBigInteger))]
253254
[JsonSerializable(typeof(WrapperForClassWithUnsupportedBigInteger))]
254255
[JsonSerializable(typeof(ClassWithIgnoredUnsupportedBigInteger))]
255256
[JsonSerializable(typeof(WrapperForClassWithIgnoredUnsupportedBigInteger))]
257+
#endif
256258
[JsonSerializable(typeof(ClassWithThingsToIgnore))]
257259
[JsonSerializable(typeof(ClassWithMixedPropertyAccessors_PropertyAttributes))]
258260
[JsonSerializable(typeof(ClassWithPropertyPolicyConflictWhichThrows))]
@@ -422,10 +424,12 @@ public override async Task JsonIgnoreCondition_WhenWritingNull_OnValueType_Fail_
422424
[JsonSerializable(typeof(ClassWithNewSlotAttributedDecimalProperty))]
423425
[JsonSerializable(typeof(ClassWithNewSlotDecimalProperty))]
424426
[JsonSerializable(typeof(LargeStructWithValueAndReferenceTypes))]
427+
#if !NETFRAMEWORK
425428
[JsonSerializable(typeof(ClassWithUnsupportedBigInteger))]
426429
[JsonSerializable(typeof(WrapperForClassWithUnsupportedBigInteger))]
427430
[JsonSerializable(typeof(ClassWithIgnoredUnsupportedBigInteger))]
428431
[JsonSerializable(typeof(WrapperForClassWithIgnoredUnsupportedBigInteger))]
432+
#endif
429433
[JsonSerializable(typeof(ClassWithThingsToIgnore))]
430434
[JsonSerializable(typeof(ClassWithMixedPropertyAccessors_PropertyAttributes))]
431435
[JsonSerializable(typeof(ClassWithPropertyPolicyConflictWhichThrows))]

src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/SerializationContextTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Text.Json.Serialization;
5+
using System.Reflection;
56
using Xunit;
67

78
namespace System.Text.Json.SourceGeneration.Tests
@@ -44,6 +45,7 @@ namespace System.Text.Json.SourceGeneration.Tests
4445
internal partial class SerializationContext : JsonSerializerContext, ITestContext
4546
{
4647
public JsonSourceGenerationMode JsonSourceGenerationMode => JsonSourceGenerationMode.Serialization;
48+
public bool IsIncludeFieldsEnabled => GetType().GetCustomAttribute<JsonSourceGenerationOptionsAttribute>()?.IncludeFields ?? false;
4749
}
4850

4951
[JsonSerializable(typeof(Location), GenerationMode = JsonSourceGenerationMode.Serialization)]
@@ -83,6 +85,7 @@ internal partial class SerializationContext : JsonSerializerContext, ITestContex
8385
internal partial class SerializationWithPerTypeAttributeContext : JsonSerializerContext, ITestContext
8486
{
8587
public JsonSourceGenerationMode JsonSourceGenerationMode => JsonSourceGenerationMode.Serialization;
88+
public bool IsIncludeFieldsEnabled => GetType().GetCustomAttribute<JsonSourceGenerationOptionsAttribute>()?.IncludeFields ?? false;
8689
}
8790

8891
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, IncludeFields = true)]
@@ -123,6 +126,7 @@ internal partial class SerializationWithPerTypeAttributeContext : JsonSerializer
123126
internal partial class SerializationContextWithCamelCase : JsonSerializerContext, ITestContext
124127
{
125128
public JsonSourceGenerationMode JsonSourceGenerationMode => JsonSourceGenerationMode.Serialization;
129+
public bool IsIncludeFieldsEnabled => GetType().GetCustomAttribute<JsonSourceGenerationOptionsAttribute>()?.IncludeFields ?? false;
126130
}
127131

128132
public class SerializationContextTests : RealWorldContextTests

src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/System.Text.Json.SourceGeneration.Tests.targets

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<TargetFrameworks>$(NetCoreAppCurrent);$(NetFrameworkCurrent)</TargetFrameworks>
3+
<TargetFrameworks>$(NetCoreAppCurrent);$(NetFrameworkMinimum)</TargetFrameworks>
44
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
55
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
66
<!-- SYSLIB0020: JsonSerializerOptions.IgnoreNullValues is obsolete -->
@@ -86,6 +86,17 @@
8686
<Compile Include="TestClasses.CustomConverters.cs" />
8787
</ItemGroup>
8888

89+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
90+
<ProjectReference Include="..\..\src\System.Text.Json.csproj" />
91+
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections.Immutable\src\System.Collections.Immutable.csproj" />
92+
</ItemGroup>
93+
94+
<ItemGroup Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)'">
95+
<Compile Include="$(CommonPath)System\Runtime\CompilerServices\IsExternalInit.cs" Link="Common\System\Runtime\CompilerServices\IsExternalInit.cs" />
96+
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicDependencyAttribute.cs" />
97+
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" />
98+
</ItemGroup>
99+
89100
<Target Name="FixIncrementalCoreCompileWithAnalyzers" BeforeTargets="CoreCompile">
90101
<ItemGroup>
91102
<CustomAdditionalCompileInputs Include="@(Analyzer)" />

0 commit comments

Comments
 (0)