-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Native AOT testing in System.Text.Json. #86975
Merged
eiriktsarpalis
merged 3 commits into
dotnet:main
from
eiriktsarpalis:fix/stj-aot-testing
Jun 2, 2023
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1049,6 +1049,7 @@ public async Task InvalidJsonFails() | |
await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Point_2D_Struct>("{true")); | ||
} | ||
|
||
#if !BUILDING_SOURCE_GENERATOR_TESTS // Anonymous types not supported in source gen | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test is hardcoding reflection, so I'm just disabling it for source gen. |
||
[Fact] | ||
public void AnonymousObject() | ||
{ | ||
|
@@ -1087,6 +1088,7 @@ public void AnonymousObject_NamingPolicy() | |
// Verify match with naming policy | ||
Assert.Equal(5, objType.GetProperty("Prop").GetValue(newObj)); | ||
} | ||
#endif | ||
|
||
public record MyRecord(int Prop); | ||
|
||
|
@@ -1329,29 +1331,29 @@ public class ClassWithIgnoredSameType | |
} | ||
|
||
[Fact] | ||
public void StructWithPropertyInit_DeseralizeEmptyObject() | ||
public async Task StructWithPropertyInit_DeseralizeEmptyObject() | ||
{ | ||
string json = @"{}"; | ||
var obj = JsonSerializer.Deserialize<StructWithPropertyInit>(json); | ||
var obj = await Serializer.DeserializeWrapper<StructWithPropertyInit>(json); | ||
Assert.Equal(42, obj.A); | ||
Assert.Equal(0, obj.B); | ||
} | ||
|
||
[Fact] | ||
public void StructWithPropertyInit_OverrideInitedProperty() | ||
public async Task StructWithPropertyInit_OverrideInitedProperty() | ||
{ | ||
string json = @"{""A"":43}"; | ||
var obj = JsonSerializer.Deserialize<StructWithPropertyInit>(json); | ||
var obj = await Serializer.DeserializeWrapper<StructWithPropertyInit>(json); | ||
Assert.Equal(43, obj.A); | ||
Assert.Equal(0, obj.B); | ||
|
||
json = @"{""A"":0,""B"":44}"; | ||
obj = JsonSerializer.Deserialize<StructWithPropertyInit>(json); | ||
obj = await Serializer.DeserializeWrapper<StructWithPropertyInit>(json); | ||
Assert.Equal(0, obj.A); | ||
Assert.Equal(44, obj.B); | ||
|
||
json = @"{""B"":45}"; | ||
obj = JsonSerializer.Deserialize<StructWithPropertyInit>(json); | ||
obj = await Serializer.DeserializeWrapper<StructWithPropertyInit>(json); | ||
Assert.Equal(42, obj.A); // JSON doesn't set A property so it's expected to be 42 | ||
Assert.Equal(45, obj.B); | ||
} | ||
|
@@ -1364,10 +1366,10 @@ public struct StructWithPropertyInit | |
} | ||
|
||
[Fact] | ||
public void StructWithFieldInit_DeseralizeEmptyObject() | ||
public async Task StructWithFieldInit_DeseralizeEmptyObject() | ||
{ | ||
string json = @"{}"; | ||
var obj = JsonSerializer.Deserialize<StructWithFieldInit>(json); | ||
var obj = await Serializer.DeserializeWrapper<StructWithFieldInit>(json); | ||
Assert.Equal(0, obj.A); | ||
Assert.Equal(42, obj.B); | ||
} | ||
|
@@ -1380,10 +1382,10 @@ public struct StructWithFieldInit | |
} | ||
|
||
[Fact] | ||
public void StructWithExplicitParameterlessCtor_DeseralizeEmptyObject() | ||
public async Task StructWithExplicitParameterlessCtor_DeseralizeEmptyObject() | ||
{ | ||
string json = @"{}"; | ||
var obj = JsonSerializer.Deserialize<StructWithExplicitParameterlessCtor>(json); | ||
var obj = await Serializer.DeserializeWrapper<StructWithExplicitParameterlessCtor>(json); | ||
Assert.Equal(42, obj.A); | ||
} | ||
|
||
|
@@ -1431,18 +1433,17 @@ public async Task TestClassWithDefaultCtorParams() | |
JsonTestHelper.AssertJsonEqual(json, await Serializer.SerializeWrapper(obj)); | ||
} | ||
|
||
#if FIXED // https://github.com/dotnet/roslyn/issues/66900 | ||
[Fact] | ||
public async Task TestClassWithManyConstructorParameters() | ||
{ | ||
ClassWithManyConstructorParameters value = ClassWithManyConstructorParameters.Create(); | ||
string json = JsonSerializer.Serialize(value); | ||
string json = await Serializer.SerializeWrapper(value); | ||
|
||
ClassWithManyConstructorParameters result = await Serializer.DeserializeWrapper<ClassWithManyConstructorParameters>(json); | ||
|
||
Assert.Equal(value, result); // Type is C# record that implements structural equality. | ||
} | ||
#endif | ||
|
||
public class ClassWithDefaultCtorParams | ||
{ | ||
public Point_2D_Struct_WithAttribute Struct { get; } | ||
|
@@ -1543,6 +1544,7 @@ public class ClassWithDefaultCtorParams | |
} | ||
|
||
[Fact] | ||
[ActiveIssue("https://github.com/dotnet/runtime/issues/79311", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] | ||
public async Task TestTypeWithEnumParameters() | ||
{ | ||
// Regression test for https://github.com/dotnet/runtime/issues/68647 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was identical to the one above, so I deleted it.