Skip to content

Commit

Permalink
🚀 [Feature]: Enable skips on SourceCode.PSModule tests (#84)
Browse files Browse the repository at this point in the history
## Description

- Implements a inline way to skip tests on source code tests.
  - Fixes #73
- Allow to hold completers in the `src/functions/public` folder.
- Improve gathering of info from the source code.

## Type of change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] 📖 [Docs]
- [ ] 🪲 [Fix]
- [ ] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [x] 🚀 [Feature]
- [ ] 🌟 [Breaking change]

## Checklist

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
  • Loading branch information
MariusStorhaug authored Dec 21, 2024
1 parent c98cca9 commit fe8b2bf
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 148 deletions.
418 changes: 281 additions & 137 deletions scripts/tests/PSModule/SourceCode.Tests.ps1

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tests/src/functions/public/New-PSModuleTest.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.0'}

#SkipTest:FunctionTest:Difficult to test due to the nature of the function.
#SkipTest:Verbose:Just want to test that a function can have multiple skips.
function New-PSModuleTest {
<#
.SYNOPSIS
Expand Down Expand Up @@ -28,11 +29,10 @@ function New-PSModuleTest {
[string] $Name
)
Write-Debug "Debug message"
Write-Verbose "Verbose message" -Verbose
Write-Output "Hello, $Name!"
}

New-Alias New-PSModuleTestAlias3 New-PSModuleTest
New-Alias -Name New-PSModuleTestAlias4 -Value New-PSModuleTest


Set-Alias New-PSModuleTestAlias5 New-PSModuleTest
4 changes: 3 additions & 1 deletion tests/src/functions/public/Test-PSModuleTest.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function Test-PSModuleTest {
#SkipTest:Verbose:Just want to test that a function can have multiple skips.
function Test-PSModuleTest {
<#
.SYNOPSIS
Performs tests on a module.
Expand All @@ -15,4 +16,5 @@
[string] $Name
)
Write-Output "Hello, $Name!"
Write-Verbose 'Verbose message' -Verbose
}
8 changes: 8 additions & 0 deletions tests/src/functions/public/completers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Register-ArgumentCompleter -CommandName New-PSModuleTest -ParameterName Name -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters

'Alice', 'Bob', 'Charlie' | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
7 changes: 4 additions & 3 deletions tests/srcWithManifest/functions/public/New-PSModuleTest.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.0'}

#SkipTest:FunctionTest:Difficult to test due to the nature of the function.
#SkipTest:Verbose:Just want to test that a function can have multiple skips.
function New-PSModuleTest {
<#
.SYNOPSIS
Expand Down Expand Up @@ -27,11 +28,11 @@ function New-PSModuleTest {
[Parameter(Mandatory)]
[string] $Name
)
Write-Debug "Debug message"
Write-Verbose "Verbose message" -Verbose
Write-Output "Hello, $Name!"
}

New-Alias New-PSModuleTestAlias3 New-PSModuleTest
New-Alias -Name New-PSModuleTestAlias4 -Value New-PSModuleTest


Set-Alias New-PSModuleTestAlias5 New-PSModuleTest
4 changes: 3 additions & 1 deletion tests/srcWithManifest/functions/public/Test-PSModuleTest.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function Test-PSModuleTest {
#SkipTest:Verbose:Just want to test that a function can have multiple skips.
function Test-PSModuleTest {
<#
.SYNOPSIS
Performs tests on a module.
Expand All @@ -15,4 +16,5 @@
[string] $Name
)
Write-Output "Hello, $Name!"
Write-Verbose 'Verbose message' -Verbose
}
3 changes: 0 additions & 3 deletions tests/tests/PSModuleTest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
It 'Function: Get-PSModuleTest' {
Get-PSModuleTest -Name 'World' | Should -Be 'Hello, World!'
}
It 'Function: New-PSModuleTest' {
New-PSModuleTest -Name 'World' | Should -Be 'Hello, World!'
}
It 'Function: Set-PSModuleTest' {
Set-PSModuleTest -Name 'World' | Should -Be 'Hello, World!'
}
Expand Down

0 comments on commit fe8b2bf

Please sign in to comment.