From d08cedb34b177af699f0219598d3d5f4d7c21e57 Mon Sep 17 00:00:00 2001 From: Tig Kindel Date: Sun, 5 Nov 2023 12:52:52 -0800 Subject: [PATCH] Fixed tests --- .github/workflows/publish.yml | 92 +++++++++++++++---------------- Build.ps1 | 7 ++- Source/F7History.psd1 | 4 +- Tests/Public/f7_history.Tests.ps1 | 75 ++++++++++++++----------- test.ps1 | 18 ++++-- 5 files changed, 110 insertions(+), 86 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bc7ed9d..97501ca 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -38,11 +38,11 @@ jobs: name: Modules path: ${{github.workspace}}/output - # - name: Upload Tests - # uses: actions/upload-artifact@v3 - # with: - # name: PesterTests - # path: ${{github.workspace}}/Tests + - name: Upload Tests + uses: actions/upload-artifact@v3 + with: + name: PesterTests + path: ${{github.workspace}}/Tests - name: Upload RequiredModules.psd1 uses: actions/upload-artifact@v3 @@ -69,48 +69,48 @@ jobs: rootPath: Modules/F7History repoToken: ${{ secrets.GITHUB_TOKEN }} - # test: - # needs: build - # runs-on: ${{ matrix.os }} - # strategy: - # fail-fast: false - # matrix: - # os: [windows-latest, ubuntu-latest, macos-latest] - # steps: - # - name: Download Build Output - # uses: actions/download-artifact@v3 - - # - name: Install Required Modules - # uses: PoshCode/Actions/install-requiredmodules@v1 - # with: - # requiredModules-path: ${{github.workspace}}/RequiredModules/RequiredModules.psd1 - - # # see https://github.com/Jaykul/RequiredModules/issues/6 - # - name: Manually Install Modules F7History is dependent on - # shell: pwsh - # run: | - # Install-Module -Name Microsoft.PowerShell.ConsoleGuiTools -Force -SkipPublisherCheck -Scope CurrentUser - # Install-Module -Name PSReadLine -Force -SkipPublisherCheck -Scope CurrentUser - # Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser - - # - name: Run Pester Tests - # uses: PoshCode/Actions/pester@v2 - # with: - # pesterVersion: "5.5.0" - # codeCoveragePath: Modules/F7History - # moduleUnderTest: F7History - # additionalModulePaths: ${{github.workspace}}/Modules + test: + needs: build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + steps: + - name: Download Build Output + uses: actions/download-artifact@v3 + + - name: Install Required Modules + uses: PoshCode/Actions/install-requiredmodules@v1 + with: + requiredModules-path: ${{github.workspace}}/RequiredModules/RequiredModules.psd1 + + # see https://github.com/Jaykul/RequiredModules/issues/6 + - name: Manually Install Modules F7History is dependent on + shell: pwsh + run: | + Install-Module -Name Microsoft.PowerShell.ConsoleGuiTools -Force -SkipPublisherCheck -Scope CurrentUser + Install-Module -Name PSReadLine -Force -SkipPublisherCheck -Scope CurrentUser + Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser + + - name: Run Pester Tests + uses: PoshCode/Actions/pester@v2 + with: + pesterVersion: "5.5.0" + codeCoveragePath: Modules/F7History + moduleUnderTest: F7History + additionalModulePaths: ${{github.workspace}}/Modules - # - name: Publish Test Results - # uses: zyborg/dotnet-tests-report@v1 - # with: - # test_results_path: results.xml - - # - name: Upload Results - # uses: actions/upload-artifact@v3 - # with: - # name: Pester Results - # path: ${{github.workspace}}/*.xml + - name: Publish Test Results + uses: zyborg/dotnet-tests-report@v1 + with: + test_results_path: results.xml + + - name: Upload Results + uses: actions/upload-artifact@v3 + with: + name: Pester Results + path: ${{github.workspace}}/*.xml publish: needs: diff --git a/Build.ps1 b/Build.ps1 index 66c7288..9c57e8a 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -38,7 +38,8 @@ $ocgvModule = "Microsoft.PowerShell.ConsoleGuiTools" $localRepositoryPath = $localRepository | Select-Object -ExpandProperty SourceLocation $v = Get-ChildItem "${localRepositoryPath}/${ocgvModule}*.nupkg" | Select-Object -ExpandProperty Name | Sort-Object -Descending | Select-Object -First 1 if ($v -match "$ocgvModule.(.*?).nupkg") { - $ocgvVersion = $Matches[1] + $v = [Version]::new($Matches[1]) + $ocgvVersion = "$($v.Major).$($v.Minor).$($v.Build)" "$ocgvModule v $ocgvVersion found in local repository; setting RequiredVersion in $PsdPath" Update-ModuleManifest -Path $PsdPath -RequiredModules @( @{ @@ -52,7 +53,9 @@ $ocgvModule = "Microsoft.PowerShell.ConsoleGuiTools" } if ($null -eq $ocgvVersion) { - $ocgvVersion = (Find-Module $ocgvModule).Version + $module = (Find-Module $ocgvModule) | Select-Object -ExpandProperty Version | Sort-Object -Descending | Select-Object -First 1 + $v = [Version]::new($module) + $ocgvVersion = "$($v.Major).$($v.Minor).$($v.Build)" "$ocgvModule v $ocgvVersion` found in PSGallery; setting ModuleVersion in $PsdPath" Update-ModuleManifest -Path $PsdPath -RequiredModules @( @{ diff --git a/Source/F7History.psd1 b/Source/F7History.psd1 index 6cc8a29..04b8b3c 100644 --- a/Source/F7History.psd1 +++ b/Source/F7History.psd1 @@ -3,7 +3,7 @@ # # Generated by: Tig Kindel # -# Generated on: 11/4/2023 +# Generated on: 11/5/2023 # @{ @@ -52,7 +52,7 @@ Description = 'Press F7 to get a graphical Command History in Powershell.' # Modules that must be imported into the global environment prior to importing this module RequiredModules = @(@{ModuleName = 'PSReadline'; ModuleVersion = '2.1'; }, - @{ModuleName = 'Microsoft.PowerShell.ConsoleGuiTools'; ModuleVersion = '0.7.6.0'; }) + @{ModuleName = 'Microsoft.PowerShell.ConsoleGuiTools'; ModuleVersion = '0.7.6'; }) # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() diff --git a/Tests/Public/f7_history.Tests.ps1 b/Tests/Public/f7_history.Tests.ps1 index 79298db..05e2874 100644 --- a/Tests/Public/f7_history.Tests.ps1 +++ b/Tests/Public/f7_history.Tests.ps1 @@ -1,37 +1,48 @@ #requires -Module F7History -# Describe "f7_history" { -# Context "The f7_history function" { -# $cmd = $null -# try { -# $cmd = get-item -path Function:\f7_history -# } catch { -# $cmd = $null -# } - -# It " is defined" { -# $cmd | Should -Be "f7_history" -# } -# } +Describe "f7_history" { + Context "The f7_history function" { + BeforeAll { + $cmd = $null + try { + $cmd = get-item -path Function:\f7_history + } + catch { + $cmd = $null + } + } + It " is defined" { + $cmd | Should -Be "f7_history" + } + } -# Context "The f7_history function" { -# $parameters = (Get-Command f7_history).Parameters -# It "has a required string parameter for the global flag" { -# $parameters.ContainsKey("global") | Should -Be $true -# $parameters["global"].ParameterType | Should -Be ([boolean]) -# $parameters["global"].Attributes.Where{$_ -is [Parameter]}.Mandatory | Should -Be $true -# } -# } + Context "The f7_history function" { + BeforeAll { + $parameters = (Get-Command f7_history).Parameters + } + It "has a required string parameter for the global flag" { + $parameters.ContainsKey("global") | Should -Be $true + $parameters["global"].ParameterType | Should -Be ([boolean]) + $parameters["global"].Attributes.Where{ $_ -is [Parameter] }.Mandatory | Should -Be $true + } + } -# Context "Default key bindings" { -# $Result = (Get-PSReadLineKeyHandler -Chord F7).Function -# It "defines F7 as the default key binding" { -# $Result | Should -Be "Show Matching Command History" -# } + Context "Default F7 keybinding " { + BeforeAll { + $Result = (Get-PSReadLineKeyHandler -Chord F7).Function + } + It "defines F7 as the default key binding" { + $Result | Should -Be "Show Matching Command History" + } -# $Result = (Get-PSReadLineKeyHandler -Chord Shift-F7).Function -# It "defines Shift-F7 as the default key binding" { -# $Result | Should -Be "Show Matching Command History for All" -# } -# } -# } + } + + Context "Default Shift-F7 keybinding " { + BeforeAll { + $Result = (Get-PSReadLineKeyHandler -Chord Shift-F7).Function + } + It "defines Shift-F7 as the default key binding" { + $Result | Should -Be "Show Matching Command History for All" + } + } +} diff --git a/test.ps1 b/test.ps1 index 4217db9..681bff4 100644 --- a/test.ps1 +++ b/test.ps1 @@ -34,14 +34,24 @@ Remove-Module $ModuleName -ErrorAction Ignore -Force $ModuleUnderTest = Import-Module $FoundModule.FullName -PassThru -Force -DisableNameChecking -Verbose:$false Write-Host "Invoke-Pester for Module $($ModuleUnderTest) version $($ModuleUnderTest.Version)" +$MyOptions = @{ + Run = @{ # Run configuration. + PassThru = $true # Return result object after finishing the test run. + } +} + +$config = New-PesterConfiguration -Hashtable $MyOptions +$config.Output.Verbosity = "Detailed" + if ($CodeCoverage) { + $config.CodeCoverage.Enabled = $true + $config.CodeCoverage.OutputPath = "./coverage.xml" # Get code coverage for the psm1 file to a coverage.xml that we can mess with later - # Invoke-Pester ./Tests -Show $Show -PesterOption @{ + #Invoke-Pester -Confi # IncludeVSCodeMarker = $IncludeVSCodeMarker # } -CodeCoverage $ModuleUnderTest.Path -CodeCoverageOutputFile ./coverage.xml -PassThru | Convert-CodeCoverage -SourceRoot ./Source -} else { - Invoke-Pester -Path ./Tests -} +} +Invoke-Pester -Configuration $config Write-Host if (-not $SkipScriptAnalyzer) {