Skip to content

Commit

Permalink
Revert dropping support of Powershell 3 and friends (#2435)
Browse files Browse the repository at this point in the history
* Revert dropping support of powershell 3 etc.

* Update lock and fix reverted change
  • Loading branch information
nohwnd committed Apr 10, 2024
1 parent 3977039 commit bd34d3f
Show file tree
Hide file tree
Showing 10 changed files with 608 additions and 415 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -94,7 +94,7 @@ Get-Help ./test.ps1 -Detailed

The Azure Devops Pipeline azure-pipelines.yml file contains the code definition used for builds, unit and integration tests in the CI pipeline.

Within the pipeline, tests are executed against PS7 and PS5.1, on Windows, Linux (Ubuntu) and MacOS.
Within the pipeline, tests are executed against PS7 Core on a strategy matrix of machines, including Ubuntu 16.04, 18.04, macOS Mojave 10.14, Catalina 10.15, Windows Server 2016, 2019. Tests are also executed against PS6.2, PS4, PS3.

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -67,7 +67,7 @@ The example above also has an [annotated and production ready version here](docs

## Installation

Pester runs on Windows, Linux, MacOS and anywhere else thanks to PowerShell. It is compatible with Windows PowerShell 5.1 and PowerShell 7.2 and newer.
Pester runs on Windows, Linux, MacOS and anywhere else thanks to PowerShell. It is compatible with Windows PowerShell 3, 4, 5, 6 and 7.

Pester 3 comes pre-installed with Windows 10, but we recommend updating, by running this PowerShell command _as administrator_:

Expand Down
47 changes: 47 additions & 0 deletions azure-pipelines.yml
Expand Up @@ -126,3 +126,50 @@ stages:
failTaskOnFailedTests: true
condition: succeededOrFailed()
timeoutInMinutes: 20
- job:
workspace:
clean: all
strategy:
matrix:
PS3:
agent: 'ps3'
pwsh: false
PS4:
agent: 'ps4'
pwsh: false
PS6_2:
agent: 'ps6'
pwsh: true
pool:
name: Default
demands:
- agent.name -equals $(agent)
steps:
- checkout: none
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'all'
targetPath: '$(Build.SourcesDirectory)'
- task: PowerShell@2
displayName: 'Test Pester'
inputs:
targetType: 'inline'
pwsh: $(pwsh)
script: |
& ./test.ps1 -CI -PassThru -NoBuild
workingDirectory: '$(Build.SourcesDirectory)'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: 'coverage.xml'
pathToSources: 'src/'
failIfCoverageEmpty: false
condition: succeededOrFailed()
- task: PublishTestResults@2
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'testResults.xml'
failTaskOnFailedTests: true
condition: succeededOrFailed()
timeoutInMinutes: 20
10 changes: 6 additions & 4 deletions build.ps1
Expand Up @@ -115,8 +115,10 @@ if ($Clean) {
, ("$PSScriptRoot/src/schemas/NUnit25/*.xsd", "$PSScriptRoot/bin/schemas/NUnit25/")
, ("$PSScriptRoot/src/schemas/NUnit3/*.xsd", "$PSScriptRoot/bin/schemas/NUnit3/")
, ("$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/net452/Pester.dll", "$PSScriptRoot/bin/bin/net452/")
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/net452/Pester.pdb", "$PSScriptRoot/bin/bin/net452/")
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/netstandard2.0/Pester.dll", "$PSScriptRoot/bin/bin/netstandard2.0/")
, ("$PSScriptRoot/src/csharp/Pester/bin/$Configuration/netstandard2.0/Pester.pdb", "$PSScriptRoot/bin/bin/netstandard2.0/")
)
}

Expand All @@ -125,10 +127,10 @@ Copy-Content -Content $content
if ($Clean) {
# update help for New-PesterConfiguration
if ($PSVersionTable.PSVersion.Major -gt 5) {
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/bin/bin/net6.0/Pester.dll")
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/bin/bin/netstandard2.0/Pester.dll")
}
else {
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/bin/bin/net462/Pester.dll")
$null = [Reflection.Assembly]::LoadFrom("$PSScriptRoot/bin/bin/net452/Pester.dll")
}

function Format-NicelyMini ($value) {
Expand Down
6 changes: 4 additions & 2 deletions publish/release.ps1
Expand Up @@ -60,8 +60,10 @@ $files = @(
'Pester.psm1'
'Pester.Format.ps1xml'
'PesterConfiguration.Format.ps1xml'
'bin/net462/Pester.dll'
'bin/net6.0/Pester.dll'
'bin/net452/Pester.dll'
'bin/net452/Pester.pdb'
'bin/netstandard2.0/Pester.dll'
'bin/netstandard2.0/Pester.pdb'
'en-US/about_BeforeEach_AfterEach.help.txt'
'en-US/about_Mocking.help.txt'
'en-US/about_Pester.help.txt'
Expand Down
12 changes: 6 additions & 6 deletions src/Pester.Types.ps1
Expand Up @@ -13,25 +13,25 @@ if ($null -ne $configurationType) {
}

if ($PSVersionTable.PSVersion.Major -ge 6) {
$path = "$PSScriptRoot/bin/net6.0/Pester.dll"
$path = "$PSScriptRoot/bin/netstandard2.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/netstandard2.0/Pester.dll"
}
else {
$path = "$PSScriptRoot/../bin/bin/net6.0/Pester.dll"
$path = "$PSScriptRoot/../bin/bin/netstandard2.0/Pester.dll"
}
# end PESTER_BUILD
& $SafeCommands['Add-Type'] -Path $path
}
else {
$path = "$PSScriptRoot/bin/net462/Pester.dll"
$path = "$PSScriptRoot/bin/net452/Pester.dll"
# PESTER_BUILD
if ((Get-Variable -Name "PESTER_BUILD" -ValueOnly -ErrorAction Ignore)) {
$path = "$PSScriptRoot/../bin/bin/net462/Pester.dll"
$path = "$PSScriptRoot/../bin/bin/net452/Pester.dll"
}
else {
$path = "$PSScriptRoot/../bin/bin/net462/Pester.dll"
$path = "$PSScriptRoot/../bin/bin/net452/Pester.dll"
}
# end PESTER_BUILD
& $SafeCommands['Add-Type'] -Path $path
Expand Down
4 changes: 2 additions & 2 deletions src/Pester.psd1
@@ -1,4 +1,4 @@
@{
@{

# Script module or binary module file associated with this manifest.
RootModule = 'Pester.psm1'
Expand All @@ -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 = @()
Expand Down
26 changes: 8 additions & 18 deletions src/csharp/Pester/Pester.csproj
@@ -1,31 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net462</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<LangVersion>latest</LangVersion>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DebugType>embedded</DebugType>
</PropertyGroup>

<!-- PowerShell 7.2.x is the oldest supported PowerShell version. That version is built using net6.0.
But there is a bug in 7.2.0 reference assemblies, up to 7.2.10, where the IExtens.File is missing from the reference assembly:
https://github.com/PowerShell/PowerShell/issues/16408
So we use the version released before 7.2.0 which was 7.1.7. We could probably use 7.2.10 safely as well,
-->
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Management.Automation" Version="7.1.7" />
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<!-- this version is used specifically to support as old version of PS6 as we can.
issue: https://github.com/pester/Pester/issues/2207 -->
<PackageReference Include="System.Management.Automation" Version="6.0.4" NoWarn="NU1903" />
</ItemGroup>

<!-- Windows PowerShell 5.1 is the only Windows PowerShell that is still in support, and it is built using .NET Framework 4.5.2.
But the oldest still supported OS on which WMF5.1 can be installed, is Windows 10 1607, which comes with .NET Framework 4.6.2. https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/wmf-overview?view=powershell-7.4#wmf-availability-across-windows-operating-systems
https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/versions-and-dependencies#net-framework-462
.NET 4.6.2 is also the oldest supported version of .NET Framework (https://learn.microsoft.com/en-us/lifecycle/products/microsoft-net-framework)
-->
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Microsoft.PowerShell.5.1.ReferenceAssemblies" Version="1.0.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<PackageReference Include="Microsoft.PowerShell.3.ReferenceAssemblies" Version="1.0.0" />

<!-- To enable build support on unix. -->
<!-- To enable build support on unix-->
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down

0 comments on commit bd34d3f

Please sign in to comment.