Skip to content

Commit

Permalink
Forward merge rel/5.3.x (pester#2163)
Browse files Browse the repository at this point in the history
Co-authored-by: James Steele <[email protected]>
Co-authored-by: Jakub Jareš <[email protected]>
Co-authored-by: Frode Flaten <[email protected]>
Co-authored-by: Aaron Jensen <[email protected]>
  • Loading branch information
4 people authored Apr 22, 2022
1 parent 4370ecc commit 48c3abc
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Pester.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RootModule = 'Pester.psm1'

# Version number of this module.
ModuleVersion = '5.3.0'
ModuleVersion = '5.3.1'

# ID used to uniquely identify this module
GUID = 'a699dea5-2c73-4616-a270-1f7abb777e71'
Expand Down
4 changes: 2 additions & 2 deletions src/csharp/Pester/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public static T[] GetArrayOrNull<T>(this IDictionary dictionary, string key) whe
if (dictionary[key] is PSObject o)
return new[] { (T)Convert.ChangeType(o.ToString(), typeof(string)) };

if (value is object[] v)
if (value is IList v)
{
try
{
var arr = new T[v.Length];
var arr = new T[v.Count];

var i = 0;
foreach (var j in v)
Expand Down
3 changes: 1 addition & 2 deletions src/functions/Coverage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,7 @@ function Get-TracerHitLocation ($command) {
# we also must avoid selecting a parent that is too high, otherwise we might mark code that was not covered as covered.
if ($parent -is [System.Management.Automation.Language.IfStatementAst] -or
$parent -is [System.Management.Automation.Language.ScriptBlockAst] -or
$parent -is [System.Management.Automation.Language.ForStatementAst] -or
$parent -is [System.Management.Automation.Language.ForEachStatementAst] -or
$parent -is [System.Management.Automation.Language.LoopStatementAst] -or
$parent -is [System.Management.Automation.Language.SwitchStatementAst] -or
$parent -is [System.Management.Automation.Language.TryStatementAst] -or
$parent -is [System.Management.Automation.Language.CatchClauseAst]) {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/Describe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function Invoke-Interactively ($CommandUsed, $ScriptName, $SessionState, $BoundP
$invokePester = {
param($private:Path, $private:ScriptParameters, $private:Out_Null)
$private:c = New-PesterContainer -Path $Path -Data $ScriptParameters
Invoke-Pester -Container $c Path | & $Out_Null
Invoke-Pester -Container $c | & $Out_Null
}

# get PSBoundParameters from caller script to allow interactive execution of parameterized tests.
Expand Down
6 changes: 3 additions & 3 deletions src/functions/New-MockObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ https://pester.dev/docs/usage/mocking
$historyName = "$($MethodHistoryPrefix)$($method.Key)"
$mockState = $mock.PSObject.Properties.Item("__mock")
if (-not $mockState) {
$mockState = @{}
$mock.PSObject.Properties.Add([Pester.Factory]::CreateNoteProperty("__mock", $mockState))
$mockState = [Pester.Factory]::CreateNoteProperty("__mock", @{});
$mock.PSObject.Properties.Add($mockState)
}

$mockState[$historyName] = @{
$mockState.Value[$historyName] = @{
Count = 0
Method = $method.Value
}
Expand Down
6 changes: 6 additions & 0 deletions tst/CoverageTestFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ catch {
finally {
$aaa = $true
}

$findIf = $true
while ($findIf) {
[string]$PartialText = "AAA"
$findIf = $false
}
9 changes: 9 additions & 0 deletions tst/PesterConfiguration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ Describe "PesterConfiguration.Format.ps1xml" {
}
}
}

Describe 'PesterConfiguration' {
It 'should convert arraylists' {
$expectedPaths = @('one', 'two', 'three')
$pathList = [Collections.ArrayList]$expectedPaths
$config = [PesterConfiguration]@{ Run = @{ Path = $pathList } }
$config.Run.Path.Value | Should -Be $expectedPaths
}
}
10 changes: 10 additions & 0 deletions tst/functions/New-MockObject.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ Describe 'New-MockObject' {
$mockObject._Kill[-1].Call | Should -Be 2
$mockObject._Kill[-1].Arguments | Should -Be $true
}

It "Adds 2 methods to the object" {
$mockObject = New-MockObject -Type 'Net.Sockets.TcpClient' -Methods @{
Connect = { param($Server, $Port)"connect" };
Close = { param($Server, $Port)"close" }
}

$mockObject.Connect() | Should -Be "connect"
$mockObject.Close() | Should -Be "close"
}
}


Expand Down

0 comments on commit 48c3abc

Please sign in to comment.