From e7a5259a6adf72da62e66193feb4781fedb08a12 Mon Sep 17 00:00:00 2001 From: Joe Skeen Date: Wed, 30 Oct 2024 14:44:56 -0600 Subject: [PATCH 01/23] Implement Cobertura coverage format (#2298) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * wip: Implement Cobertura coverage format * fix unit test * revert editor settings change * remove ?? operator * fix attribute ordering * make coverage report test work on all platforms * Fix windows paths * fix unit test for Windows paths * kick the build * re-implement Cobertura coverage report generation * fix compatibility issues * fix tests * removing Cobertura from v4 parameter options * fix compatibility with ReportGenerator * Update src/functions/Coverage.ps1 Co-authored-by: Frode Flaten <3436158+fflaten@users.noreply.github.com> * fix whitespace * fix output * fix windows paths * order packages,classes,methods by name * change Cobertura DTD to loose * Tune coverage report for performance * Remove outdated condition * Add Cobertura DTD file * Apply suggestions from code review Co-authored-by: Jakub Jareš * Fix typo and update JaCoCo starttime * Fix tests * Use epoch time for Cobertura and JaCoCo * Update test --------- Co-authored-by: Frode Flaten <3436158+fflaten@users.noreply.github.com> Co-authored-by: Jakub Jareš --- build.ps1 | 1 + publish/filesToPublish.ps1 | 1 + .../Pester/CodeCoverageConfiguration.cs | 2 +- src/en-US/about_PesterConfiguration.help.txt | 2 +- src/functions/Coverage.Plugin.ps1 | 14 +- src/functions/Coverage.ps1 | 242 +++++++++++++++++- src/schemas/Cobertura/coverage-loose.dtd | 61 +++++ tst/functions/Coverage.Tests.ps1 | 111 ++++++++ 8 files changed, 417 insertions(+), 17 deletions(-) create mode 100644 src/schemas/Cobertura/coverage-loose.dtd diff --git a/build.ps1 b/build.ps1 index 254e8484a..622dfbe47 100644 --- a/build.ps1 +++ b/build.ps1 @@ -202,6 +202,7 @@ if ($Clean) { , ("$PSScriptRoot/src/schemas/JUnit4/*.xsd", "$PSScriptRoot/bin/schemas/JUnit4/") , ("$PSScriptRoot/src/schemas/NUnit25/*.xsd", "$PSScriptRoot/bin/schemas/NUnit25/") , ("$PSScriptRoot/src/schemas/NUnit3/*.xsd", "$PSScriptRoot/bin/schemas/NUnit3/") + , ("$PSScriptRoot/src/schemas/Cobertura/*.dtd", "$PSScriptRoot/bin/schemas/Cobertura/") , ("$PSScriptRoot/src/schemas/JaCoCo/*.dtd", "$PSScriptRoot/bin/schemas/JaCoCo/") , ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net462/Pester.dll", "$PSScriptRoot/bin/bin/net462/") , ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net6.0/Pester.dll", "$PSScriptRoot/bin/bin/net6.0/") diff --git a/publish/filesToPublish.ps1 b/publish/filesToPublish.ps1 index 6ae35efc8..ec216ff18 100644 --- a/publish/filesToPublish.ps1 +++ b/publish/filesToPublish.ps1 @@ -8,6 +8,7 @@ 'bin/net6.0/Pester.dll' 'en-US/about_Pester.help.txt' 'en-US/about_PesterConfiguration.help.txt' + 'schemas/Cobertura/coverage-loose.dtd' 'schemas/JaCoCo/report.dtd' 'schemas/JUnit4/junit_schema_4.xsd' 'schemas/NUnit25/nunit_schema_2.5.xsd' diff --git a/src/csharp/Pester/CodeCoverageConfiguration.cs b/src/csharp/Pester/CodeCoverageConfiguration.cs index b43d7ece3..1f1b3eda0 100644 --- a/src/csharp/Pester/CodeCoverageConfiguration.cs +++ b/src/csharp/Pester/CodeCoverageConfiguration.cs @@ -41,7 +41,7 @@ public static CodeCoverageConfiguration ShallowClone(CodeCoverageConfiguration c public CodeCoverageConfiguration() : base("Options to enable and configure Pester's code coverage feature.") { Enabled = new BoolOption("Enable CodeCoverage.", false); - OutputFormat = new StringOption("Format to use for code coverage report. Possible values: JaCoCo, CoverageGutters", "JaCoCo"); + OutputFormat = new StringOption("Format to use for code coverage report. Possible values: JaCoCo, CoverageGutters, Cobertura", "JaCoCo"); OutputPath = new StringOption("Path relative to the current directory where code coverage report is saved.", "coverage.xml"); OutputEncoding = new StringOption("Encoding of the output file.", "UTF8"); Path = new StringArrayOption("Directories or files to be used for code coverage, by default the Path(s) from general settings are used, unless overridden here.", new string[0]); diff --git a/src/en-US/about_PesterConfiguration.help.txt b/src/en-US/about_PesterConfiguration.help.txt index 3ebe44620..c00ff5b29 100644 --- a/src/en-US/about_PesterConfiguration.help.txt +++ b/src/en-US/about_PesterConfiguration.help.txt @@ -99,7 +99,7 @@ SECTIONS AND OPTIONS Type: bool Default value: $false - OutputFormat: Format to use for code coverage report. Possible values: JaCoCo, CoverageGutters + OutputFormat: Format to use for code coverage report. Possible values: JaCoCo, CoverageGutters, Cobertura Type: string Default value: 'JaCoCo' diff --git a/src/functions/Coverage.Plugin.ps1 b/src/functions/Coverage.Plugin.ps1 index 809e058c6..bf507a034 100644 --- a/src/functions/Coverage.Plugin.ps1 +++ b/src/functions/Coverage.Plugin.ps1 @@ -145,11 +145,11 @@ $configuration = $run.PluginConfiguration.Coverage - if ($configuration.OutputFormat -in 'JaCoCo', 'CoverageGutters') { - [xml] $jaCoCoReport = [xml] (Get-JaCoCoReportXml -CommandCoverage $breakpoints -TotalMilliseconds $totalMilliseconds -CoverageReport $coverageReport -Format $configuration.OutputFormat) - } - else { - throw "CodeCoverage.CoverageFormat '$($configuration.OutputFormat)' is not valid, please review your configuration." + $coverageXmlReport = switch ($configuration.OutputFormat) { + 'JaCoCo' { [xml](Get-JaCoCoReportXml -CommandCoverage $breakpoints -TotalMilliseconds $totalMilliseconds -CoverageReport $coverageReport -Format 'JaCoCo') } + 'CoverageGutters' { [xml](Get-JaCoCoReportXml -CommandCoverage $breakpoints -TotalMilliseconds $totalMilliseconds -CoverageReport $coverageReport -Format 'CoverageGutters') } + 'Cobertura' { [xml](Get-CoberturaReportXml -CoverageReport $coverageReport -TotalMilliseconds $totalMilliseconds) } + default { throw "CodeCoverage.CoverageFormat '$($configuration.OutputFormat)' is not valid, please review your configuration." } } $settings = [Xml.XmlWriterSettings] @{ @@ -163,7 +163,7 @@ $stringWriter = [Pester.Factory]::CreateStringWriter() $xmlWriter = [Xml.XmlWriter]::Create($stringWriter, $settings) - $jaCocoReport.WriteContentTo($xmlWriter) + $coverageXmlReport.WriteContentTo($xmlWriter) $xmlWriter.Flush() $stringWriter.Flush() @@ -216,7 +216,7 @@ } function Resolve-CodeCoverageConfiguration { - $supportedFormats = 'JaCoCo', 'CoverageGutters' + $supportedFormats = 'JaCoCo', 'CoverageGutters', 'Cobertura' if ($PesterPreference.CodeCoverage.OutputFormat.Value -notin $supportedFormats) { throw (Get-StringOptionErrorMessage -OptionPath 'CodeCoverage.OutputFormat' -SupportedValues $supportedFormats -Value $PesterPreference.CodeCoverage.OutputFormat.Value) } diff --git a/src/functions/Coverage.ps1 b/src/functions/Coverage.ps1 index fb8f0e877..739ed90fc 100644 --- a/src/functions/Coverage.ps1 +++ b/src/functions/Coverage.ps1 @@ -810,13 +810,12 @@ function Get-JaCoCoReportXml { $isGutters = "CoverageGutters" -eq $Format - if ($null -eq $CoverageReport -or ('None' -eq $pester.Show) -or $CoverageReport.NumberOfCommandsAnalyzed -eq 0) { + if ($null -eq $CoverageReport -or $CoverageReport.NumberOfCommandsAnalyzed -eq 0) { return [string]::Empty } - $now = & $SafeCommands['Get-Date'] - $nineteenSeventy = & $SafeCommands['Get-Date'] -Date "01/01/1970" - [long] $endTime = [math]::Floor((New-TimeSpan -start $nineteenSeventy -end $now).TotalMilliseconds) + # Report uses unix epoch time format (milliseconds since midnight 1/1/1970 UTC) + [long] $endTime = [System.DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() [long] $startTime = [math]::Floor($endTime - $TotalMilliseconds) $folderGroups = $CommandCoverage | & $SafeCommands["Group-Object"] -Property { @@ -1038,6 +1037,224 @@ function Get-JaCoCoReportXml { return $xml } +function Get-CoberturaReportXml { + param ( + [parameter(Mandatory = $true)] + [object] $CoverageReport, + [parameter(Mandatory = $true)] + [long] $TotalMilliseconds + ) + + if ($null -eq $CoverageReport -or $CoverageReport.NumberOfCommandsAnalyzed -eq 0) { + return [string]::Empty + } + + # Report uses unix epoch time format (milliseconds since midnight 1/1/1970 UTC) + [long] $endTime = [System.DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() + [long] $startTime = [math]::Floor($endTime - $TotalMilliseconds) + + $commonRoot = Get-CommonParentPath -Path $CoverageReport.AnalyzedFiles + + $allLines = [System.Collections.Generic.List[object]]@() + $allLines.AddRange($CoverageReport.MissedCommands) + $allLines.AddRange($CoverageReport.HitCommands) + $packages = @{} + foreach ($command in $allLines) { + $package = & $SafeCommands["Split-Path"] $command.File -Parent + if (!$packages[$package]) { + $packages[$package] = @{ + Classes = @{} + } + } + + $class = $command.File + if (!$packages[$package].Classes[$class]) { + $packages[$package].Classes[$class] = @{ + Methods = @{} + Lines = @{} + } + } + + if (!$packages[$package].Classes[$class].Lines[$command.Line]) { + $packages[$package].Classes[$class].Lines[$command.Line] = [ordered]@{ number = $command.Line ; hits = 0 } + } + $packages[$package].Classes[$class].Lines[$command.Line].hits += $command.HitCount + + $method = $command.Function + if (!$method) { + continue + } + + if (!$packages[$package].Classes[$class].Methods[$method]) { + $packages[$package].Classes[$class].Methods[$method] = @{} + } + + if (!$packages[$package].Classes[$class].Methods[$method][$command.Line]) { + $packages[$package].Classes[$class].Methods[$method][$command.Line] = [ordered]@{ number = $command.Line ; hits = 0 } + } + $packages[$package].Classes[$class].Methods[$method][$command.Line].hits += $command.HitCount + } + + $packages = foreach ($packageGroup in $packages.GetEnumerator()) { + $classGroups = $packageGroup.Value.Classes + $classes = foreach ($classGroup in $classGroups.GetEnumerator()) { + $methodGroups = $classGroup.Value.Methods + $methods = foreach ($methodGroup in $methodGroups.GetEnumerator()) { + $lines = ([object[]]$methodGroup.Value.Values) | New-LineNode + $coveredLines = foreach ($line in $lines) { if (0 -lt $line.attributes.hits) { $line } } + + $method = [ordered]@{ + name = 'method' + attributes = [ordered]@{ + name = $methodGroup.Name + signature = '()' + } + children = [ordered]@{ + lines = $lines | & $SafeCommands["Sort-Object"] { [int]$_.attributes.number } + } + totalLines = $lines.Length + coveredLines = $coveredLines.Length + } + + $method + } + + $lines = ([object[]]$classGroup.Value.Lines.Values) | New-LineNode + $coveredLines = foreach ($line in $lines) { if (0 -lt $line.attributes.hits) { $line } } + + $lineRate = Get-LineRate -CoveredLines $coveredLines.Length -TotalLines $lines.Length + $filename = $classGroup.Name.Substring($commonRoot.Length).Replace('\', '/').TrimStart('/') + + $class = [ordered]@{ + name = 'class' + attributes = [ordered]@{ + name = (& $SafeCommands["Split-Path"] $classGroup.Name -Leaf) + filename = $filename + 'line-rate' = $lineRate + 'branch-rate' = 1 + } + children = [ordered]@{ + methods = $methods | & $SafeCommands["Sort-Object"] { $_.attributes.name } + lines = $lines | & $SafeCommands["Sort-Object"] { [int]$_.attributes.number } + } + totalLines = $lines.Length + coveredLines = $coveredLines.Length + } + + $class + } + + $totalLines = ($classes.totalLines | & $SafeCommands["Measure-Object"] -Sum).Sum + $coveredLines = ($classes.coveredLines | & $SafeCommands["Measure-Object"] -Sum).Sum + $lineRate = Get-LineRate -CoveredLines $coveredLines -TotalLines $totalLines + $packageName = $packageGroup.Name.Substring($commonRoot.Length).Replace('\', '/').TrimStart('/') + + $package = [ordered]@{ + name = 'package' + attributes = [ordered]@{ + name = $packageName + 'line-rate' = $lineRate + 'branch-rate' = 0 + } + children = [ordered]@{ + classes = $classes | & $SafeCommands["Sort-Object"] { $_.attributes.name } + } + totalLines = $totalLines + coveredLines = $coveredLines + } + + $package + } + + $totalLines = ($packages.totalLines | & $SafeCommands["Measure-Object"] -Sum).Sum + $coveredLines = ($packages.coveredLines | & $SafeCommands["Measure-Object"] -Sum).Sum + $lineRate = Get-LineRate -CoveredLines $coveredLines -TotalLines $totalLines + + $coverage = [ordered]@{ + name = 'coverage' + attributes = [ordered]@{ + 'lines-valid' = $totalLines + 'lines-covered' = $coveredLines + 'line-rate' = $lineRate + 'branches-valid' = 0 + 'branches-covered' = 0 + 'branch-rate' = 1 + timestamp = $startTime + version = 0.1 + } + children = [ordered]@{ + sources = [ordered]@{ + name = 'source' + value = $commonRoot.Replace('\', '/') + } + packages = $packages | & $SafeCommands["Sort-Object"] { $_.attributes.name } + } + } + + $xmlDeclaration = '' + $docType = '' + $coverageXml = ConvertTo-XmlElement -Node $coverage + $document = "$xmlDeclaration`n$docType`n$($coverageXml.OuterXml)" + + $document +} + +function New-LineNode { + param( + [parameter(Mandatory = $true, ValueFromPipeline = $true)] [object] $LineObject + ) + + process { + [ordered]@{ + name = 'line' + attributes = $LineObject + } + } +} + +function Get-LineRate { + param( + [parameter(Mandatory = $true)] [int] $CoveredLines, + [parameter(Mandatory = $true)] [int] $TotalLines + ) + + [double]$denominator = if ($TotalLines) { $TotalLines } else { 1 } + + $CoveredLines / $denominator +} + +function ConvertTo-XmlElement { + param( + [parameter(Mandatory = $true)] [object] $Node + ) + + $element = ([xml]"<$($Node.name)/>").DocumentElement + if ($node.attributes) { + $attributes = $node.attributes + foreach ($attr in $attributes.GetEnumerator()) { + $element.SetAttribute($attr.Name, $attr.Value) + } + } + if ($node.children) { + $children = $node.children + foreach ($child in $children.GetEnumerator()) { + $childElement = ([xml]"<$($child.Name)/>").DocumentElement + foreach ($value in $child.Value) { + $childXml = ConvertTo-XmlElement $value + $importedChildXml = $childElement.OwnerDocument.ImportNode($childXml, $true) + $null = $childElement.AppendChild($importedChildXml) + } + $importedChild = $element.OwnerDocument.ImportNode($childElement, $true) + $null = $element.AppendChild($importedChild) + } + } + if ($node.value) { + $element.InnerText = $node.value + } + + $element +} + function Add-XmlElement { param ( [parameter(Mandatory = $true)] [System.Xml.XmlNode] $Parent, @@ -1046,14 +1263,23 @@ function Add-XmlElement { ) $element = $Parent.AppendChild($Parent.OwnerDocument.CreateElement($Name)) if ($Attributes) { - foreach ($key in $Attributes.Keys) { - $attribute = $element.Attributes.Append($Parent.OwnerDocument.CreateAttribute($key)) - $attribute.Value = $Attributes.$key - } + Add-XmlAttribute -Element $element -Attributes $Attributes } return $element } +function Add-XmlAttribute { + param( + [parameter(Mandatory = $true)] [System.Xml.XmlNode] $Element, + [parameter(Mandatory = $true)] [System.Collections.IDictionary] $Attributes + ) + + foreach ($key in $Attributes.Keys) { + $attribute = $Element.Attributes.Append($Element.OwnerDocument.CreateAttribute($key)) + $attribute.Value = $Attributes.$key + } +} + function Add-JaCoCoCounter { param ( [parameter(Mandatory = $true)] [ValidateSet('Instruction', 'Line', 'Method', 'Class')] [string] $Type, diff --git a/src/schemas/Cobertura/coverage-loose.dtd b/src/schemas/Cobertura/coverage-loose.dtd new file mode 100644 index 000000000..35c8272d2 --- /dev/null +++ b/src/schemas/Cobertura/coverage-loose.dtd @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tst/functions/Coverage.Tests.ps1 b/tst/functions/Coverage.Tests.ps1 index 7b87327d8..5cdfd83db 100644 --- a/tst/functions/Coverage.Tests.ps1 +++ b/tst/functions/Coverage.Tests.ps1 @@ -494,6 +494,110 @@ InPesterModuleScope { ') } + It 'Cobertura report must be correct' { + [String]$coberturaReportXml = Get-CoberturaReportXml -TotalMilliseconds 10000 -CoverageReport $coverageReport + $coberturaReportXml = $coberturaReportXml -replace 'timestamp="[0-9]*"', 'timestamp=""' + $coberturaReportXml = $coberturaReportXml -replace "$([System.Environment]::NewLine)", '' + $coberturaReportXml = $coberturaReportXml.Replace($root, 'CommonRoot') + $coberturaReportXml = $coberturaReportXml.Replace($root.Replace('\', '/'), 'CommonRoot') + (Clear-WhiteSpace $coberturaReportXml) | Should -Be (Clear-WhiteSpace ' + + + + + CommonRoot + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ') + } + It 'JaCoCo returns empty string when there are 0 analyzed commands' { $coverageReport = [PSCustomObject] @{ NumberOfCommandsAnalyzed = 0 } [String]$jaCoCoReportXml = Get-JaCoCoReportXml -CommandCoverage @{} -TotalMilliseconds 10000 -CoverageReport $coverageReport -Format "CoverageGutters" @@ -501,6 +605,13 @@ InPesterModuleScope { $jaCoCoReportXml | Should -Be ([String]::Empty) } + It 'Cobertura returns empty string when there are 0 analyzed commands' { + $coverageReport = [PSCustomObject] @{ NumberOfCommandsAnalyzed = 0 } + [String]$coberturaReportXml = Get-CoberturaReportXml -CoverageReport $coverageReport -TotalMilliseconds 10000 + $coberturaReportXml | Should -Not -Be $null + $coberturaReportXml | Should -Be ([String]::Empty) + } + It 'Reports the right line numbers' { $coverageReport.HitCommands[$coverageReport.NumberOfCommandsExecuted - 1].Line | Should -Be 1 $coverageReport.HitCommands[$coverageReport.NumberOfCommandsExecuted - 1].StartLine | Should -Be 1 From 65a2a31bf0089e3cf1544bb0dd59cc12112a1869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 30 Oct 2024 22:05:09 +0100 Subject: [PATCH 02/23] Add -Count to Should-BeCollection (#2567) * Add -Count to Should-BeCollection * Message fixes --- .../assert/Collection/Should-BeCollection.ps1 | 27 ++++++++++++++----- .../Collection/Should-BeCollection.Tests.ps1 | 22 +++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/functions/assert/Collection/Should-BeCollection.ps1 b/src/functions/assert/Collection/Should-BeCollection.ps1 index c6643dcce..67af94ccd 100644 --- a/src/functions/assert/Collection/Should-BeCollection.ps1 +++ b/src/functions/assert/Collection/Should-BeCollection.ps1 @@ -9,6 +9,9 @@ .PARAMETER Actual A collection of items. + .PARAMETER Count + Checks if the collection has the expected number of items. + .PARAMETER Because The reason why the input should be the expected value. @@ -41,26 +44,36 @@ param ( [Parameter(Position = 1, ValueFromPipeline = $true)] $Actual, - [Parameter(Position = 0, Mandatory)] + [Parameter(Position = 0, Mandatory, ParameterSetName = 'Expected')] $Expected, - [String]$Because + [String]$Because, + [Parameter(ParameterSetName = 'Count')] + [int] $Count ) $collectedInput = Collect-Input -ParameterInput $Actual -PipelineInput $local:Input -IsPipelineInput $MyInvocation.ExpectingInput $Actual = $collectedInput.Actual - if (-not (Is-Collection -Value $Expected)) { - $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Expected is not a collection." + if (-not (Is-Collection -Value $Actual)) { + $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Actual is not a collection." throw [Pester.Factory]::CreateShouldErrorRecord($Message, $MyInvocation.ScriptName, $MyInvocation.ScriptLineNumber, $MyInvocation.Line.TrimEnd([System.Environment]::NewLine), $true) } - if (-not (Is-Collection -Value $Actual)) { - $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Actual is not a collection." + if ($PSCmdlet.ParameterSetName -eq 'Count') { + if ($Count -ne $Actual.Count) { + $Message = Get-AssertionMessage -Expected $Count -Actual $Actual -Because $Because -Data @{ actualCount = $Actual.Count } -DefaultMessage "Expected items in , but it has items." + throw [Pester.Factory]::CreateShouldErrorRecord($Message, $MyInvocation.ScriptName, $MyInvocation.ScriptLineNumber, $MyInvocation.Line.TrimEnd([System.Environment]::NewLine), $true) + } + return + } + + if (-not (Is-Collection -Value $Expected)) { + $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Expected is not a collection." throw [Pester.Factory]::CreateShouldErrorRecord($Message, $MyInvocation.ScriptName, $MyInvocation.ScriptLineNumber, $MyInvocation.Line.TrimEnd([System.Environment]::NewLine), $true) } if (-not (Is-CollectionSize -Expected $Expected -Actual $Actual)) { - $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Expected to be present in , but they don't have the same number of items." + $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Expected to be present in , but they don't have the same number of items." throw [Pester.Factory]::CreateShouldErrorRecord($Message, $MyInvocation.ScriptName, $MyInvocation.ScriptLineNumber, $MyInvocation.Line.TrimEnd([System.Environment]::NewLine), $true) } diff --git a/tst/functions/assert/Collection/Should-BeCollection.Tests.ps1 b/tst/functions/assert/Collection/Should-BeCollection.Tests.ps1 index ef5dab0de..7038df09c 100644 --- a/tst/functions/assert/Collection/Should-BeCollection.Tests.ps1 +++ b/tst/functions/assert/Collection/Should-BeCollection.Tests.ps1 @@ -24,4 +24,26 @@ Describe "Should-BeCollection" { $err = { $actual | Should-BeCollection $expected } | Verify-AssertionFailed $err.Exception.Message | Verify-Equal "Expected [Object[]] @(5, 6, 7, 8, 9) to be present in [Object[]] @(1, 2, 3, 4, 5) in any order, but some values were not.`nMissing in actual: '6 (index 1), 7 (index 2), 8 (index 3), 9 (index 4)'`nExtra in actual: '1 (index 0), 2 (index 1), 3 (index 2), 4 (index 3)'" } + + Describe "-Count" { + It "Counts empty collection @() correctly" { + @() | Should-BeCollection -Count 0 + } + + It "Counts collection with one item correctly" -ForEach @( + @(1), + (, @()), # array in array + @($null), + @(""), + # we also cannot distinguish between a single item and a single item array + 1 + ) { + $_ | Should-BeCollection -Count 1 + } + + It "Fails when collection does not have the expected number of items" { + $err = { @(1, 2) | Should-BeCollection -Count 3 } | Verify-AssertionFailed + $err.Exception.Message | Verify-Equal "Expected 3 items in [Object[]] @(1, 2), but it has 2 items." + } + } } From e4f9092ac0a7ad97db5a34067789f89509713ca9 Mon Sep 17 00:00:00 2001 From: Frode Flaten <3436158+fflaten@users.noreply.github.com> Date: Wed, 30 Oct 2024 22:05:29 +0100 Subject: [PATCH 03/23] Throw on unbound user-provided scriptblocks (#2551) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Block unbound scriptblocks as input * Improve error message for unbound scriptblock input to clarify potential issues Co-authored-by: Jakub Jareš --------- Co-authored-by: Jakub Jareš --- src/Main.ps1 | 4 ++ src/Pester.Runtime.ps1 | 21 +++++++++ src/functions/Context.ps1 | 2 + src/functions/Describe.ps1 | 2 + src/functions/It.ps1 | 2 + src/functions/SetupTeardown.ps1 | 4 ++ .../assert/Collection/Should-All.ps1 | 1 + .../assert/Collection/Should-Any.ps1 | 2 + .../assert/Exception/Should-Throw.ps1 | 2 + tst/Pester.RSpec.ts.ps1 | 44 +++++++++++++++++++ tst/functions/Add-ShouldOperator.ts.ps1 | 11 +++++ tst/functions/Context.Tests.ps1 | 9 +++- tst/functions/Describe.Tests.ps1 | 5 +++ tst/functions/It.Tests.ps1 | 24 ++++++++++ tst/functions/Mock.Tests.ps1 | 12 ++++- tst/functions/SetupTeardown.Tests.ps1 | 19 ++++++++ .../assert/Collection/Should-All.Tests.ps1 | 6 +++ .../assert/Collection/Should-Any.Tests.ps1 | 6 +++ .../assert/Exception/Should-Throw.Tests.ps1 | 7 ++- 19 files changed, 179 insertions(+), 4 deletions(-) create mode 100644 tst/functions/It.Tests.ps1 diff --git a/src/Main.ps1 b/src/Main.ps1 index 900978ef2..2c71b497f 100644 --- a/src/Main.ps1 +++ b/src/Main.ps1 @@ -80,6 +80,8 @@ function Add-ShouldOperator { [switch] $SupportsArrayInput ) + Assert-BoundScriptBlockInput -ScriptBlock $Test + $entry = [PSCustomObject]@{ Test = $Test SupportsArrayInput = [bool]$SupportsArrayInput @@ -1260,6 +1262,8 @@ function BeforeDiscovery { [ScriptBlock]$ScriptBlock ) + Assert-BoundScriptBlockInput -ScriptBlock $ScriptBlock + if ($ExecutionContext.SessionState.PSVariable.Get('invokedViaInvokePester')) { if ($state.CurrentBlock.IsRoot -and -not $state.CurrentBlock.FrameworkData.MissingParametersProcessed) { # For undefined parameters in container, add parameter's default value to Data diff --git a/src/Pester.Runtime.ps1 b/src/Pester.Runtime.ps1 index 965ac9ab2..40ef93a56 100644 --- a/src/Pester.Runtime.ps1 +++ b/src/Pester.Runtime.ps1 @@ -2474,6 +2474,10 @@ function New-BlockContainerObject { default { throw [System.ArgumentOutOfRangeException]'' } } + if ($item -is [scriptblock]) { + Assert-BoundScriptBlockInput -ScriptBlock $item + } + $c = [Pester.ContainerInfo]::Create() $c.Type = $type $c.Item = $item @@ -2604,3 +2608,20 @@ function Add-MissingContainerParameters ($RootBlock, $Container, $CallingFunctio $RootBlock.FrameworkData.MissingParametersProcessed = $true } + +function Assert-BoundScriptBlockInput { + param( + [Parameter(Mandatory = $true)] + [ScriptBlock] $ScriptBlock + ) + $internalSessionState = $script:ScriptBlockSessionStateInternalProperty.GetValue($ScriptBlock, $null) + if ($null -eq $internalSessionState) { + $maxLength = 250 + $prettySb = (Format-Nicely2 $ScriptBlock) -replace '\s{2,}', ' ' + if ($prettySb.Length -gt $maxLength) { + $prettySb = "$($prettySb.Remove($maxLength))..." + } + + throw [System.ArgumentException]::new("Unbound scriptblock is not allowed, because it would run inside of Pester session state and produce unexpected results. See https://github.com/pester/Pester/issues/2411 for more details and workarounds. ScriptBlock: '$prettySb'") + } +} diff --git a/src/functions/Context.ps1 b/src/functions/Context.ps1 index 3af6a1e9e..6f6e506a2 100644 --- a/src/functions/Context.ps1 +++ b/src/functions/Context.ps1 @@ -105,6 +105,8 @@ } } + Assert-BoundScriptBlockInput -ScriptBlock $Fixture + if ($ExecutionContext.SessionState.PSVariable.Get('invokedViaInvokePester')) { if ($state.CurrentBlock.IsRoot -and -not $state.CurrentBlock.FrameworkData.MissingParametersProcessed) { # For undefined parameters in container, add parameter's default value to Data diff --git a/src/functions/Describe.ps1 b/src/functions/Describe.ps1 index 577e648c0..d46bb190c 100644 --- a/src/functions/Describe.ps1 +++ b/src/functions/Describe.ps1 @@ -113,6 +113,8 @@ } } + Assert-BoundScriptBlockInput -ScriptBlock $Fixture + if ($ExecutionContext.SessionState.PSVariable.Get('invokedViaInvokePester')) { if ($state.CurrentBlock.IsRoot -and -not $state.CurrentBlock.FrameworkData.MissingParametersProcessed) { # For undefined parameters in container, add parameter's default value to Data diff --git a/src/functions/It.ps1 b/src/functions/It.ps1 index f3015d48a..1efa922f1 100644 --- a/src/functions/It.ps1 +++ b/src/functions/It.ps1 @@ -152,6 +152,8 @@ } } + Assert-BoundScriptBlockInput -ScriptBlock $Test + if ($PSBoundParameters.ContainsKey('ForEach')) { if ($null -eq $ForEach -or 0 -eq @($ForEach).Count) { if ($PesterPreference.Run.FailOnNullOrEmptyForEach.Value -and -not $AllowNullOrEmptyForEach) { diff --git a/src/functions/SetupTeardown.ps1 b/src/functions/SetupTeardown.ps1 index 55824742d..b83c61a24 100644 --- a/src/functions/SetupTeardown.ps1 +++ b/src/functions/SetupTeardown.ps1 @@ -57,6 +57,7 @@ $Scriptblock ) Assert-DescribeInProgress -CommandName BeforeEach + Assert-BoundScriptBlockInput -ScriptBlock $Scriptblock New-EachTestSetup -ScriptBlock $Scriptblock } @@ -123,6 +124,7 @@ function AfterEach { $Scriptblock ) Assert-DescribeInProgress -CommandName AfterEach + Assert-BoundScriptBlockInput -ScriptBlock $Scriptblock New-EachTestTeardown -ScriptBlock $Scriptblock } @@ -198,6 +200,7 @@ function BeforeAll { [Scriptblock] $Scriptblock ) + Assert-BoundScriptBlockInput -ScriptBlock $Scriptblock New-OneTimeTestSetup -ScriptBlock $Scriptblock } @@ -265,6 +268,7 @@ function AfterAll { $Scriptblock ) Assert-DescribeInProgress -CommandName AfterAll + Assert-BoundScriptBlockInput -ScriptBlock $Scriptblock New-OneTimeTestTeardown -ScriptBlock $Scriptblock } diff --git a/src/functions/assert/Collection/Should-All.ps1 b/src/functions/assert/Collection/Should-All.ps1 index 1f8dfeab4..90d285320 100644 --- a/src/functions/assert/Collection/Should-All.ps1 +++ b/src/functions/assert/Collection/Should-All.ps1 @@ -45,6 +45,7 @@ [String]$Because ) + Assert-BoundScriptBlockInput -ScriptBlock $FilterScript $Expected = $FilterScript $collectedInput = Collect-Input -ParameterInput $Actual -PipelineInput $local:Input -IsPipelineInput $MyInvocation.ExpectingInput diff --git a/src/functions/assert/Collection/Should-Any.ps1 b/src/functions/assert/Collection/Should-Any.ps1 index bd2f970b0..f01d96183 100644 --- a/src/functions/assert/Collection/Should-Any.ps1 +++ b/src/functions/assert/Collection/Should-Any.ps1 @@ -44,6 +44,8 @@ [String]$Because ) + Assert-BoundScriptBlockInput -ScriptBlock $FilterScript + $Expected = $FilterScript $collectedInput = Collect-Input -ParameterInput $Actual -PipelineInput $local:Input -IsPipelineInput $MyInvocation.ExpectingInput $Actual = $collectedInput.Actual diff --git a/src/functions/assert/Exception/Should-Throw.ps1 b/src/functions/assert/Exception/Should-Throw.ps1 index d2606b6b1..9f75e26e0 100644 --- a/src/functions/assert/Exception/Should-Throw.ps1 +++ b/src/functions/assert/Exception/Should-Throw.ps1 @@ -67,6 +67,8 @@ function Should-Throw { $collectedInput = Collect-Input -ParameterInput $ScriptBlock -PipelineInput $local:Input -IsPipelineInput $MyInvocation.ExpectingInput -UnrollInput $ScriptBlock = $collectedInput.Actual + Assert-BoundScriptBlockInput -ScriptBlock $ScriptBlock + $errorThrown = $false $err = $null try { diff --git a/tst/Pester.RSpec.ts.ps1 b/tst/Pester.RSpec.ts.ps1 index bc400befa..2002e4d78 100644 --- a/tst/Pester.RSpec.ts.ps1 +++ b/tst/Pester.RSpec.ts.ps1 @@ -1668,6 +1668,12 @@ i -PassThru:$PassThru { } } } + + t "Does not accept unbound scriptblocks" { + # Would execute in Pester's internal module state + $ex = { New-PesterContainer -ScriptBlock ([ScriptBlock]::Create('$true')) } | Verify-Throw + $ex.Exception.Message | Verify-Like 'Unbound scriptblock*' + } } b "BeforeDiscovery" { @@ -1691,6 +1697,15 @@ i -PassThru:$PassThru { $r.Containers[0].Blocks[0].Tests[0].Result | Verify-Equal "Passed" $r.Containers[0].Blocks[1].Tests[0].Result | Verify-Equal "Passed" } + + t "Does not accept unbound scriptblocks" { + # Would execute in Pester's internal module state + $sb = { BeforeDiscovery ([ScriptBlock]::Create('$true')) } + $container = New-PesterContainer -ScriptBlock $sb + $r = Invoke-Pester -Container $container -PassThru + $r.Containers[0].Result | Verify-Equal 'Failed' + $r.Containers[0].ErrorRecord.Exception.Message | Verify-Like 'Unbound scriptblock*' + } } b "Parametric tests" { @@ -2922,4 +2937,33 @@ i -PassThru:$PassThru { $pwd.Path | Verify-Equal $beforePWD } } + + b 'Unbound scriptblocks' { + # Would execute in Pester's internal module state + t 'Throws when provided to Run.ScriptBlock' { + $sb = [scriptblock]::Create('') + $conf = New-PesterConfiguration + $conf.Run.ScriptBlock = $sb + $conf.Run.Throw = $true + $conf.Output.CIFormat = 'None' + + $ex = { Invoke-Pester -Configuration $conf } | Verify-Throw + $ex.Exception.Message | Verify-Like '*Unbound scriptblock*' + } + + t 'Throws when provided to Run.Container' { + $c = [Pester.ContainerInfo]::Create() + $c.Type = 'ScriptBlock' + $c.Item = [scriptblock]::Create('') + $c.Data = @{} + + $conf = New-PesterConfiguration + $conf.Run.Container = $c + $conf.Run.Throw = $true + $conf.Output.CIFormat = 'None' + + $ex = { Invoke-Pester -Configuration $conf } | Verify-Throw + $ex.Exception.Message | Verify-Like '*Unbound scriptblock*' + } + } } diff --git a/tst/functions/Add-ShouldOperator.ts.ps1 b/tst/functions/Add-ShouldOperator.ts.ps1 index 71c4143c9..4d5be5a08 100644 --- a/tst/functions/Add-ShouldOperator.ts.ps1 +++ b/tst/functions/Add-ShouldOperator.ts.ps1 @@ -70,6 +70,17 @@ i -PassThru:$PassThru { } } + b 'Add-ShouldOperator input validation' { + Get-Module Pester | Remove-Module + Import-Module "$PSScriptRoot\..\..\bin\Pester.psd1" + + t 'Does not allow unbound scriptblocks' { + # Would execute in Pester's internal module state + $ex = { Add-ShouldOperator -Name DenyUnbound -Test ([ScriptBlock]::Create('$true')) } | Verify-Throw + $ex.Exception.Message | Verify-Like 'Unbound scriptblock*' + } + } + b 'Executing custom Should assertions' { # Testing paramter and output syntax described in docs (https://pester.dev/docs/assertions/custom-assertions) Get-Module Pester | Remove-Module diff --git a/tst/functions/Context.Tests.ps1 b/tst/functions/Context.Tests.ps1 index 2ce94eaa7..c962c322a 100644 --- a/tst/functions/Context.Tests.ps1 +++ b/tst/functions/Context.Tests.ps1 @@ -7,7 +7,7 @@ Describe 'Testing Context' { } } - } | should -Throw 'Test fixture name has multiple lines and no test fixture is provided. (Have you provided a name for the test group?)' + } | Should -Throw 'Test fixture name has multiple lines and no test fixture is provided. (Have you provided a name for the test group?)' } It "Has a name that looks like a script block" { @@ -17,6 +17,11 @@ Describe 'Testing Context' { } } - } | should -Throw 'No test fixture is provided. (Have you put the open curly brace on the next line?)' + } | Should -Throw 'No test fixture is provided. (Have you put the open curly brace on the next line?)' + } + + It 'Throws when provided unbound scriptblock' { + # Unbound scriptblocks would execute in Pester's internal module state + { Context 'c' -Fixture ([scriptblock]::Create('')) } | Should -Throw -ExpectedMessage 'Unbound scriptblock*' } } diff --git a/tst/functions/Describe.Tests.ps1 b/tst/functions/Describe.Tests.ps1 index 0ade9f093..fa292512e 100644 --- a/tst/functions/Describe.Tests.ps1 +++ b/tst/functions/Describe.Tests.ps1 @@ -36,6 +36,11 @@ Describe 'Testing Describe' { } } | Should -Throw 'Test fixture name has multiple lines and no test fixture is provided. (Have you provided a name for the test group?)' } + + It 'Throws when provided unbound scriptblock' { + # Unbound scriptblocks would execute in Pester's internal module state + { Describe 'd' -Fixture ([scriptblock]::Create('')) } | Should -Throw -ExpectedMessage 'Unbound scriptblock*' + } } diff --git a/tst/functions/It.Tests.ps1 b/tst/functions/It.Tests.ps1 new file mode 100644 index 000000000..6249f10af --- /dev/null +++ b/tst/functions/It.Tests.ps1 @@ -0,0 +1,24 @@ +Set-StrictMode -Version Latest + +Describe 'Testing It' { + It 'Throws when missing name' { + { It { + + 'something' + } + } | Should -Throw -ExpectedMessage 'Test name has multiple lines and no test scriptblock is provided*' + } + + It 'Throws when missing scriptblock' { + { It 'runs a test' + { + # This scriptblock is a new statement as scriptblock didn't start on It-line nor used a backtick + } + } | Should -Throw -ExpectedMessage 'No test scriptblock is provided*' + } + + It 'Throws when provided unbound scriptblock' { + # Unbound scriptblocks would execute in Pester's internal module state + { It 'i' -Test ([scriptblock]::Create('')) } | Should -Throw -ExpectedMessage 'Unbound scriptblock*' + } +} diff --git a/tst/functions/Mock.Tests.ps1 b/tst/functions/Mock.Tests.ps1 index ab769e95a..b3853dca6 100644 --- a/tst/functions/Mock.Tests.ps1 +++ b/tst/functions/Mock.Tests.ps1 @@ -2366,15 +2366,25 @@ Describe 'Naming conflicts in mocked functions' { } Describe 'Passing unbound script blocks as mocks' { - It 'Does not produce an error' { + BeforeAll { function TestMe { 'Original' } + } + It 'Does not produce an error' { $scriptBlock = [scriptblock]::Create('"Mocked"') { Mock TestMe $scriptBlock } | Should -Not -Throw TestMe | Should -Be Mocked } + + It 'Should not execute in Pester internal state' { + $filter = [scriptblock]::Create('if ("pester" -eq $ExecutionContext.SessionState.Module) { throw "executed parameter filter in internal state" } else { $true }') + $scriptBlock = [scriptblock]::Create('if ("pester" -eq $ExecutionContext.SessionState.Module) { throw "executed mock in internal state" } else { "Mocked" }') + + { Mock -CommandName TestMe -ParameterFilter $filter -MockWith $scriptBlock } | Should -Not -Throw + TestMe -SomeParam | Should -Be Mocked + } } Describe 'Should -Invoke when mock called outside of It block' { diff --git a/tst/functions/SetupTeardown.Tests.ps1 b/tst/functions/SetupTeardown.Tests.ps1 index 864ffa0e2..8b0f6236f 100644 --- a/tst/functions/SetupTeardown.Tests.ps1 +++ b/tst/functions/SetupTeardown.Tests.ps1 @@ -190,6 +190,25 @@ Describe 'Finishing TestGroup Setup and Teardown tests' { } } +Describe 'Unbound scriptsblocks as input' { + # Unbound scriptblocks would execute in Pester's internal module state + BeforeAll { + $sb = [scriptblock]::Create('') + $expectedMessage = 'Unbound scriptblock*' + } + It 'Throws when provided to BeforeAll' { + { BeforeAll -Scriptblock $sb } | Should -Throw -ExpectedMessage $expectedMessage + } + It 'Throws when provided to AfterAll' { + { AfterAll -Scriptblock $sb } | Should -Throw -ExpectedMessage $expectedMessage + } + It 'Throws when provided to BeforeEach' { + { BeforeEach -Scriptblock $sb } | Should -Throw -ExpectedMessage $expectedMessage + } + It 'Throws when provided to AfterEach' { + { AfterEach -Scriptblock $sb } | Should -Throw -ExpectedMessage $expectedMessage + } +} # if ($PSVersionTable.PSVersion.Major -ge 3) { # # TODO: this depends on the old pester internals it would be easier to test in P diff --git a/tst/functions/assert/Collection/Should-All.Tests.ps1 b/tst/functions/assert/Collection/Should-All.Tests.ps1 index b02c7efca..51e431664 100644 --- a/tst/functions/assert/Collection/Should-All.Tests.ps1 +++ b/tst/functions/assert/Collection/Should-All.Tests.ps1 @@ -57,4 +57,10 @@ Expected [int] 2, but got [int] 1." -replace "`r`n", "`n") It 'It fails when the only item not matching the filter is 0' { { 0 | Should-All -FilterScript { $_ -gt 0 } } | Verify-AssertionFailed } + + It 'Throws when provided unbound scriptblock' { + # Unbound scriptblocks would execute in Pester's internal module state + $ex = { 1 | Should-All ([scriptblock]::Create('')) } | Verify-Throw + $ex.Exception.Message | Verify-Like 'Unbound scriptblock*' + } } diff --git a/tst/functions/assert/Collection/Should-Any.Tests.ps1 b/tst/functions/assert/Collection/Should-Any.Tests.ps1 index 03fe6fd9f..bfd5f1279 100644 --- a/tst/functions/assert/Collection/Should-Any.Tests.ps1 +++ b/tst/functions/assert/Collection/Should-Any.Tests.ps1 @@ -61,4 +61,10 @@ Expected [int] 2, but got [int] 1." -replace "`r`n", "`n") It "Accepts FilterScript and Actual by position" { Should-Any { $true } 1, 2 } + + It 'Throws when provided unbound scriptblock' { + # Unbound scriptblocks would execute in Pester's internal module state + $ex = { 1 | Should-Any ([scriptblock]::Create('')) } | Verify-Throw + $ex.Exception.Message | Verify-Like 'Unbound scriptblock*' + } } diff --git a/tst/functions/assert/Exception/Should-Throw.Tests.ps1 b/tst/functions/assert/Exception/Should-Throw.Tests.ps1 index 4c2cc6084..cf0c516a9 100644 --- a/tst/functions/assert/Exception/Should-Throw.Tests.ps1 +++ b/tst/functions/assert/Exception/Should-Throw.Tests.ps1 @@ -10,7 +10,6 @@ Describe "Should-Throw" { } It "Passes when non-terminating exception is thrown" { - { Write-Error "fail!" } | Should-Throw } @@ -23,6 +22,12 @@ Describe "Should-Throw" { Should-Throw 'MockErrorMessage' 'MockErrorId' ([Microsoft.PowerShell.Commands.WriteErrorException]) 'MockBecauseString' } + It 'Throws when provided unbound scriptblock' { + # Unbound scriptblocks would execute in Pester's internal module state + $ex = { ([scriptblock]::Create('')) | Should-Throw } | Verify-Throw + $ex.Exception.Message | Verify-Like 'Unbound scriptblock*' + } + Context "Filtering with exception type" { It "Passes when exception has the expected type" { { throw [ArgumentException]"A is null!" } | Should-Throw -ExceptionType ([ArgumentException]) From ad3caa77f3afdb08ed726bbe8fef3c1d054b672a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 30 Oct 2024 22:28:23 +0100 Subject: [PATCH 04/23] Bump to 6.0.0-alpha4 --- src/Pester.psd1 | 102 ++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/Pester.psd1 b/src/Pester.psd1 index cf2ae277c..3a5e03596 100644 --- a/src/Pester.psd1 +++ b/src/Pester.psd1 @@ -4,7 +4,7 @@ RootModule = 'Pester.psm1' # Version number of this module. - ModuleVersion = '6.0.0' + ModuleVersion = '5.6.1' # ID used to uniquely identify this module GUID = 'a699dea5-2c73-4616-a270-1f7abb777e71' @@ -22,7 +22,7 @@ Description = 'Pester provides a framework for running BDD style Tests to execute and validate PowerShell commands inside of PowerShell and offers a powerful set of Mocking Functions that allow tests to mimic and mock the functionality of any command inside of a piece of PowerShell code being tested. Pester tests can execute any command or script that is accessible to a pester test file. This can include functions, Cmdlets, Modules and scripts. Pester can be run in ad hoc style in a console or it can be integrated into the Build scripts of a Continuous Integration system.' # Minimum version of the Windows PowerShell engine required by this module - PowerShellVersion = '5.1' + PowerShellVersion = '3.0' # Type files (.ps1xml) to be loaded when importing this module TypesToProcess = @() @@ -66,55 +66,13 @@ 'New-PesterContainer' 'New-PesterConfiguration' - # assert - # bool - 'Should-BeFalse' - 'Should-BeTrue' - 'Should-BeFalsy' - 'Should-BeTruthy' - - # collection - 'Should-All' - 'Should-Any' - 'Should-ContainCollection' - 'Should-NotContainCollection' - 'Should-BeCollection' - 'Should-BeEquivalent' - 'Should-Throw' - 'Should-Be' - 'Should-BeGreaterThan' - 'Should-BeGreaterThanOrEqual' - 'Should-BeLessThan' - 'Should-BeLessThanOrEqual' - 'Should-NotBe' - 'Should-NotBeNull' - 'Should-NotBeSame' - 'Should-NotHaveType' - 'Should-BeNull' - 'Should-BeSame' - 'Should-HaveType' - - # string - 'Should-BeString' - 'Should-NotBeString' - - 'Should-BeEmptyString' - - 'Should-NotBeWhiteSpaceString' - 'Should-NotBeEmptyString' - - 'Should-BeLikeString' - 'Should-NotBeLikeString' - - 'Should-BeFasterThan' - 'Should-BeSlowerThan' - 'Should-BeBefore' - 'Should-BeAfter' - - # helpers + # legacy + 'Assert-VerifiableMock' + 'Assert-MockCalled' + 'Set-ItResult' 'New-MockObject' + 'New-Fixture' - 'Set-ItResult' ) # # Cmdlets to export from this module @@ -158,10 +116,52 @@ LicenseUri = "https://www.apache.org/licenses/LICENSE-2.0.html" # Release notes for this particular version of the module - ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/6.0.0-alpha4' + ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/5.6.1' + + # Prerelease string of this module + Prerelease = '' + } + + # Minimum assembly version required + RequiredAssemblyVersion = '5.6.1' + } + + # HelpInfo URI of this module + # HelpInfoURI = '' + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' + +} + # List of all files packaged with this module + # FileList = @() + + PrivateData = @{ + # PSData is module packaging and gallery metadata embedded in PrivateData + # It's for rebuilding PowerShellGet (and PoshCode) NuGet-style packages + # We had to do this because it's the only place we're allowed to extend the manifest + # https://connect.microsoft.com/PowerShell/feedback/details/421837 + PSData = @{ + # The primary categorization of this module (from the TechNet Gallery tech tree). + Category = "Scripting Techniques" + + # Keyword tags to help users find this module via navigations and search. + Tags = @('powershell', 'unit_testing', 'bdd', 'tdd', 'mocking', 'PSEdition_Core', 'PSEdition_Desktop', 'Windows', 'Linux', 'MacOS') + + # The web address of an icon which can be used in galleries to represent this module + IconUri = 'https://raw.githubusercontent.com/pester/Pester/main/images/pester.PNG' + + # The web address of this module's project or support homepage. + ProjectUri = "https://github.com/Pester/Pester" + + # The web address of this module's license. Points to a page that's embeddable and linkable. + LicenseUri = "https://www.apache.org/licenses/LICENSE-2.0.html" + + # Release notes for this particular version of the module + ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/6.0.0-alpha5' # Prerelease string of this module - Prerelease = 'alpha4' + Prerelease = 'alpha5' } # Minimum assembly version required From b94aa7e3e344faae15516addbe2238e5239e98ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 30 Oct 2024 22:34:44 +0100 Subject: [PATCH 05/23] Revert "Bump to 6.0.0-alpha4" This reverts commit ad3caa77f3afdb08ed726bbe8fef3c1d054b672a. --- src/Pester.psd1 | 102 ++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/Pester.psd1 b/src/Pester.psd1 index 3a5e03596..cf2ae277c 100644 --- a/src/Pester.psd1 +++ b/src/Pester.psd1 @@ -4,7 +4,7 @@ RootModule = 'Pester.psm1' # Version number of this module. - ModuleVersion = '5.6.1' + ModuleVersion = '6.0.0' # ID used to uniquely identify this module GUID = 'a699dea5-2c73-4616-a270-1f7abb777e71' @@ -22,7 +22,7 @@ Description = 'Pester provides a framework for running BDD style Tests to execute and validate PowerShell commands inside of PowerShell and offers a powerful set of Mocking Functions that allow tests to mimic and mock the functionality of any command inside of a piece of PowerShell code being tested. Pester tests can execute any command or script that is accessible to a pester test file. This can include functions, Cmdlets, Modules and scripts. Pester can be run in ad hoc style in a console or it can be integrated into the Build scripts of a Continuous Integration system.' # Minimum version of the Windows PowerShell engine required by this module - PowerShellVersion = '3.0' + PowerShellVersion = '5.1' # Type files (.ps1xml) to be loaded when importing this module TypesToProcess = @() @@ -66,13 +66,55 @@ 'New-PesterContainer' 'New-PesterConfiguration' - # legacy - 'Assert-VerifiableMock' - 'Assert-MockCalled' - 'Set-ItResult' + # assert + # bool + 'Should-BeFalse' + 'Should-BeTrue' + 'Should-BeFalsy' + 'Should-BeTruthy' + + # collection + 'Should-All' + 'Should-Any' + 'Should-ContainCollection' + 'Should-NotContainCollection' + 'Should-BeCollection' + 'Should-BeEquivalent' + 'Should-Throw' + 'Should-Be' + 'Should-BeGreaterThan' + 'Should-BeGreaterThanOrEqual' + 'Should-BeLessThan' + 'Should-BeLessThanOrEqual' + 'Should-NotBe' + 'Should-NotBeNull' + 'Should-NotBeSame' + 'Should-NotHaveType' + 'Should-BeNull' + 'Should-BeSame' + 'Should-HaveType' + + # string + 'Should-BeString' + 'Should-NotBeString' + + 'Should-BeEmptyString' + + 'Should-NotBeWhiteSpaceString' + 'Should-NotBeEmptyString' + + 'Should-BeLikeString' + 'Should-NotBeLikeString' + + 'Should-BeFasterThan' + 'Should-BeSlowerThan' + 'Should-BeBefore' + 'Should-BeAfter' + + # helpers 'New-MockObject' - 'New-Fixture' + 'Set-ItResult' ) # # Cmdlets to export from this module @@ -116,52 +158,10 @@ LicenseUri = "https://www.apache.org/licenses/LICENSE-2.0.html" # Release notes for this particular version of the module - ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/5.6.1' - - # Prerelease string of this module - Prerelease = '' - } - - # Minimum assembly version required - RequiredAssemblyVersion = '5.6.1' - } - - # HelpInfo URI of this module - # HelpInfoURI = '' - - # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. - # DefaultCommandPrefix = '' - -} - # List of all files packaged with this module - # FileList = @() - - PrivateData = @{ - # PSData is module packaging and gallery metadata embedded in PrivateData - # It's for rebuilding PowerShellGet (and PoshCode) NuGet-style packages - # We had to do this because it's the only place we're allowed to extend the manifest - # https://connect.microsoft.com/PowerShell/feedback/details/421837 - PSData = @{ - # The primary categorization of this module (from the TechNet Gallery tech tree). - Category = "Scripting Techniques" - - # Keyword tags to help users find this module via navigations and search. - Tags = @('powershell', 'unit_testing', 'bdd', 'tdd', 'mocking', 'PSEdition_Core', 'PSEdition_Desktop', 'Windows', 'Linux', 'MacOS') - - # The web address of an icon which can be used in galleries to represent this module - IconUri = 'https://raw.githubusercontent.com/pester/Pester/main/images/pester.PNG' - - # The web address of this module's project or support homepage. - ProjectUri = "https://github.com/Pester/Pester" - - # The web address of this module's license. Points to a page that's embeddable and linkable. - LicenseUri = "https://www.apache.org/licenses/LICENSE-2.0.html" - - # Release notes for this particular version of the module - ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/6.0.0-alpha5' + ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/6.0.0-alpha4' # Prerelease string of this module - Prerelease = 'alpha5' + Prerelease = 'alpha4' } # Minimum assembly version required From 882c3581a14aa0a86a5b67d2c6c832cce81ddae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 30 Oct 2024 22:36:56 +0100 Subject: [PATCH 06/23] Bump to 6.0.0-alpha5 --- src/Pester.psd1 | 102 ++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/Pester.psd1 b/src/Pester.psd1 index cf2ae277c..49dea0fc7 100644 --- a/src/Pester.psd1 +++ b/src/Pester.psd1 @@ -4,7 +4,7 @@ RootModule = 'Pester.psm1' # Version number of this module. - ModuleVersion = '6.0.0' + ModuleVersion = '5.6.1' # ID used to uniquely identify this module GUID = 'a699dea5-2c73-4616-a270-1f7abb777e71' @@ -22,7 +22,7 @@ Description = 'Pester provides a framework for running BDD style Tests to execute and validate PowerShell commands inside of PowerShell and offers a powerful set of Mocking Functions that allow tests to mimic and mock the functionality of any command inside of a piece of PowerShell code being tested. Pester tests can execute any command or script that is accessible to a pester test file. This can include functions, Cmdlets, Modules and scripts. Pester can be run in ad hoc style in a console or it can be integrated into the Build scripts of a Continuous Integration system.' # Minimum version of the Windows PowerShell engine required by this module - PowerShellVersion = '5.1' + PowerShellVersion = '3.0' # Type files (.ps1xml) to be loaded when importing this module TypesToProcess = @() @@ -66,55 +66,13 @@ 'New-PesterContainer' 'New-PesterConfiguration' - # assert - # bool - 'Should-BeFalse' - 'Should-BeTrue' - 'Should-BeFalsy' - 'Should-BeTruthy' - - # collection - 'Should-All' - 'Should-Any' - 'Should-ContainCollection' - 'Should-NotContainCollection' - 'Should-BeCollection' - 'Should-BeEquivalent' - 'Should-Throw' - 'Should-Be' - 'Should-BeGreaterThan' - 'Should-BeGreaterThanOrEqual' - 'Should-BeLessThan' - 'Should-BeLessThanOrEqual' - 'Should-NotBe' - 'Should-NotBeNull' - 'Should-NotBeSame' - 'Should-NotHaveType' - 'Should-BeNull' - 'Should-BeSame' - 'Should-HaveType' - - # string - 'Should-BeString' - 'Should-NotBeString' - - 'Should-BeEmptyString' - - 'Should-NotBeWhiteSpaceString' - 'Should-NotBeEmptyString' - - 'Should-BeLikeString' - 'Should-NotBeLikeString' - - 'Should-BeFasterThan' - 'Should-BeSlowerThan' - 'Should-BeBefore' - 'Should-BeAfter' - - # helpers + # legacy + 'Assert-VerifiableMock' + 'Assert-MockCalled' + 'Set-ItResult' 'New-MockObject' + 'New-Fixture' - 'Set-ItResult' ) # # Cmdlets to export from this module @@ -158,10 +116,52 @@ LicenseUri = "https://www.apache.org/licenses/LICENSE-2.0.html" # Release notes for this particular version of the module - ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/6.0.0-alpha4' + ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/5.6.1' + + # Prerelease string of this module + Prerelease = '' + } + + # Minimum assembly version required + RequiredAssemblyVersion = '5.6.1' + } + + # HelpInfo URI of this module + # HelpInfoURI = '' + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' + +} } } } + # List of all files packaged with this module + # FileList = @() + + PrivateData = @{ + # PSData is module packaging and gallery metadata embedded in PrivateData + # It's for rebuilding PowerShellGet (and PoshCode) NuGet-style packages + # We had to do this because it's the only place we're allowed to extend the manifest + # https://connect.microsoft.com/PowerShell/feedback/details/421837 + PSData = @{ + # The primary categorization of this module (from the TechNet Gallery tech tree). + Category = "Scripting Techniques" + + # Keyword tags to help users find this module via navigations and search. + Tags = @('powershell', 'unit_testing', 'bdd', 'tdd', 'mocking', 'PSEdition_Core', 'PSEdition_Desktop', 'Windows', 'Linux', 'MacOS') + + # The web address of an icon which can be used in galleries to represent this module + IconUri = 'https://raw.githubusercontent.com/pester/Pester/main/images/pester.PNG' + + # The web address of this module's project or support homepage. + ProjectUri = "https://github.com/Pester/Pester" + + # The web address of this module's license. Points to a page that's embeddable and linkable. + LicenseUri = "https://www.apache.org/licenses/LICENSE-2.0.html" + + # Release notes for this particular version of the module + ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/6.0.0-alpha5' # Prerelease string of this module - Prerelease = 'alpha4' + Prerelease = 'alpha5' } # Minimum assembly version required From b0cfb01b4a263e1ca5c3af2c36a4af1931c27145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 30 Oct 2024 22:40:08 +0100 Subject: [PATCH 07/23] Revert "Bump to 6.0.0-alpha5" This reverts commit 882c3581a14aa0a86a5b67d2c6c832cce81ddae9. --- src/Pester.psd1 | 102 ++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/Pester.psd1 b/src/Pester.psd1 index 49dea0fc7..cf2ae277c 100644 --- a/src/Pester.psd1 +++ b/src/Pester.psd1 @@ -4,7 +4,7 @@ RootModule = 'Pester.psm1' # Version number of this module. - ModuleVersion = '5.6.1' + ModuleVersion = '6.0.0' # ID used to uniquely identify this module GUID = 'a699dea5-2c73-4616-a270-1f7abb777e71' @@ -22,7 +22,7 @@ Description = 'Pester provides a framework for running BDD style Tests to execute and validate PowerShell commands inside of PowerShell and offers a powerful set of Mocking Functions that allow tests to mimic and mock the functionality of any command inside of a piece of PowerShell code being tested. Pester tests can execute any command or script that is accessible to a pester test file. This can include functions, Cmdlets, Modules and scripts. Pester can be run in ad hoc style in a console or it can be integrated into the Build scripts of a Continuous Integration system.' # Minimum version of the Windows PowerShell engine required by this module - PowerShellVersion = '3.0' + PowerShellVersion = '5.1' # Type files (.ps1xml) to be loaded when importing this module TypesToProcess = @() @@ -66,13 +66,55 @@ 'New-PesterContainer' 'New-PesterConfiguration' - # legacy - 'Assert-VerifiableMock' - 'Assert-MockCalled' - 'Set-ItResult' + # assert + # bool + 'Should-BeFalse' + 'Should-BeTrue' + 'Should-BeFalsy' + 'Should-BeTruthy' + + # collection + 'Should-All' + 'Should-Any' + 'Should-ContainCollection' + 'Should-NotContainCollection' + 'Should-BeCollection' + 'Should-BeEquivalent' + 'Should-Throw' + 'Should-Be' + 'Should-BeGreaterThan' + 'Should-BeGreaterThanOrEqual' + 'Should-BeLessThan' + 'Should-BeLessThanOrEqual' + 'Should-NotBe' + 'Should-NotBeNull' + 'Should-NotBeSame' + 'Should-NotHaveType' + 'Should-BeNull' + 'Should-BeSame' + 'Should-HaveType' + + # string + 'Should-BeString' + 'Should-NotBeString' + + 'Should-BeEmptyString' + + 'Should-NotBeWhiteSpaceString' + 'Should-NotBeEmptyString' + + 'Should-BeLikeString' + 'Should-NotBeLikeString' + + 'Should-BeFasterThan' + 'Should-BeSlowerThan' + 'Should-BeBefore' + 'Should-BeAfter' + + # helpers 'New-MockObject' - 'New-Fixture' + 'Set-ItResult' ) # # Cmdlets to export from this module @@ -116,52 +158,10 @@ LicenseUri = "https://www.apache.org/licenses/LICENSE-2.0.html" # Release notes for this particular version of the module - ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/5.6.1' - - # Prerelease string of this module - Prerelease = '' - } - - # Minimum assembly version required - RequiredAssemblyVersion = '5.6.1' - } - - # HelpInfo URI of this module - # HelpInfoURI = '' - - # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. - # DefaultCommandPrefix = '' - -} } } } - # List of all files packaged with this module - # FileList = @() - - PrivateData = @{ - # PSData is module packaging and gallery metadata embedded in PrivateData - # It's for rebuilding PowerShellGet (and PoshCode) NuGet-style packages - # We had to do this because it's the only place we're allowed to extend the manifest - # https://connect.microsoft.com/PowerShell/feedback/details/421837 - PSData = @{ - # The primary categorization of this module (from the TechNet Gallery tech tree). - Category = "Scripting Techniques" - - # Keyword tags to help users find this module via navigations and search. - Tags = @('powershell', 'unit_testing', 'bdd', 'tdd', 'mocking', 'PSEdition_Core', 'PSEdition_Desktop', 'Windows', 'Linux', 'MacOS') - - # The web address of an icon which can be used in galleries to represent this module - IconUri = 'https://raw.githubusercontent.com/pester/Pester/main/images/pester.PNG' - - # The web address of this module's project or support homepage. - ProjectUri = "https://github.com/Pester/Pester" - - # The web address of this module's license. Points to a page that's embeddable and linkable. - LicenseUri = "https://www.apache.org/licenses/LICENSE-2.0.html" - - # Release notes for this particular version of the module - ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/6.0.0-alpha5' + ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/6.0.0-alpha4' # Prerelease string of this module - Prerelease = 'alpha5' + Prerelease = 'alpha4' } # Minimum assembly version required From cb5d640f5229a4ea848eb48350ab628964d3ff02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Wed, 30 Oct 2024 22:41:21 +0100 Subject: [PATCH 08/23] Bump to 6.0.0-alpha5, second try --- src/Pester.psd1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pester.psd1 b/src/Pester.psd1 index cf2ae277c..48d9eb5b9 100644 --- a/src/Pester.psd1 +++ b/src/Pester.psd1 @@ -158,10 +158,10 @@ LicenseUri = "https://www.apache.org/licenses/LICENSE-2.0.html" # Release notes for this particular version of the module - ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/6.0.0-alpha4' + ReleaseNotes = 'https://github.com/pester/Pester/releases/tag/6.0.0-alpha5' # Prerelease string of this module - Prerelease = 'alpha4' + Prerelease = 'alpha5' } # Minimum assembly version required From 32cfd48a3600ca74e82aec024a7145fc94153bd6 Mon Sep 17 00:00:00 2001 From: Frode Flaten <3436158+fflaten@users.noreply.github.com> Date: Tue, 12 Nov 2024 21:15:44 +0100 Subject: [PATCH 09/23] Update macOS image and PublishCodeCoverageResults task in CI (#2573) * Replace deprecated macOS 12 image in CI * Upgrade deprecated PublishCodeCoverageResults task to v2 --- azure-pipelines.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c9a22f910..9261634f0 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -82,12 +82,12 @@ stages: PS7_Ubuntu_22_04: vmImage: ubuntu-22.04 pwsh: true - PS7_macOS_12: - vmImage: macOS-12 - pwsh: true PS7_macOS_13: vmImage: macOS-13 pwsh: true + PS7_macOS_14: + vmImage: macOS-14 + pwsh: true PS7_Windows_Server2019: vmImage: windows-2019 pwsh: true @@ -114,9 +114,8 @@ stages: script: | & ./test.ps1 -CI -CC -PassThru -NoBuild workingDirectory: '$(Build.SourcesDirectory)' - - task: PublishCodeCoverageResults@1 + - task: PublishCodeCoverageResults@2 inputs: - codeCoverageTool: 'JaCoCo' summaryFileLocation: 'coverage.xml' pathToSources: '$(Build.SourcesDirectory)/bin/' failIfCoverageEmpty: false From 4f98a73a820dc5d935a06e6027eb030f781ac332 Mon Sep 17 00:00:00 2001 From: Frode Flaten <3436158+fflaten@users.noreply.github.com> Date: Sun, 17 Nov 2024 14:43:38 +0100 Subject: [PATCH 10/23] Remove about_ in related links (#2576) platyPS creates broken link in markdown. Topic is mentioned in description section --- src/Pester.RSpec.ps1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Pester.RSpec.ps1 b/src/Pester.RSpec.ps1 index 633557cf5..e15094b98 100644 --- a/src/Pester.RSpec.ps1 +++ b/src/Pester.RSpec.ps1 @@ -333,9 +333,6 @@ function New-PesterConfiguration { .LINK https://pester.dev/docs/commands/Invoke-Pester - - .LINK - about_PesterConfiguration #> [CmdletBinding()] [OutputType([PesterConfiguration])] From 7e5d35ca65370af0181c77c3a75c4d08e57fefb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Sun, 17 Nov 2024 16:41:58 +0100 Subject: [PATCH 11/23] Fix coverage code for pre-v5 (#2577) --- tst/functions/Coverage.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tst/functions/Coverage.Tests.ps1 b/tst/functions/Coverage.Tests.ps1 index 5cdfd83db..bcfa99ba0 100644 --- a/tst/functions/Coverage.Tests.ps1 +++ b/tst/functions/Coverage.Tests.ps1 @@ -97,7 +97,7 @@ InPesterModuleScope { #{ function MyClass { - MyBaseClass; 'I am the constructor.' + MyBaseClass # call the base constructor } function MethodOne From 0ecf29a402816b88963f9389609e2657b1808929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Thu, 12 Dec 2024 11:36:27 +0100 Subject: [PATCH 12/23] Update BACKERS.md --- BACKERS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BACKERS.md b/BACKERS.md index 2ef2ac64b..493efa14b 100644 --- a/BACKERS.md +++ b/BACKERS.md @@ -18,3 +18,5 @@ @tabs-not-spaces @avanreijn @DevOpsCollectiveINC +@chocolatey + From d40aaa1022c736c6e43ec1b2bef018510bc895ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Thu, 12 Dec 2024 22:18:49 +0100 Subject: [PATCH 13/23] Update to net8 and newer dep (#2586) * Update to net8 and newer dep * Fix occurences of net6.0 --- build.ps1 | 4 +- global.json | 2 +- publish/filesToPublish.ps1 | 2 +- src/Pester.Types.ps1 | 6 +- src/csharp/Pester/Pester.csproj | 14 +- src/csharp/Pester/packages.lock.json | 238 +++++------------ src/csharp/PesterTests/PesterTests.csproj | 7 +- src/csharp/PesterTests/packages.lock.json | 312 ++++++++-------------- 8 files changed, 197 insertions(+), 388 deletions(-) diff --git a/build.ps1 b/build.ps1 index 622dfbe47..7587e1a33 100644 --- a/build.ps1 +++ b/build.ps1 @@ -94,7 +94,7 @@ if ($Clean) { if ($Clean) { # Update PesterConfiguration help in about_PesterConfiguration if ($PSVersionTable.PSVersion.Major -ge 6) { - $null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net6.0/Pester.dll") + $null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net8.0/Pester.dll") } else { $null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net462/Pester.dll") @@ -205,7 +205,7 @@ if ($Clean) { , ("$PSScriptRoot/src/schemas/Cobertura/*.dtd", "$PSScriptRoot/bin/schemas/Cobertura/") , ("$PSScriptRoot/src/schemas/JaCoCo/*.dtd", "$PSScriptRoot/bin/schemas/JaCoCo/") , ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net462/Pester.dll", "$PSScriptRoot/bin/bin/net462/") - , ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net6.0/Pester.dll", "$PSScriptRoot/bin/bin/net6.0/") + , ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net8.0/Pester.dll", "$PSScriptRoot/bin/bin/net8.0/") ) } diff --git a/global.json b/global.json index 2d566bd8c..04fa23b25 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "rollForward": "latestFeature", + "rollForward": "latestMajor", "version": "8.0.100", "allowPrerelease": false } diff --git a/publish/filesToPublish.ps1 b/publish/filesToPublish.ps1 index ec216ff18..ca9f45457 100644 --- a/publish/filesToPublish.ps1 +++ b/publish/filesToPublish.ps1 @@ -5,7 +5,7 @@ 'Pester.Format.ps1xml' 'PesterConfiguration.Format.ps1xml' 'bin/net462/Pester.dll' - 'bin/net6.0/Pester.dll' + 'bin/net8.0/Pester.dll' 'en-US/about_Pester.help.txt' 'en-US/about_PesterConfiguration.help.txt' 'schemas/Cobertura/coverage-loose.dtd' diff --git a/src/Pester.Types.ps1 b/src/Pester.Types.ps1 index d891dddaf..b63d20d43 100644 --- a/src/Pester.Types.ps1 +++ b/src/Pester.Types.ps1 @@ -13,13 +13,13 @@ if ($null -ne $configurationType) { } if ($PSVersionTable.PSVersion.Major -ge 6) { - $path = "$PSScriptRoot/bin/net6.0/Pester.dll" + $path = "$PSScriptRoot/bin/net8.0/Pester.dll" # PESTER_BUILD if ((Get-Variable -Name "PESTER_BUILD" -ValueOnly -ErrorAction Ignore)) { - $path = "$PSScriptRoot/../bin/bin/net6.0/Pester.dll" + $path = "$PSScriptRoot/../bin/bin/net8.0/Pester.dll" } else { - $path = "$PSScriptRoot/../bin/bin/net6.0/Pester.dll" + $path = "$PSScriptRoot/../bin/bin/net8.0/Pester.dll" } # end PESTER_BUILD & $SafeCommands['Add-Type'] -Path $path diff --git a/src/csharp/Pester/Pester.csproj b/src/csharp/Pester/Pester.csproj index 6392dbb9f..bea226a3e 100644 --- a/src/csharp/Pester/Pester.csproj +++ b/src/csharp/Pester/Pester.csproj @@ -1,7 +1,7 @@  - net6.0;net462 + net8.0;net462 latest true embedded @@ -11,14 +11,10 @@ $(DefineConstants);PESTER - - - + + + +