@@ -8,10 +8,18 @@ param (
8
8
[string ]$TestsToRun
9
9
)
10
10
11
- function InstallModule ([string ]$Name , [version ]$Version ){
12
- if (! (Get-Module $Name - List | where Version -ge $Version )) {
13
- Write-Host " Installing $Name "
14
- Install-Module - Name $Name - Force - SkipPublisherCheck - Scope CurrentUser - Repository PSGallery
11
+ function InstallModule ([string ]$Name , [version ]$Version , [version ]$MaxVersion = $null ){
12
+ if ($MaxVersion ) {
13
+ if (! (Get-Module $Name - List | where Version -ge $Version | where Version -le $MaxVersion )) {
14
+ Write-Host " Installing $Name with Max Version $MaxVersion "
15
+ Install-Module - Name $Name - Force - SkipPublisherCheck - Scope CurrentUser - Repository PSGallery - MaximumVersion $MaxVersion
16
+ }
17
+ Import-Module $Name - MaximumVersion $MaxVersion
18
+ } else {
19
+ if (! (Get-Module $Name - List | where Version -ge $Version )) {
20
+ Write-Host " Installing $Name "
21
+ Install-Module - Name $Name - Force - SkipPublisherCheck - Scope CurrentUser - Repository PSGallery
22
+ }
15
23
Import-Module $Name
16
24
}
17
25
if ($env: TF_BUILD ) {Get-Module $Name - List}
@@ -32,7 +40,7 @@ if ($env:TF_BUILD) {
32
40
# Install Pester and Platy, if needed
33
41
#
34
42
35
- InstallModule Pester ' 4.0.0'
43
+ InstallModule Pester ' 4.0.0' ' 4.99 '
36
44
InstallModule PlatyPS ' 0.14.0'
37
45
InstallModule PSScriptAnalyzer ' 1.17.0'
38
46
@@ -53,4 +61,4 @@ switch ($TestsToRun) {
53
61
54
62
Write-Host " Run Pester tests"
55
63
$Result = Invoke-Pester - Path " $tests /module" , " $tests /functions" - Tag $Tags - PassThru - OutputFile PesterTestResults.xml
56
- if ($Result.failedCount -ne 0 ) {Write-Error " Pester returned errors" }
64
+ if ($Result.failedCount -ne 0 ) {Write-Error " Pester returned errors" }
0 commit comments