Skip to content

Commit 3dcca81

Browse files
Add documentation for skipping individual PSModule framework tests (#252)
The Test-PSModule framework runs style and standards tests against source code (e.g., enforcing one function per file, requiring CmdletBinding attributes). Users needed guidance on skipping specific tests per-file when framework rules don't apply. ## Changes - **New documentation section** "Skipping Individual Framework Tests" added to README - Syntax: `#SkipTest:<TestID>:<Reason>` comment at file top - Complete reference table of 10 SourceCode test IDs with descriptions - Module test overview (import/manifest validation) - Code example demonstrating skip usage - Best practices and configuration cross-references ## Available Test IDs | Test ID | What It Enforces | |---------|------------------| | `NumberOfProcessors` | Use `[System.Environment]::ProcessorCount` not `$env:NUMBER_OF_PROCESSORS` | | `Verbose` | Don't pass `-Verbose` to commands (overrides user preference) | | `OutNull` | Use `$null = ...` not `\| Out-Null` | | `FunctionCount` | One function per file | | `FunctionName` | Filename matches function name | | `CmdletBinding` | All functions have `[CmdletBinding()]` | | `ParamBlock` | All functions have `param()` block | | `FunctionTest` | Public functions have tests | ## Example ```powershell #SkipTest:FunctionCount:Contains helper functions for main function function Get-ComplexData { [CmdletBinding()] param([string]$Path) $data = Get-RawData -Path $Path return Format-ComplexData -Data $data } function Get-RawData { ... } function Format-ComplexData { ... } ``` Based on analysis of [Test-PSModule framework tests](https://github.com/PSModule/Test-PSModule/tree/main/scripts/tests). <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>🩹 [Patch]: Add doc for how to skip framework (PSModule) tests</issue_title> > <issue_description>### Describe the change > > Based on the code in PSModule/Test-PSModule, we need to recreate guidance in the readme on Process-PSModule for how users can skip individual tests from the framework, i.e. number of functions to have in a file.</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #251 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
1 parent 88570b1 commit 3dcca81

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,110 @@ This is useful for reviewing what was checked even when no issues are found.
445445
For a complete list of available environment variables and configuration options, see the
446446
[super-linter environment variables documentation](https://github.com/super-linter/super-linter#environment-variables).
447447

448+
## Skipping Individual Framework Tests
449+
450+
The PSModule framework tests run automatically as part of the `Test-Module` and `Test-SourceCode` jobs. While you can skip entire test categories using the configuration settings (e.g., `Test.PSModule.Skip`), you can also skip individual framework tests on a per-file basis when needed.
451+
452+
### How to Skip Tests
453+
454+
To skip an individual framework test for a specific file, add a special comment at the top of that file:
455+
456+
```powershell
457+
#SkipTest:<TestID>:<Reason>
458+
```
459+
460+
- `<TestID>`: The unique identifier of the test to skip (see list below)
461+
- `<Reason>`: A brief explanation of why the test is being skipped
462+
463+
The skip comment will cause the framework to skip that specific test for that file only, and will log a warning in the build output with the reason provided.
464+
465+
### Available Framework Tests
466+
467+
#### SourceCode Tests
468+
469+
These tests run against your source code files in the `src` directory:
470+
471+
| Test ID | Description | Example Skip Comment |
472+
|---------|-------------|---------------------|
473+
| `NumberOfProcessors` | Enforces use of `[System.Environment]::ProcessorCount` instead of `$env:NUMBER_OF_PROCESSORS` | `#SkipTest:NumberOfProcessors:Legacy code compatibility required` |
474+
| `Verbose` | Ensures code does not pass `-Verbose` to other commands (which would override user preference), unless explicitly disabled with `-Verbose:$false` | `#SkipTest:Verbose:Required for debugging output` |
475+
| `OutNull` | Enforces use of `$null = ...` instead of `... \| Out-Null` for better performance | `#SkipTest:OutNull:Pipeline processing required` |
476+
| `NoTernary` | Prohibits ternary operators for PowerShell 5.1 compatibility (this test is skipped by default in the framework) | `#SkipTest:NoTernary:PowerShell 7+ only module` |
477+
| `LowercaseKeywords` | Ensures all PowerShell keywords are lowercase | `#SkipTest:LowercaseKeywords:Generated code` |
478+
| `FunctionCount` | Ensures each file contains exactly one function | `#SkipTest:FunctionCount:Helper functions included` |
479+
| `FunctionName` | Ensures the filename matches the function name | `#SkipTest:FunctionName:Legacy naming convention` |
480+
| `CmdletBinding` | Requires all functions to have `[CmdletBinding()]` attribute | `#SkipTest:CmdletBinding:Simple helper function` |
481+
| `ParamBlock` | Requires all functions to have a `param()` block | `#SkipTest:ParamBlock:No parameters needed` |
482+
| `FunctionTest` | Ensures all public functions have corresponding tests | `#SkipTest:FunctionTest:Test in development` |
483+
484+
#### Module Tests
485+
486+
These tests run against the compiled module in the `outputs/module` directory:
487+
488+
- Module import validation
489+
- Module manifest validation
490+
491+
Module tests typically don't need to be skipped as they validate the final built module.
492+
493+
### Example Usage
494+
495+
Here's an example of a function file that skips the `FunctionCount` test because it includes helper functions:
496+
497+
```powershell
498+
#SkipTest:FunctionCount:This file contains helper functions for the main function
499+
500+
function Get-ComplexData {
501+
<#
502+
.SYNOPSIS
503+
Retrieves complex data using helper functions.
504+
#>
505+
[CmdletBinding()]
506+
param(
507+
[Parameter(Mandatory)]
508+
[string] $Path
509+
)
510+
511+
$data = Get-RawData -Path $Path
512+
$processed = Format-ComplexData -Data $data
513+
return $processed
514+
}
515+
516+
function Get-RawData {
517+
[CmdletBinding()]
518+
param(
519+
[Parameter(Mandatory)]
520+
[string] $Path
521+
)
522+
# Helper function implementation
523+
}
524+
525+
function Format-ComplexData {
526+
[CmdletBinding()]
527+
param(
528+
[Parameter(Mandatory)]
529+
$Data
530+
)
531+
# Helper function implementation
532+
}
533+
```
534+
535+
### Best Practices
536+
537+
- **Use skip comments sparingly**: Framework tests exist to maintain code quality and consistency. Only skip tests when absolutely necessary.
538+
- **Provide clear reasons**: Always include a meaningful explanation in the skip comment to help reviewers understand why the test is being skipped.
539+
- **Consider alternatives**: Before skipping a test, consider whether refactoring the code to comply with the test would be better for long-term maintainability.
540+
- **Document exceptions**: If you skip a test, document the reason in your PR description or code comments.
541+
542+
### Related Configuration
543+
544+
For broader test control, use the configuration file settings:
545+
546+
- Skip all framework tests: `Test.PSModule.Skip: true`
547+
- Skip only source code tests: `Test.SourceCode.Skip: true`
548+
- Skip framework tests on specific OS: `Test.PSModule.Windows.Skip: true`
549+
550+
See the [Configuration](#configuration) section for more details.
551+
448552
## Specifications and practices
449553

450554
The process is compatible with:

0 commit comments

Comments
 (0)