Fixed Join_ObjectArray test in StringTests#14083
Conversation
|
Fixed test pass for local run in |
| Assert.Equal(expected, string.Join(separator, (IEnumerable<object>)values)); | ||
| } | ||
| var exp = expected; | ||
| if (values.Length > 0 && values[0] == null) // Join return empty string if array[0] is null |
There was a problem hiding this comment.
nit: put this inside an #else condition after the block of #if netstandard17
There was a problem hiding this comment.
@hughbe but early at here #13747 (comment) @danmosemsft say to remove #else and I changed code to more complicated to remove #else. Can I use #else or can't?
There was a problem hiding this comment.
Ah okay, I'm not bothered. It seems that the #else would make more sense, as you're overwriting the value immediately and that code is dead before netstandard17
| { | ||
| Assert.Equal(expected, string.Join(separator, (IEnumerable<object>)values)); | ||
| } | ||
| var exp = expected; |
There was a problem hiding this comment.
Can we make this name more descriptive?
| @@ -1619,22 +1619,25 @@ public static IEnumerable<object[]> Join_ObjectArray_TestData() | |||
| yield return new object[] { "$$", new object[] { "Foo", null, "Baz" }, "Foo$$$$Baz" }; | |||
|
|
|||
| // Join does nothing if array[0] is null | |||
| // 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" }; |
There was a problem hiding this comment.
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.
I think it pass test on NetFramework because I wrote next code
#if !netstandard17
if (values.Length > 0 && values[0] == null) // Join return nothing when first value is null
expected = "";
#endif| [MemberData(nameof(Join_ObjectArray_TestData))] | ||
| public static void Join_ObjectArray(string separator, object[] values, string expected) | ||
| { | ||
| var enumerableExpected = expected; |
|
@AlexRadch please put important relevant info in the bug/PR description: Join issue for first null in object array is fixed. So calling string.Join(",", null, 1, 2, 3) now return ",1,2,3", but not empty string as before. See dotnet/coreclr#8114. |
@karelz sorry I am beginning in english. Can you help with relevant description to me? |
Sure and no worries, I have been there myself some time ago :) The relevant information is usually links to bugs and some context, description like the one you had in previous PR. |
| [ActiveIssue(13747)] | ||
| [Theory] | ||
| [MemberData(nameof(Join_ObjectArray_TestData))] | ||
| public static void Join_ObjectArray(string separator, object[] values, string expected) |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Do you suggest split test data too?
There was a problem hiding this comment.
Yes -- I think it would simplify the tests since they don't have to account for unexpected values.
There was a problem hiding this comment.
Join_ObjectArray_WithNullIssue test tests two methods string.Join(separator, values) and string.Join(separator, (IEnumerable<object>)values)). First method has issue but second hasn't.
So to test both we should split data in 2 and split test in 3 or 4 not in 2 as now.
So at begin we have 1 data and 1 test method with one #if and one if inside.
To remove #if I splited test in 2 with common data. But why I should split data in 2 and test in 3 or 4 to remove one if.
Original test that I am trying to fix for netcoreapp11 has if inside, But nobody did not split it on two with two data.
I think if we split one data and two tests in 2 data and 3 or 4 tests is not simplifying it is unnecessary complication.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Is next not enough?
if (values.Length > 0 && values[0] == null) // Join return nothing when first value is null
It is old comment that was before. I should extend it?
|
@dotnet-bot test this please |
1 similar comment
|
@dotnet-bot test this please |
|
Thank you for your contribution @AlexRadch ! |
|
ditto, thanks for your contribution, we appreciate it! |
|
Is this ported to netfx yet? |
* Fixed Join_ObjectArray test in StringTests Commit migrated from dotnet/corefx@57eb42f
Join issue for first null in object array is fixed. So calling string.Join(",", null, 1, 2, 3) now return ",1,2,3", but not empty string as before. See dotnet/coreclr#8114