Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8059,7 +8059,7 @@ internal ParseError(IScriptExtent extent, string errorId, string message, bool i
/// <returns></returns>
public override string ToString()
{
return PositionUtilities.VerboseMessage(Extent) + "\n" + Message;
return PositionUtilities.VerboseMessage(Extent) + Environment.NewLine + Message;
}

/// <summary>
Expand Down
20 changes: 20 additions & 0 deletions test/powershell/Language/Parser/Parsing.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,23 @@ Describe "Ternary Operator parsing" -Tags CI {
$expr.IfFalse | Should -BeOfType System.Management.Automation.Language.ConstantExpressionAst
}
}

Describe "ParserError type tests" -Tag CI {
# This test was added because there use to be a hardcoded newline in the ToString() method of
# the ParseError class. This makes sure the proper newlines are used.
It "Should use consistant newline depending on OS" {
$ers = $null
[System.Management.Automation.Language.Parser]::ParseInput('$x =', [ref]$null, [ref]$ers) | Out-Null
$measureResult = $ers[0].ToString() -split [System.Environment]::NewLine | Measure-Object

# We expect the string to have 4 lines. That means that if we split by NewLine for that platform,
# We should have 4 as the count.
$measureResult.Count | Should -BeExactly 4

# Just checking the above is not enough. We should also make sure that on non-Windows, there are no
# `r`n
if (!$IsWindows) {
$measureResult = $ers[0].ToString() | Should -Not -Contain "`r`n"
}
}
}