-
-
Notifications
You must be signed in to change notification settings - Fork 809
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
Fix tests on WinPS, PS Core Windows and Linux #533
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
37cc5c4
Tests pass on WinPS, PS Core Windows and Linux
rkeithhill 19a5ee9
Merge branch 'develop' into rkeithhill/fix-pester-tests
dahlbyk 07ea92c
Disable choco tests on non-Windows
rkeithhill 8097c28
Config Travis bld to only run tests in test dir
rkeithhill 6cc11d4
Switched from git to &$gitbin in more places
rkeithhill faa04b2
Try to exclude osx via stages filter
dahlbyk 5be371e
Try conditional job?
dahlbyk 4da7b87
Try filtering on type instead of branch
dahlbyk 23de00c
Limit gitbin to a single command
dahlbyk bc36a81
Enable PR build for this branch
dahlbyk 129aa5d
Attempt to fix last 2 macOS tests
rkeithhill 3964657
Fix bone-headed mistake, sigh
rkeithhill b9c49dd
Merge branch 'develop' into rkeithhill/fix-pester-tests
rkeithhill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,43 @@ | ||
. $PSScriptRoot\Shared.ps1 | ||
|
||
Describe 'Default Prompt Tests' { | ||
Describe 'Default Prompt Tests - NO ANSI' { | ||
BeforeAll { | ||
$GitPromptSettings.AnsiConsole = $false | ||
$prompt = Get-Item Function:\prompt | ||
$OFS = '' | ||
} | ||
BeforeEach { | ||
# Ensure these settings start out set to the default values | ||
$GitPromptSettings.DefaultPromptPrefix = '' | ||
$GitPromptSettings.DefaultPromptSuffix = '$(''>'' * ($nestedPromptLevel + 1)) ' | ||
$GitPromptSettings.DefaultPromptDebugSuffix = ' [DBG]$(''>'' * ($nestedPromptLevel + 1)) ' | ||
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $false | ||
$GitPromptSettings.DefaultPromptEnableTiming = $false | ||
$global:GitPromptSettings = & $module.NewBoundScriptBlock({[GitPromptSettings]::new()}) | ||
$GitPromptSettings.AnsiConsole = $false | ||
} | ||
|
||
Context 'Prompt with no Git summary' { | ||
It 'Returns the expected prompt string' { | ||
Set-Location $env:windir -ErrorAction Stop | ||
Set-Location $env:HOME -ErrorAction Stop | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "$env:windir> " | ||
$res | Should BeExactly "${env:HOME}> " | ||
} | ||
It 'Returns the expected prompt string with changed DefaultPromptPrefix' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptPrefix = 'PS ' | ||
$GitPromptSettings.DefaultPromptPrefix.Text = 'PS ' | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "PS $Home> " | ||
$res | Should BeExactly "PS ${Home}> " | ||
} | ||
It 'Returns the expected prompt string with expanded DefaultPromptPrefix' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptPrefix = '[$(hostname)] ' | ||
$GitPromptSettings.DefaultPromptPrefix.Text = '[$(hostname)] ' | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "[$(hostname)] $Home> " | ||
} | ||
It 'Returns the expected prompt string with changed DefaultPromptSuffix' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptSuffix = '`n> ' | ||
$GitPromptSettings.DefaultPromptSuffix.Text = '`n> ' | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "$Home`n> " | ||
} | ||
It 'Returns the expected prompt string with expanded DefaultPromptSuffix' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptSuffix = ' - $(6*7)> ' | ||
$GitPromptSettings.DefaultPromptSuffix.Text = ' - $(6*7)> ' | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "$Home - 42> " | ||
} | ||
|
@@ -53,8 +49,8 @@ Describe 'Default Prompt Tests' { | |
} | ||
It 'Returns the expected prompt string with prefix, suffix and abbrev home set' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptPrefix = '[$(hostname)] ' | ||
$GitPromptSettings.DefaultPromptSuffix = ' - $(6*7)> ' | ||
$GitPromptSettings.DefaultPromptPrefix.Text = '[$(hostname)] ' | ||
$GitPromptSettings.DefaultPromptSuffix.Text = ' - $(6*7)> ' | ||
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "[$(hostname)] ~ - 42> " | ||
|
@@ -74,23 +70,127 @@ Describe 'Default Prompt Tests' { | |
} | ||
|
||
It 'Returns the expected prompt string with status' { | ||
Mock git { | ||
Mock -ModuleName posh-git -CommandName git { | ||
$OFS = " " | ||
if ($args -contains 'rev-parse') { | ||
$res = Invoke-Expression "git.exe $args" | ||
$res = Invoke-Expression "&$gitbin $args" | ||
return $res | ||
} | ||
return @' | ||
Convert-NativeLineEnding -SplitLines @' | ||
## master | ||
A test/Foo.Tests.ps1 | ||
D test/Bar.Tests.ps1 | ||
M test/Baz.Tests.ps1 | ||
|
||
'@ -split [System.Environment]::NewLine | ||
} -ModuleName posh-git | ||
'@ | ||
} | ||
|
||
$res = [string](&$prompt 6>&1) | ||
Assert-MockCalled git -ModuleName posh-git | ||
Assert-MockCalled git -ModuleName posh-git -Scope It | ||
$res | Should BeExactly "$PSScriptRoot [master +1 ~0 -0 | +0 ~1 -1 !]> " | ||
} | ||
} | ||
} | ||
|
||
Describe 'Default Prompt Tests - ANSI' { | ||
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. 💯 |
||
BeforeAll { | ||
$prompt = Get-Item Function:\prompt | ||
$OFS = '' | ||
} | ||
BeforeEach { | ||
# Ensure these settings start out set to the default values | ||
$global:GitPromptSettings = & $module.NewBoundScriptBlock({[GitPromptSettings]::new()}) | ||
$GitPromptSettings.AnsiConsole = $true | ||
} | ||
|
||
Context 'Prompt with no Git summary' { | ||
It 'Returns the expected prompt string' { | ||
Set-Location $env:HOME -ErrorAction Stop | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "${env:HOME}> " | ||
} | ||
It 'Returns the expected prompt string with changed DefaultPromptSuffix' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptSuffix.Text = '`n> ' | ||
$GitPromptSettings.DefaultPromptSuffix.ForegroundColor = [ConsoleColor]::DarkBlue | ||
$GitPromptSettings.DefaultPromptSuffix.BackgroundColor = 0xFF6000 # Orange | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "$Home${csi}34m${csi}48;2;255;96;0m`n> ${csi}0m" | ||
} | ||
It 'Returns the expected prompt string with expanded DefaultPromptSuffix' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptSuffix.Text = ' - $(6*7)> ' | ||
$GitPromptSettings.DefaultPromptSuffix.ForegroundColor = [ConsoleColor]::DarkBlue | ||
$GitPromptSettings.DefaultPromptSuffix.BackgroundColor = 0xFF6000 # Orange | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "$Home${csi}34m${csi}48;2;255;96;0m - 42> ${csi}0m" | ||
} | ||
It 'Returns the expected prompt string with changed DefaultPromptPrefix' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptPrefix.Text = 'PS ' | ||
$GitPromptSettings.DefaultPromptPrefix.BackgroundColor = [ConsoleColor]::White | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "${csi}107mPS ${csi}0m${Home}> " | ||
} | ||
It 'Returns the expected prompt string with expanded DefaultPromptPrefix' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptPrefix.Text = '[$(hostname)] ' | ||
$GitPromptSettings.DefaultPromptPrefix.BackgroundColor = 0xF5F5F5 | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "${csi}48;2;245;245;245m[$(hostname)] ${csi}0m$Home> " | ||
} | ||
It 'Returns the expected prompt path colors' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true | ||
$GitPromptSettings.DefaultPromptPath.ForegroundColor = [ConsoleColor]::DarkCyan | ||
$GitPromptSettings.DefaultPromptPath.BackgroundColor = [ConsoleColor]::DarkRed | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "${csi}36m${csi}41m~${csi}0m> " | ||
} | ||
It 'Returns the expected prompt string with prefix, suffix and abbrev home set' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptPrefix.Text = '[$(hostname)] ' | ||
$GitPromptSettings.DefaultPromptPrefix.ForegroundColor = 0xF5F5F5 | ||
$GitPromptSettings.DefaultPromptSuffix.Text = ' - $(6*7)> ' | ||
$GitPromptSettings.DefaultPromptSuffix.ForegroundColor = [ConsoleColor]::DarkBlue | ||
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true | ||
$res = [string](&$prompt 6>&1) | ||
$res | Should BeExactly "${csi}38;2;245;245;245m[$(hostname)] ${csi}0m~${csi}34m - 42> ${csi}0m" | ||
} | ||
It 'Returns the expected prompt string with prompt timing enabled' { | ||
Set-Location $Home -ErrorAction Stop | ||
$GitPromptSettings.DefaultPromptEnableTiming = $true | ||
$GitPromptSettings.DefaultPromptTimingColor.ForegroundColor = [System.ConsoleColor]::Magenta | ||
$res = [string](&$prompt 6>&1) | ||
$escapedHome = [regex]::Escape($Home) | ||
$rexcsi = [regex]::Escape($csi) | ||
$res | Should Match "$escapedHome${rexcsi}95m${rexcsi}49m \d+ms${rexcsi}0m> " | ||
} | ||
} | ||
|
||
Context 'Prompt with Git summary' { | ||
BeforeAll { | ||
Set-Location $PSScriptRoot | ||
} | ||
|
||
It 'Returns the expected prompt string with status' { | ||
Mock -ModuleName posh-git git { | ||
if ($args -contains 'rev-parse') { | ||
$res = Invoke-Expression "&$gitbin $args" | ||
return $res | ||
} | ||
Convert-NativeLineEnding -SplitLines @' | ||
## master | ||
A test/Foo.Tests.ps1 | ||
D test/Bar.Tests.ps1 | ||
M test/Baz.Tests.ps1 | ||
|
||
'@ | ||
} | ||
|
||
$res = [string](&$prompt 6>&1) | ||
Assert-MockCalled git -ModuleName posh-git | ||
$res | Should BeExactly "$PSScriptRoot${csi}93m [${csi}0m${csi}96mmaster${csi}0m${csi}32m${csi}0m${csi}32m${csi}49m +1${csi}0m${csi}32m${csi}49m ~0${csi}0m${csi}32m${csi}49m -0${csi}0m${csi}93m |${csi}0m${csi}31m${csi}49m +0${csi}0m${csi}31m${csi}49m ~1${csi}0m${csi}31m${csi}49m -1${csi}0m${csi}31m !${csi}0m${csi}93m]${csi}0m> " | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If we're assuming no colors, is there a downside to setting the property directly (meaning a new span is created from the string constructor) instead of setting
Text
?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.
No, just a minor perf hit no one would likely notice.