-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Fixed Join_ObjectArray test in StringTests #14083
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1618,23 +1618,32 @@ public static IEnumerable<object[]> Join_ObjectArray_TestData() | |
| yield return new object[] { null, new object[] { "Foo", "Bar", "Baz" }, "FooBarBaz" }; | ||
| yield return new object[] { "$$", new object[] { "Foo", null, "Baz" }, "Foo$$$$Baz" }; | ||
|
|
||
| // Join does nothing if array[0] is null | ||
| yield return new object[] { "$$", new object[] { null, "Bar", "Baz" }, "" }; | ||
| // Test join when first value is null | ||
| yield return new object[] { "$$", new object[] { null, "Bar", "Baz" }, "$$Bar$$Baz" }; | ||
|
|
||
| // Join should ignore objects that have a null ToString() value | ||
| yield return new object[] { "|", new object[] { new ObjectWithNullToString(), "Foo", new ObjectWithNullToString(), "Bar", new ObjectWithNullToString() }, "|Foo||Bar|" }; | ||
| } | ||
|
|
||
| [ActiveIssue(13747)] | ||
| [Theory] | ||
| [MemberData(nameof(Join_ObjectArray_TestData))] | ||
| [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework | TargetFrameworkMonikers.NetcoreUwp | TargetFrameworkMonikers.Netcoreapp1_0)] | ||
| public static void Join_ObjectArray(string separator, object[] values, string expected) | ||
|
Contributor
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. I think the right approach is to split this in 2 methods. The first method will test the new behavior and you will have to add these 2 attributes to make sure it does not run on the previous versions of the platform: [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp1_0)]And another method will test the old behavior. For that you will have to add this attribute: [SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp1_1)]To make sure it is not running on the new version of the platform. As I mentioned in the other PR, the netstandard17 define is actually set for more build configuration that you need it.
Author
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. @AlexGhiondea I splited test in two |
||
| { | ||
| Assert.Equal(expected, string.Join(separator, values)); | ||
| if (!(values.Length > 0 && values[0] == null)) | ||
| { | ||
| Assert.Equal(expected, string.Join(separator, (IEnumerable<object>)values)); | ||
| } | ||
| Assert.Equal(expected, string.Join(separator, (IEnumerable<object>)values)); | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(Join_ObjectArray_TestData))] | ||
| [SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp1_1)] | ||
| public static void Join_ObjectArray_WithNullIssue(string separator, object[] values, string expected) | ||
| { | ||
| string enumerableExpected = expected; | ||
| if (values.Length > 0 && values[0] == null) // Join return nothing when first value is null | ||
|
Contributor
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. Thanks for splitting this out. Given that you have 2 methods now you can remove this special case for the null value and have 2 data generator methods for the two tests. The idea is that you can then remove the #if-def from the test data generator.
Author
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. Do you suggest split test data too?
Contributor
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. Yes -- I think it would simplify the tests since they don't have to account for unexpected values.
Author
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.
So to test both we should split data in 2 and split test in 3 or 4 not in 2 as now. Original test that I am trying to fix for netcoreapp11 has
Contributor
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. What I was trying to avoid is doing both the attribute on the methods to skip them on various platforms and having an #if/def inside the tests. I believe the reason why it was not split before is because we were using an if and not an #if/def. Anyway, at this point let's just leave them as they are but please add a comment explaining why we have the if that tests for null inside the tests.
Author
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. Is next not enough? |
||
| expected = ""; | ||
| Assert.Equal(expected, string.Join(separator, values)); | ||
| Assert.Equal(enumerableExpected, string.Join(separator, (IEnumerable<object>)values)); | ||
| } | ||
|
|
||
| [Fact] | ||
|
|
||
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 will end up failing when run on desktop, right? We'll need to separate it out into a separate test that's disabled for NetFramework.
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.
I think it pass test on NetFramework because I wrote next code