Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fixed Join_ObjectArray test in StringTests#14083

Merged
AlexGhiondea merged 4 commits into
dotnet:masterfrom
AlexRadch:String-Join_ObjectArray-Test
Dec 1, 2016
Merged

Fixed Join_ObjectArray test in StringTests#14083
AlexGhiondea merged 4 commits into
dotnet:masterfrom
AlexRadch:String-Join_ObjectArray-Test

Conversation

@AlexRadch
Copy link
Copy Markdown

@AlexRadch AlexRadch commented Nov 29, 2016

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

@AlexRadch
Copy link
Copy Markdown
Author

Fixed test pass for local run in src\System.Runtime\tests\ folder by executing msbuild /t:BuildAndTest command.
But test fail in root folder if run build command. I do not know how to fix that.
I tried to use netcoreapp11 instead netstandard17 but then test fail in both cases.

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: put this inside an #else condition after the block of #if netstandard17

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this name more descriptive?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed name

@@ -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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, I will change it.

// 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" };
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Author

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

#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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: var => string

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@karelz
Copy link
Copy Markdown
Member

karelz commented Nov 29, 2016

@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.

@AlexRadch
Copy link
Copy Markdown
Author

AlexRadch commented Nov 29, 2016

@AlexRadch please put important relevant info in the bug/PR description:

@karelz sorry I am beginning in english. Can you help with relevant description to me?

@karelz
Copy link
Copy Markdown
Member

karelz commented Nov 29, 2016

@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 :)
BTW: The description text I meant was already in my reply + I already updated the top text in the PR.

The relevant information is usually links to bugs and some context, description like the one you had in previous PR.
In this PR you had just "We fixed string.Join, now add test" which does not describe which fix of string.Join you mean. Second question that immediately pops is "why tests were not part of the fix" ... both of these are naturally answered by the text in your previous PR which links the string.Join bug fix (in coreclr) and says briefly what it was about.

[ActiveIssue(13747)]
[Theory]
[MemberData(nameof(Join_ObjectArray_TestData))]
public static void Join_ObjectArray(string separator, object[] values, string expected)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexGhiondea I splited test in two

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you suggest split test data too?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

@AlexRadch AlexRadch Nov 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

@AlexRadch AlexRadch Dec 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@stephentoub
Copy link
Copy Markdown
Member

@dotnet-bot test this please

1 similar comment
@AlexGhiondea
Copy link
Copy Markdown
Contributor

@dotnet-bot test this please

@AlexGhiondea AlexGhiondea merged commit 57eb42f into dotnet:master Dec 1, 2016
@AlexGhiondea
Copy link
Copy Markdown
Contributor

Thank you for your contribution @AlexRadch !

@AlexRadch AlexRadch deleted the String-Join_ObjectArray-Test branch December 1, 2016 06:15
@karelz
Copy link
Copy Markdown
Member

karelz commented Dec 1, 2016

ditto, thanks for your contribution, we appreciate it!

@karelz karelz modified the milestone: 1.2.0 Dec 3, 2016
@jayaranigarg
Copy link
Copy Markdown

Is this ported to netfx yet?

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Fixed Join_ObjectArray test in StringTests

Commit migrated from dotnet/corefx@57eb42f
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants