Skip to content

Commit

Permalink
[json tests] Fix CRLF vs LF issues (#52142)
Browse files Browse the repository at this point in the history
Context: #52106

When running `System.Text.Json.Tests` on windows targeting `Browser`,
the line ending differs between host and target systems. Compensate for
that by using `Assert.Equal(..., ignoreLineEndingDifferences: true)`.

The `Browser` Environment.NewLine is `\n`, while windows use `\r\n`.
https://github.com/dotnet/runtime/blob/5bd0edfe860e41bdfd690d3743e730594307292e/src/libraries/System.Private.CoreLib/src/System/Environment.UnixOrBrowser.cs#L51
  • Loading branch information
radekdoulik committed May 10, 2021
1 parent 1874842 commit 1197851
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public static void AssertContentsNotEqual(string expectedValue, ArrayBufferWrite

public static void AssertContentsAgainstJsonNet(string expectedValue, string value, bool skipSpecialRules)
{
Assert.Equal(expectedValue.NormalizeToJsonNetFormat(skipSpecialRules), value.NormalizeToJsonNetFormat(skipSpecialRules));
Assert.Equal(expectedValue.NormalizeToJsonNetFormat(skipSpecialRules), value.NormalizeToJsonNetFormat(skipSpecialRules), ignoreLineEndingDifferences: true);
}

public static void AssertContentsNotEqualAgainstJsonNet(string expectedValue, string value, bool skipSpecialRules)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void SerializeArray()
""One"",
""II"",
""3""
]", json);
]", json, ignoreLineEndingDifferences: true);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ public static void CustomReferenceResolver()
Assert.Same(john, jane.Spouse);
Assert.Same(jane, john.Spouse);

Assert.Equal(json, JsonSerializer.Serialize(people, options));
Assert.Equal(json, JsonSerializer.Serialize(people, options), ignoreLineEndingDifferences: true);
}

[Fact]
Expand Down Expand Up @@ -619,7 +619,7 @@ public static void CustomReferenceResolverPersistent()
Assert.Same(firstListOfPeople[0].Spouse, secondListOfPeople[0].Spouse);
Assert.Same(firstListOfPeople[1].Spouse, secondListOfPeople[1].Spouse);

Assert.Equal(json, JsonSerializer.Serialize(secondListOfPeople, options));
Assert.Equal(json, JsonSerializer.Serialize(secondListOfPeople, options), ignoreLineEndingDifferences: true);
}

internal class PresistentGuidReferenceHandler : ReferenceHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ static void WriteAndValidate(object input, Type type, string expected, JsonSeria
{
JsonSerializer.Serialize(writer, input, type, options);
}
Assert.Equal(expected, Encoding.UTF8.GetString(stream.ToArray()));
Assert.Equal(expected, Encoding.UTF8.GetString(stream.ToArray()), ignoreLineEndingDifferences: true);
}
}
}
Expand Down

0 comments on commit 1197851

Please sign in to comment.