From b4de4cfe9ef053ce07e216f1534fe619d9f25890 Mon Sep 17 00:00:00 2001 From: Mark Schofield Date: Sun, 5 Oct 2025 21:12:54 -0700 Subject: [PATCH 1/3] Use 'Should -HaveCount' not '.Count | Should -Be' for better error messages --- Tests/BuildConfigurationsCompleter.Tests.ps1 | 4 ++-- Tests/BuildPresetsCompleter.Tests.ps1 | 4 ++-- Tests/BuildTargetsCompleter.Tests.ps1 | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/BuildConfigurationsCompleter.Tests.ps1 b/Tests/BuildConfigurationsCompleter.Tests.ps1 index a2663d8..4f7fae0 100644 --- a/Tests/BuildConfigurationsCompleter.Tests.ps1 +++ b/Tests/BuildConfigurationsCompleter.Tests.ps1 @@ -12,7 +12,7 @@ BeforeAll { Describe 'BuildConfigurationsCompleter' { It 'Returns the default configurations when no preset is specified' { $Completions = Get-CommandCompletion "Build-CMakeBuild -Configuration " - $Completions.CompletionMatches.Count | Should -Be 4 + $Completions.CompletionMatches | Should -HaveCount 4 $Completions.CompletionMatches[0].CompletionText | Should -Be 'Release' $Completions.CompletionMatches[1].CompletionText | Should -Be 'Debug' $Completions.CompletionMatches[2].CompletionText | Should -Be 'RelWithDebInfo' @@ -21,7 +21,7 @@ Describe 'BuildConfigurationsCompleter' { It 'Returns the default configurations when no preset is specified, filtered by the word to complete' { $Completions = Get-CommandCompletion "Build-CMakeBuild -Configuration D" - $Completions.CompletionMatches.Count | Should -Be 1 + $Completions.CompletionMatches | Should -HaveCount 1 $Completions.CompletionMatches[0].CompletionText | Should -Be 'Debug' } } diff --git a/Tests/BuildPresetsCompleter.Tests.ps1 b/Tests/BuildPresetsCompleter.Tests.ps1 index 10d24af..5b1909c 100644 --- a/Tests/BuildPresetsCompleter.Tests.ps1 +++ b/Tests/BuildPresetsCompleter.Tests.ps1 @@ -12,14 +12,14 @@ BeforeAll { Describe 'BuildPresetsCompleter' { It 'Returns the presets from the discovered presets file, in the order that they are defined' { $Completions = Get-CommandCompletion "Build-CMakeBuild -Preset " - $Completions.CompletionMatches.Count | Should -Be 2 + $Completions.CompletionMatches | Should -HaveCount 2 $Completions.CompletionMatches[0].CompletionText | Should -Be 'windows-x64' $Completions.CompletionMatches[1].CompletionText | Should -Be 'windows-arm' } It 'Returns the presets from the discovered presets file, filtered by the word to complete' { $Completions = Get-CommandCompletion "Build-CMakeBuild -Preset windows-a" - $Completions.CompletionMatches.Count | Should -Be 1 + $Completions.CompletionMatches | Should -HaveCount 1 $Completions.CompletionMatches[0].CompletionText | Should -Be 'windows-arm' } } diff --git a/Tests/BuildTargetsCompleter.Tests.ps1 b/Tests/BuildTargetsCompleter.Tests.ps1 index 5742a65..779b819 100644 --- a/Tests/BuildTargetsCompleter.Tests.ps1 +++ b/Tests/BuildTargetsCompleter.Tests.ps1 @@ -20,7 +20,7 @@ Describe 'BuildTargetsCompleter' { Using-Location "$PSScriptRoot/ReferenceBuild" { $Completions = Get-CommandCompletion "Build-CMakeBuild -Targets " - $Completions.CompletionMatches.Count | Should -Be 10 + $Completions.CompletionMatches | Should -HaveCount 10 $Completions.CompletionMatches.CompletionText | Should -Be @( 'A_Library' 'B_Library' From cc6a5be8c064494877009096bafad8df9cd239df Mon Sep 17 00:00:00 2001 From: Mark Schofield Date: Sun, 5 Oct 2025 21:13:22 -0700 Subject: [PATCH 2/3] Add tests for 'GetMacroConstants' --- Tests/GetMacroConstants.Tests.ps1 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Tests/GetMacroConstants.Tests.ps1 diff --git a/Tests/GetMacroConstants.Tests.ps1 b/Tests/GetMacroConstants.Tests.ps1 new file mode 100644 index 0000000..6ddb5cd --- /dev/null +++ b/Tests/GetMacroConstants.Tests.ps1 @@ -0,0 +1,26 @@ +#Requires -PSEdition Core + +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' + +BeforeAll { + . $PSScriptRoot/../PSCMake/Common/CMake.ps1 +} + +Describe 'GetMacroConstants' { + It 'Returns the correct macro constants' { + $HostSystemName = if ($IsWindows) { + 'Windows' + } elseif ($IsMacOS) { + 'Darwin' + } elseif ($IsLinux) { + 'Linux' + } else { + Write-Error "Unsupported `${hostSystemName} value." + } + + $MacroConstants = GetMacroConstants + $MacroConstants['${hostSystemName}'] | Should -Be $HostSystemName + $MacroConstants['$vendor{PSCMake}'] | Should -Be 'true' + } +} From 0ed524af84124ce4717a35d438920eed47cb7461 Mon Sep 17 00:00:00 2001 From: Mark Schofield Date: Sun, 5 Oct 2025 21:13:24 -0700 Subject: [PATCH 3/3] Add Build\RunTests.ps1 --- .github/workflows/ci.yaml | 16 ++-------------- .github/workflows/pull-request.yaml | 14 +------------- .vscode/settings.json | 1 + Build/RunTests.ps1 | 27 +++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 Build/RunTests.ps1 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a3eaa62..e000ab4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,22 +24,10 @@ jobs: - name: Invoke-Pester shell: pwsh run: | - Import-Module Pester - $Configuration = [PesterConfiguration]@{ - Run = @{ - Path = '*' - Passthru = $true - } - CodeCoverage = @{ - Enabled = $true - OutputFormat = 'JaCoCo' - OutputPath = '${{ github.workspace }}/Pester-Coverage.xml' - } - } - Invoke-Pester -Configuration $Configuration + ${{ github.workspace }}/Build/RunTests.ps1 - uses: codecov/codecov-action@v5 with: - files: '${{ github.workspace }}/Pester-Coverage.xml' + files: '${{ github.workspace }}/__output/coverage.xml' flags: unittests name: codecov-umbrella token: '${{ secrets.CODECOV_TOKEN }}' diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 79fd98b..aef6467 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -15,19 +15,7 @@ jobs: - name: Invoke-Pester shell: pwsh run: | - Import-Module Pester - $Configuration = [PesterConfiguration]@{ - Run = @{ - Path = '*' - Passthru = $true - } - CodeCoverage = @{ - Enabled = $true - OutputFormat = 'JaCoCo' - OutputPath = '${{ github.workspace }}/Pester-Coverage.xml' - } - } - Invoke-Pester -Configuration $Configuration + ${{ github.workspace }}/Build/RunTests.ps1 - name: Build shell: pwsh run: | diff --git a/.vscode/settings.json b/.vscode/settings.json index 27a865f..9a725c2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + "coverage-gutters.coverageBaseDir": "__output", "editor.renderWhitespace": "all", "powershell.codeFormatting.newLineAfterCloseBrace": false, "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline", diff --git a/Build/RunTests.ps1 b/Build/RunTests.ps1 new file mode 100644 index 0000000..bad0c94 --- /dev/null +++ b/Build/RunTests.ps1 @@ -0,0 +1,27 @@ +#Requires -PSEdition Core + +[CmdletBinding()] +param( +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' + +Import-Module Pester + +$WorkingDirectory = $PSScriptRoot +$RepositoryRoot = Resolve-Path -Path (& git -C $WorkingDirectory rev-parse '--show-toplevel') +$Configuration = [PesterConfiguration]@{ + Run = @{ + Path = $RepositoryRoot + Passthru = $true + } + CodeCoverage = @{ + Enabled = $true + Path = "$RepositoryRoot/PSCMake" + OutputFormat = 'JaCoCo' + OutputPath = "$RepositoryRoot/__output/coverage.xml" + } +} + +Invoke-Pester -Configuration $Configuration