Skip to content
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

Add NoNewLine switch for Out-String cmdlet #5056

Merged
merged 1 commit into from Oct 11, 2017

Conversation

raghav710
Copy link
Contributor

@raghav710 raghav710 commented Oct 8, 2017

Fix #3684.

First PS pull request {insert nervous emoji}
Mostly adapted from the -NoNewLine changes for Out-File

@msftclas
Copy link

msftclas commented Oct 8, 2017

CLA assistant check
All CLA requirements met.

_buffer.AppendLine(s);
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove extra line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done as suggested

@@ -124,7 +143,17 @@ private void OnWriteLine(string s)
if (_stream)
this.WriteObject(s);
else
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add braces here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added braces as suggested

set
{
_suppressNewline = value;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use one line formatting as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. Done!

/// False to add a newline to the end of the output string, true if not.
/// </summary>
[Parameter]
public SwitchParameter NoNewline
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please put NoNewLine and Sream parameters in different parameter sets as discussed in the Issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I have named the ParameterSets as NonStreamFormatting and StreamFormatting for want of a better name. Do suggest one if this is bad :)
I've also fixed-up the commit instead of adding a new one to keep it clean. Let me know if that is an inconvenience.

@@ -45,4 +45,14 @@ Describe "Out-String" -Tags "CI" {

$streamoutputlength | Should BeLessThan $nonstreamoutputlength
}

It "Should not print a newline when the nonewline switch is used" {
$testArray = "a", " b"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why we use space? I'd prefer to remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not sure what example to give and hence followed the one in
It "Should accumulate the strings and returns them as a single string"
Will remove the space as suggested

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the space

@iSazonov iSazonov changed the title Add NoNewLine switch for Out-String cmdlet (#3684) Add NoNewLine switch for Out-String cmdlet Oct 8, 2017
@raghav710 raghav710 force-pushed the fix-issue-3684 branch 2 times, most recently from d3a59c3 to f17122a Compare October 8, 2017 14:59
Copy link
Contributor

@markekraus markekraus left a comment

Choose a reason for hiding this comment

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

LGTM.

@markekraus
Copy link
Contributor

We just need to make sure the documentation is updated to include the new parameter.

/// <summary>
/// False to add a newline to the end of the output string, true if not.
/// </summary>
[Parameter(ParameterSetName="NonStreamFormatting")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer "NoNewlineFormatting".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice. changing it now


It "Should not print a newline when the nonewline switch is used" {
$testArray = "a", "b"
$testArray | Out-String -NoNewLine | Should Be "ab"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add the test for default parameter set:
$testArray | Out-String | Should Be "ab"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If i am not wrong, this is the test for the default parameter set wherein newlines are added to the output. Is my understanding correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! Yes, correct.

Closed.

It "Should preserve embedded newline when the nonewline switch is used" {
$testArray = "a$nl", "b"
$testArray | Out-String -NoNewLine | Should Be "a$($nl)b"
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should a test that Stream and NoNewLine in different parameter sets:

{$testarray | Out-String -NoNewLine -Stream } | ShouldBeErrorId "....."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I was a bit unsure how to go about doing that. Thanks for helping out!

@iSazonov iSazonov added the Documentation Needed in this repo Documentation is needed in this repo label Oct 8, 2017

It "Should preserve embedded newline when the nonewline switch is used" {
$testArray = "a$nl", "b"
$testArray | Out-String -NoNewLine | Should Be "a$($nl)b"
Copy link
Member

Choose a reason for hiding this comment

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

Please replace $($nl) with ${nl}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Done :)

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

@raghav710 Thanks for your contribution! Hope to see you around more.

One side note: It's recommended to push new commits to address comments instead of squashing new fixes into the existing commit. In this way, the change history is preserved and it's very helpful for code reviews.

@raghav710
Copy link
Contributor Author

@daxian-dbw Thanks for the note. Will follow that henceforth during code reviews. As an aside, do you think it is good to squash the commits after approval as that would keep the history clean in case there were multiple code comments.
Heartfelt thanks to you and @mklement0 @iSazonov @SteveL-MSFT . The comments were quite helpful!

@iSazonov
Copy link
Collaborator

@raghav710 We want keep the history while we review. Then we usually Squash and Merge for simple changes. But if the code is very complex, tricky and add big feature we keep all commits.

@iSazonov iSazonov merged commit 7dd36c9 into PowerShell:master Oct 11, 2017
@iSazonov
Copy link
Collaborator

@mklement0 We merged the PR but we can always bring Out-String and Out-File into line until RTM.

@raghav710
Copy link
Contributor Author

Yaay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants