diff --git a/CHANGELOG.md b/CHANGELOG.md index 16bfe3bf1..512991f59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ - **auto-pr:** Add `CommitMessageFormat` option ([#5171](https://github.com/ScoopInstaller/Scoop/issues/5171)) - **checkver:** Support XML default namespace ([#5191](https://github.com/ScoopInstaller/Scoop/issues/5191)) +### Tests + +- **unix:** Fix tests in Linux and macOS ([#5179](https://github.com/ScoopInstaller/Scoop/issues/5179)) + ## [v0.3.0](https://github.com/ScoopInstaller/Scoop/compare/v0.2.4...v0.3.0) - 2022-10-10 ### Features diff --git a/test/Scoop-Alias.Tests.ps1 b/test/Scoop-Alias.Tests.ps1 index 1f696f5a8..957b2d91b 100644 --- a/test/Scoop-Alias.Tests.ps1 +++ b/test/Scoop-Alias.Tests.ps1 @@ -3,54 +3,41 @@ . "$PSScriptRoot\..\lib\help.ps1" . "$PSScriptRoot\..\libexec\scoop-alias.ps1" | Out-Null -Describe 'add_alias' -Tag 'Scoop' { - Mock shimdir { "$env:TEMP\shims" } - Mock set_config { } - Mock get_config { @{} } +Describe 'Manipulate Alias' -Tag 'Scoop' { + BeforeAll { + Mock shimdir { "$TestDrive\shims" } + Mock set_config { } + Mock get_config { @{} } - $shimdir = shimdir - ensure $shimdir - - Context "alias doesn't exist" { - It 'creates a new alias' { - $alias_file = "$shimdir\scoop-rm.ps1" - $alias_file | Should -Not -Exist - - add_alias 'rm' '"hello, world!"' - & $alias_file | Should -Be 'hello, world!' - } + $shimdir = shimdir + ensure $shimdir } - Context 'alias exists' { - It 'does not change existing alias' { - $alias_file = "$shimdir\scoop-rm.ps1" - New-Item $alias_file -Type File -Force - $alias_file | Should -Exist + It 'Creates a new alias if alias doesn''t exist' { + $alias_file = "$shimdir\scoop-rm.ps1" + $alias_file | Should -Not -Exist - add_alias 'rm' 'test' - $alias_file | Should -FileContentMatch '' - } - } -} - -Describe 'rm_alias' -Tag 'Scoop' { - Mock shimdir { "$env:TEMP\shims" } - Mock set_config { } - Mock get_config { @{} } - - $shimdir = shimdir - ensure $shimdir - - Context 'alias exists' { - It 'removes an existing alias' { - $alias_file = "$shimdir\scoop-rm.ps1" - add_alias 'rm' '"hello, world!"' - - $alias_file | Should -Exist - Mock get_config { @(@{'rm' = 'scoop-rm' }) } - - rm_alias 'rm' - $alias_file | Should -Not -Exist - } + add_alias 'rm' '"hello, world!"' + & $alias_file | Should -Be 'hello, world!' + } + + It 'Does not change existing alias if alias exists' { + $alias_file = "$shimdir\scoop-rm.ps1" + New-Item $alias_file -Type File -Force + $alias_file | Should -Exist + + add_alias 'rm' 'test' + & $alias_file | Should -Not -Be 'test' + } + + It 'Removes an existing alias' { + $alias_file = "$shimdir\scoop-rm.ps1" + add_alias 'rm' '"hello, world!"' + + $alias_file | Should -Exist + Mock get_config { @(@{'rm' = 'scoop-rm' }) } + + rm_alias 'rm' + $alias_file | Should -Not -Exist } } diff --git a/test/Scoop-Config.Tests.ps1 b/test/Scoop-Config.Tests.ps1 index 604a25b2f..4b2e81ff6 100644 --- a/test/Scoop-Config.Tests.ps1 +++ b/test/Scoop-Config.Tests.ps1 @@ -3,15 +3,12 @@ Describe 'config' -Tag 'Scoop' { BeforeAll { - $configFile = "$env:TEMP\ScoopTestFixtures\config.json" - if (Test-Path $configFile) { - Remove-Item -Path $configFile -Force - } + $configFile = [IO.Path]::GetTempFileName() $unicode = [Regex]::Unescape('\u4f60\u597d\u3053\u3093\u306b\u3061\u306f') # 你好こんにちは } - BeforeEach { - $scoopConfig = $null + AfterAll { + Remove-Item -Path $configFile -Force } It 'load_cfg should return null if config file does not exist' { diff --git a/test/Scoop-Core.Tests.ps1 b/test/Scoop-Core.Tests.ps1 index 398cbfaad..bdcd29c1a 100644 --- a/test/Scoop-Core.Tests.ps1 +++ b/test/Scoop-Core.Tests.ps1 @@ -1,10 +1,8 @@ . "$PSScriptRoot\Scoop-TestLib.ps1" . "$PSScriptRoot\..\lib\core.ps1" . "$PSScriptRoot\..\lib\install.ps1" -. "$PSScriptRoot\..\lib\unix.ps1" $repo_dir = (Get-Item $MyInvocation.MyCommand.Path).directory.parent.FullName -$isUnix = is_unix Describe 'Get-AppFilePath' -Tag 'Scoop' { BeforeAll { @@ -128,7 +126,7 @@ Describe 'is_directory' -Tag 'Scoop' { } } -Describe 'movedir' -Tag 'Scoop' { +Describe 'movedir' -Tag 'Scoop', 'Windows' { $extract_dir = 'subdir' $extract_to = $null @@ -136,7 +134,7 @@ Describe 'movedir' -Tag 'Scoop' { $working_dir = setup_working 'movedir' } - It 'moves directories with no spaces in path' -Skip:$isUnix { + It 'moves directories with no spaces in path' { $dir = "$working_dir\user" movedir "$dir\_tmp\$extract_dir" "$dir\$extract_to" @@ -144,7 +142,7 @@ Describe 'movedir' -Tag 'Scoop' { "$dir\_tmp\$extract_dir" | Should -Not -Exist } - It 'moves directories with spaces in path' -Skip:$isUnix { + It 'moves directories with spaces in path' { $dir = "$working_dir\user with space" movedir "$dir\_tmp\$extract_dir" "$dir\$extract_to" @@ -157,7 +155,7 @@ Describe 'movedir' -Tag 'Scoop' { "$dir\_tmp" | Should -Not -Exist } - It 'moves directories with quotes in path' -Skip:$isUnix { + It 'moves directories with quotes in path' { $dir = "$working_dir\user with 'quote" movedir "$dir\_tmp\$extract_dir" "$dir\$extract_to" @@ -166,14 +164,14 @@ Describe 'movedir' -Tag 'Scoop' { } } -Describe 'shim' -Tag 'Scoop' { +Describe 'shim' -Tag 'Scoop', 'Windows' { BeforeAll { $working_dir = setup_working 'shim' $shimdir = shimdir $(ensure_in_path $shimdir) | Out-Null } - It "links a file onto the user's path" -Skip:$isUnix { + It "links a file onto the user's path" { { Get-Command 'shim-test' -ea stop } | Should -Throw { Get-Command 'shim-test.ps1' -ea stop } | Should -Throw { Get-Command 'shim-test.cmd' -ea stop } | Should -Throw @@ -187,7 +185,7 @@ Describe 'shim' -Tag 'Scoop' { } Context 'user with quote' { - It 'shims a file with quote in path' -Skip:$isUnix { + It 'shims a file with quote in path' { { Get-Command 'shim-test' -ea stop } | Should -Throw { shim-test } | Should -Throw @@ -202,14 +200,14 @@ Describe 'shim' -Tag 'Scoop' { } } -Describe 'rm_shim' -Tag 'Scoop' { +Describe 'rm_shim' -Tag 'Scoop', 'Windows' { BeforeAll { $working_dir = setup_working 'shim' $shimdir = shimdir $(ensure_in_path $shimdir) | Out-Null } - It 'removes shim from path' -Skip:$isUnix { + It 'removes shim from path' { shim "$working_dir\shim-test.ps1" $false 'shim-test' rm_shim 'shim-test' $shimdir @@ -221,7 +219,7 @@ Describe 'rm_shim' -Tag 'Scoop' { } } -Describe 'get_app_name_from_shim' -Tag 'Scoop' { +Describe 'get_app_name_from_shim' -Tag 'Scoop', 'Windows' { BeforeAll { $working_dir = setup_working 'shim' $shimdir = shimdir @@ -229,11 +227,11 @@ Describe 'get_app_name_from_shim' -Tag 'Scoop' { Mock appsdir { $working_dir } } - It 'returns empty string if file does not exist' -Skip:$isUnix { + It 'returns empty string if file does not exist' { get_app_name_from_shim 'non-existent-file' | Should -Be '' } - It 'returns app name if file exists and is a shim to an app' -Skip:$isUnix { + It 'returns app name if file exists and is a shim to an app' { ensure "$working_dir/mockapp/current/" Write-Output '' | Out-File "$working_dir/mockapp/current/mockapp1.ps1" shim "$working_dir/mockapp/current/mockapp1.ps1" $false 'shim-test1' @@ -246,7 +244,7 @@ Describe 'get_app_name_from_shim' -Tag 'Scoop' { get_app_name_from_shim "$shim_path2" | Should -Be 'mockapp' } - It 'returns empty string if file exists and is not a shim' -Skip:$isUnix { + It 'returns empty string if file exists and is not a shim' { Write-Output 'lorem ipsum' | Out-File -Encoding ascii "$working_dir/mock-shim.ps1" get_app_name_from_shim "$working_dir/mock-shim.ps1" | Should -Be '' } @@ -263,12 +261,12 @@ Describe 'get_app_name_from_shim' -Tag 'Scoop' { } } -Describe 'ensure_robocopy_in_path' -Tag 'Scoop' { +Describe 'ensure_robocopy_in_path' -Tag 'Scoop', 'Windows' { $shimdir = shimdir $false Mock versiondir { $repo_dir } Context 'robocopy is not in path' { - It 'shims robocopy when not on path' -Skip:$isUnix { + It 'shims robocopy when not on path' { Mock Test-CommandAvailable { $false } Test-CommandAvailable robocopy | Should -Be $false @@ -283,7 +281,7 @@ Describe 'ensure_robocopy_in_path' -Tag 'Scoop' { } Context 'robocopy is in path' { - It 'does not shim robocopy when it is in path' -Skip:$isUnix { + It 'does not shim robocopy when it is in path' { Mock Test-CommandAvailable { $true } Test-CommandAvailable robocopy | Should -Be $true diff --git a/test/Scoop-Decompress.Tests.ps1 b/test/Scoop-Decompress.Tests.ps1 index 351d19453..81e42ffad 100644 --- a/test/Scoop-Decompress.Tests.ps1 +++ b/test/Scoop-Decompress.Tests.ps1 @@ -4,11 +4,8 @@ . "$PSScriptRoot\..\lib\install.ps1" . "$PSScriptRoot\..\lib\manifest.ps1" . "$PSScriptRoot\..\lib\versions.ps1" -. "$PSScriptRoot\..\lib\unix.ps1" -$isUnix = is_unix - -Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { +Describe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' { BeforeAll { $working_dir = setup_working 'decompress' @@ -19,13 +16,17 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { return $to } - It 'Decompression test cases should exist' { + } + Context 'Decompression test cases should exist' { + BeforeAll { $testcases = "$working_dir\TestCases.zip" + } + It 'Test cases should exist and hash should match' { $testcases | Should -Exist (Get-FileHash -Path $testcases -Algorithm SHA256).Hash.ToLower() | Should -Be '791bfce192917a2ff225dcdd87d23ae5f720b20178d85e68e4b1b56139cf8e6a' - if (!$isUnix) { - Microsoft.PowerShell.Archive\Expand-Archive $testcases $working_dir - } + } + It 'Test cases should be extracted correctly' { + { Microsoft.PowerShell.Archive\Expand-Archive -Path $testcases -DestinationPath $working_dir } | Should -Not -Throw } } @@ -49,14 +50,14 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { $test6_3 = "$working_dir\7ZipTest6.part03.rar" } - It 'extract normal compressed file' -Skip:$isUnix { + It 'extract normal compressed file' { $to = test_extract 'Expand-7zipArchive' $test1 $to | Should -Exist "$to\empty" | Should -Exist (Get-ChildItem $to).Count | Should -Be 1 } - It 'extract nested compressed file' -Skip:$isUnix { + It 'extract nested compressed file' { # file ext: tgz $to = test_extract 'Expand-7zipArchive' $test2 $to | Should -Exist @@ -70,28 +71,28 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { (Get-ChildItem $to).Count | Should -Be 1 } - It 'extract nested compressed file with different inner name' -Skip:$isUnix { + It 'extract nested compressed file with different inner name' { $to = test_extract 'Expand-7zipArchive' $test4 $to | Should -Exist "$to\empty" | Should -Exist (Get-ChildItem $to).Count | Should -Be 1 } - It 'extract splited 7z archives (.001, .002, ...)' -Skip:$isUnix { + It 'extract splited 7z archives (.001, .002, ...)' { $to = test_extract 'Expand-7zipArchive' $test5_1 $to | Should -Exist "$to\empty" | Should -Exist (Get-ChildItem $to).Count | Should -Be 1 } - It 'extract splited RAR archives (.part01.rar, .part02.rar, ...)' -Skip:$isUnix { + It 'extract splited RAR archives (.part01.rar, .part02.rar, ...)' { $to = test_extract 'Expand-7zipArchive' $test6_1 $to | Should -Exist "$to\dummy" | Should -Exist (Get-ChildItem $to).Count | Should -Be 1 } - It 'works with "-Removal" switch ($removal param)' -Skip:$isUnix { + It 'works with "-Removal" switch ($removal param)' { $test1 | Should -Exist test_extract 'Expand-7zipArchive' $test1 $true $test1 | Should -Not -Exist @@ -126,21 +127,21 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { $test2 = "$working_dir\ZstdTest.tar.zst" } - It 'extract normal compressed file' -Skip:$isUnix { + It 'extract normal compressed file' { $to = test_extract 'Expand-ZstdArchive' $test1 $to | Should -Exist "$to\ZstdTest" | Should -Exist (Get-ChildItem $to).Count | Should -Be 1 } - It 'extract nested compressed file' -Skip:$isUnix { + It 'extract nested compressed file' { $to = test_extract 'Expand-ZstdArchive' $test2 $to | Should -Exist "$to\ZstdTest" | Should -Exist (Get-ChildItem $to).Count | Should -Be 1 } - It 'works with "-Removal" switch ($removal param)' -Skip:$isUnix { + It 'works with "-Removal" switch ($removal param)' { $test1 | Should -Exist test_extract 'Expand-ZstdArchive' $test1 $true $test1 | Should -Not -Exist @@ -159,7 +160,7 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { $test2 = "$working_dir\MSITestNull.msi" } - It 'extract normal MSI file' -Skip:$isUnix { + It 'extract normal MSI file' { Mock get_config { $false } $to = test_extract 'Expand-MsiArchive' $test1 $to | Should -Exist @@ -167,13 +168,13 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { (Get-ChildItem "$to\MSITest").Count | Should -Be 1 } - It 'extract empty MSI file using lessmsi' -Skip:$isUnix { + It 'extract empty MSI file using lessmsi' { Mock get_config { $true } $to = test_extract 'Expand-MsiArchive' $test2 $to | Should -Exist } - It 'works with "-Removal" switch ($removal param)' -Skip:$isUnix { + It 'works with "-Removal" switch ($removal param)' { Mock get_config { $false } $test1 | Should -Exist test_extract 'Expand-MsiArchive' $test1 $true @@ -192,14 +193,14 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { $test = "$working_dir\InnoTest.exe" } - It 'extract Inno Setup file' -Skip:$isUnix { + It 'extract Inno Setup file' { $to = test_extract 'Expand-InnoArchive' $test $to | Should -Exist "$to\empty" | Should -Exist (Get-ChildItem $to).Count | Should -Be 1 } - It 'works with "-Removal" switch ($removal param)' -Skip:$isUnix { + It 'works with "-Removal" switch ($removal param)' { $test | Should -Exist test_extract 'Expand-InnoArchive' $test $true $test | Should -Not -Exist @@ -212,14 +213,14 @@ Describe 'Decompression function' -Tag 'Scoop', 'Decompress' { $test = "$working_dir\ZipTest.zip" } - It 'extract compressed file' -Skip:$isUnix { + It 'extract compressed file' { $to = test_extract 'Expand-ZipArchive' $test $to | Should -Exist "$to\empty" | Should -Exist (Get-ChildItem $to).Count | Should -Be 1 } - It 'works with "-Removal" switch ($removal param)' -Skip:$isUnix { + It 'works with "-Removal" switch ($removal param)' { $test | Should -Exist test_extract 'Expand-ZipArchive' $test $true $test | Should -Not -Exist diff --git a/test/Scoop-Install.Tests.ps1 b/test/Scoop-Install.Tests.ps1 index fe5fd83d9..1e2c30d0a 100644 --- a/test/Scoop-Install.Tests.ps1 +++ b/test/Scoop-Install.Tests.ps1 @@ -2,9 +2,6 @@ . "$PSScriptRoot\..\lib\core.ps1" . "$PSScriptRoot\..\lib\manifest.ps1" . "$PSScriptRoot\..\lib\install.ps1" -. "$PSScriptRoot\..\lib\unix.ps1" - -$isUnix = is_unix Describe 'appname_from_url' -Tag 'Scoop' { It 'should extract the correct name' { @@ -34,8 +31,8 @@ Describe 'url_remote_filename' -Tag 'Scoop' { } } -Describe 'is_in_dir' -Tag 'Scoop' { - It 'should work correctly' -Skip:$isUnix { +Describe 'is_in_dir' -Tag 'Scoop', 'Windows' { + It 'should work correctly' { is_in_dir 'C:\test' 'C:\foo' | Should -BeFalse is_in_dir 'C:\test' 'C:\test\foo\baz.zip' | Should -BeTrue @@ -44,7 +41,7 @@ Describe 'is_in_dir' -Tag 'Scoop' { } } -Describe 'env add and remove path' -Tag 'Scoop' { +Describe 'env add and remove path' -Tag 'Scoop', 'Windows' { # test data $manifest = @{ 'env_add_path' = @('foo', 'bar') @@ -55,7 +52,7 @@ Describe 'env add and remove path' -Tag 'Scoop' { # store the original path to prevent leakage of tests $origPath = $env:PATH - It 'should concat the correct path' -Skip:$isUnix { + It 'should concat the correct path' { Mock add_first_in_path {} Mock remove_from_path {} diff --git a/test/Scoop-TestLib.ps1 b/test/Scoop-TestLib.ps1 index 1e5812233..219453673 100644 --- a/test/Scoop-TestLib.ps1 +++ b/test/Scoop-TestLib.ps1 @@ -1,69 +1,3 @@ -if (!$script:run) { $script:run = 0 } -if (!$script:failed) { $script:failed = 0 } - -function filter_tests($arg) { - if (!$arg) { return } - $script:filter = $arg -join ' ' - Write-Host "filtering by '$filter'" -} -function test($desc, $assertions) { - if ($filter -and $desc -notlike "*$filter*") { return } - $script:test = $desc - $script:run++ - try { - $assertions.invoke() - } catch { - script:fail $_.exception.innerexception.message - } - $script:test = $null -} - -function assert($x, $eq = '__undefined', $ne = '__undefined') { - if ($args.length -gt 0) { - fail "unexpected arguments: $args" - } - - if ($eq -ne '__undefined') { - if ($x -ne $eq) { fail "$(fmt $x) != $(fmt $eq)" } - } elseif ($ne -ne '__undefined') { - if ($x -eq $ne) { fail "$(fmt $x) == $(fmt $ne)" } - } else { - if (!$x) { fail "$x" } - } -} - -function test_results { - $col = 'darkgreen' - $res = 'all passed' - if ($script:failed -gt 0) { - $col = 'darkred' - $res = "$script:failed failed" - } - - Write-Host "ran $script:run tests, " -NoNewline - Write-Host $res -f $col -} - -function script:fail($msg) { - $script:failed++ - $invoked = (Get-Variable -Scope 1 myinvocation).value - - $script = Split-Path $invoked.scriptname -Leaf - $line = $invoked.scriptlinenumber - - if ($script:test) { $msg = "$script:test`r`n -> $msg" } - - Write-Host "FAIL: $msg" -f darkred - Write-Host "$script line $line`:" - Write-Host (($invoked.positionmessage -split "`r`n")[1..2] -join "`r`n") -} - -function script:fmt($var) { - if ($null -eq $var) { return "`$null" } - if ($var -is [string]) { return "'$var'" } - return $var -} - # copies fixtures to a working directory function setup_working($name) { $fixtures = "$PSScriptRoot/fixtures/$name" @@ -73,11 +7,7 @@ function setup_working($name) { } # reset working dir - if ($PSVersionTable.Platform -eq 'Unix') { - $working_dir = "/tmp/ScoopTestFixtures/$name" - } else { - $working_dir = "$env:TEMP/ScoopTestFixtures/$name" - } + $working_dir = "$([IO.Path]::GetTempPath())ScoopTestFixtures/$name" if (Test-Path $working_dir) { Remove-Item -Recurse -Force $working_dir diff --git a/test/bin/init.ps1 b/test/bin/init.ps1 index a37125182..23ace0dfe 100644 --- a/test/bin/init.ps1 +++ b/test/bin/init.ps1 @@ -1,6 +1,5 @@ #Requires -Version 5.1 Write-Host "PowerShell: $($PSVersionTable.PSVersion)" -Write-Host (7z.exe | Select-String -Pattern '7-Zip').ToString() Write-Host 'Check and install testsuite dependencies ...' if (Get-InstalledModule -Name Pester -MinimumVersion 4.0 -MaximumVersion 4.99 -ErrorAction SilentlyContinue) { Write-Host 'Pester 4 is already installed.' diff --git a/test/bin/test.ps1 b/test/bin/test.ps1 index f70805ade..ea8de6507 100644 --- a/test/bin/test.ps1 +++ b/test/bin/test.ps1 @@ -10,13 +10,17 @@ $splat = @{ Path = $TestPath PassThru = $true } +$excludes = @() + +if ($IsLinux -or $IsMacOS) { + Write-Warning 'Skipping Windows-only tests on Linux/macOS' + $excludes += 'Windows' +} if ($env:CI -eq $true) { Write-Host "Load 'BuildHelpers' environment variables ..." Set-BuildEnvironment -Force - $CI_WIN = (($env:RUNNER_OS -eq 'Windows') -or ($env:CI_WINDOWS -eq $true)) - $excludes = @() $commit = $env:BHCommitHash $commitMessage = $env:BHCommitMessage @@ -27,11 +31,6 @@ if ($env:CI -eq $true) { $excludes += 'Linter' } - if (!$CI_WIN) { - Write-Warning 'Skipping tests and code linting for decompress.ps1 because they only work on Windows' - $excludes += 'Decompress' - } - $changedScripts = (Get-GitChangedFile -Include '*.ps1' -Commit $commit) if (!$changedScripts) { Write-Warning "Skipping tests and code linting for *.ps1 files because they didn't change" @@ -44,9 +43,11 @@ if ($env:CI -eq $true) { $excludes += 'Decompress' } - if ('Decompress' -notin $excludes) { + if ('Decompress' -notin $excludes -and 'Windows' -notin $excludes) { Write-Host 'Install decompress dependencies ...' + Write-Host (7z.exe | Select-String -Pattern '7-Zip').ToString() + $env:SCOOP_HELPERS_PATH = 'C:\projects\helpers' if (!(Test-Path $env:SCOOP_HELPERS_PATH)) { New-Item -ItemType Directory -Path $env:SCOOP_HELPERS_PATH @@ -83,10 +84,6 @@ if ($env:CI -eq $true) { } } - if ($excludes.Length -gt 0) { - $splat.ExcludeTag = $excludes - } - # Display CI environment variables $buildVariables = ( Get-ChildItem -Path 'Env:' ).Where( { $_.Name -match '^(?:BH|CI(?:_|$)|APPVEYOR|GITHUB_|RUNNER_|SCOOP_)' } ) $buildVariables += ( Get-Variable -Name 'CI_*' -Scope 'Script' ) @@ -97,24 +94,26 @@ if ($env:CI -eq $true) { Out-String Write-Host 'CI variables:' Write-Host $details -ForegroundColor DarkGray - - # AppVeyor - if ($env:BHBuildSystem -eq "AppVeyor") { - $resultsXml = "$PSScriptRoot\TestResults.xml" - $splat += @{ - OutputFile = $resultsXml - OutputFormat = 'NUnitXML' - } - - Write-Host 'Invoke-Pester' @splat - $result = Invoke-Pester @splat - - (New-Object Net.WebClient).UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $resultsXml) - exit $result.FailedCount - } } -# GitHub Actions / Local -Write-Host 'Invoke-Pester' @splat -$result = Invoke-Pester @splat +if ($excludes.Length -gt 0) { + $splat.ExcludeTag = $excludes +} + +if ($env:BHBuildSystem -eq 'AppVeyor') { + # AppVeyor + $resultsXml = "$PSScriptRoot\TestResults.xml" + $splat += @{ + OutputFile = $resultsXml + OutputFormat = 'NUnitXML' + } + Write-Host 'Invoke-Pester' @splat + $result = Invoke-Pester @splat + (New-Object Net.WebClient).UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $resultsXml) +} else { + # GitHub Actions / Local + Write-Host 'Invoke-Pester' @splat + $result = Invoke-Pester @splat +} + exit $result.FailedCount