Skip to content

Commit 0d00563

Browse files
Merge branch 'main' of https://github.com/PSModule/Process-PSModule into 001-settings-driven-workflow
2 parents 4c2dc40 + 3dcca81 commit 0d00563

File tree

1 file changed

+106
-1
lines changed

1 file changed

+106
-1
lines changed

README.md

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,112 @@ This is useful for reviewing what was checked even when no issues are found.
564564

565565
**Note:** The `GITHUB_TOKEN` is automatically provided by the workflow to enable status updates in pull requests.
566566

567-
For a complete list of available environment variables and configuration options, see the [super-linter environment variables documentation](https://github.com/super-linter/super-linter#environment-variables).
567+
For a complete list of available environment variables and configuration options, see the
568+
[super-linter environment variables documentation](https://github.com/super-linter/super-linter#environment-variables).
569+
570+
## Skipping Individual Framework Tests
571+
572+
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.
573+
574+
### How to Skip Tests
575+
576+
To skip an individual framework test for a specific file, add a special comment at the top of that file:
577+
578+
```powershell
579+
#SkipTest:<TestID>:<Reason>
580+
```
581+
582+
- `<TestID>`: The unique identifier of the test to skip (see list below)
583+
- `<Reason>`: A brief explanation of why the test is being skipped
584+
585+
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.
586+
587+
### Available Framework Tests
588+
589+
#### SourceCode Tests
590+
591+
These tests run against your source code files in the `src` directory:
592+
593+
| Test ID | Description | Example Skip Comment |
594+
|---------|-------------|---------------------|
595+
| `NumberOfProcessors` | Enforces use of `[System.Environment]::ProcessorCount` instead of `$env:NUMBER_OF_PROCESSORS` | `#SkipTest:NumberOfProcessors:Legacy code compatibility required` |
596+
| `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` |
597+
| `OutNull` | Enforces use of `$null = ...` instead of `... \| Out-Null` for better performance | `#SkipTest:OutNull:Pipeline processing required` |
598+
| `NoTernary` | Prohibits ternary operators for PowerShell 5.1 compatibility (this test is skipped by default in the framework) | `#SkipTest:NoTernary:PowerShell 7+ only module` |
599+
| `LowercaseKeywords` | Ensures all PowerShell keywords are lowercase | `#SkipTest:LowercaseKeywords:Generated code` |
600+
| `FunctionCount` | Ensures each file contains exactly one function | `#SkipTest:FunctionCount:Helper functions included` |
601+
| `FunctionName` | Ensures the filename matches the function name | `#SkipTest:FunctionName:Legacy naming convention` |
602+
| `CmdletBinding` | Requires all functions to have `[CmdletBinding()]` attribute | `#SkipTest:CmdletBinding:Simple helper function` |
603+
| `ParamBlock` | Requires all functions to have a `param()` block | `#SkipTest:ParamBlock:No parameters needed` |
604+
| `FunctionTest` | Ensures all public functions have corresponding tests | `#SkipTest:FunctionTest:Test in development` |
605+
606+
#### Module Tests
607+
608+
These tests run against the compiled module in the `outputs/module` directory:
609+
610+
- Module import validation
611+
- Module manifest validation
612+
613+
Module tests typically don't need to be skipped as they validate the final built module.
614+
615+
### Example Usage
616+
617+
Here's an example of a function file that skips the `FunctionCount` test because it includes helper functions:
618+
619+
```powershell
620+
#SkipTest:FunctionCount:This file contains helper functions for the main function
621+
622+
function Get-ComplexData {
623+
<#
624+
.SYNOPSIS
625+
Retrieves complex data using helper functions.
626+
#>
627+
[CmdletBinding()]
628+
param(
629+
[Parameter(Mandatory)]
630+
[string] $Path
631+
)
632+
633+
$data = Get-RawData -Path $Path
634+
$processed = Format-ComplexData -Data $data
635+
return $processed
636+
}
637+
638+
function Get-RawData {
639+
[CmdletBinding()]
640+
param(
641+
[Parameter(Mandatory)]
642+
[string] $Path
643+
)
644+
# Helper function implementation
645+
}
646+
647+
function Format-ComplexData {
648+
[CmdletBinding()]
649+
param(
650+
[Parameter(Mandatory)]
651+
$Data
652+
)
653+
# Helper function implementation
654+
}
655+
```
656+
657+
### Best Practices
658+
659+
- **Use skip comments sparingly**: Framework tests exist to maintain code quality and consistency. Only skip tests when absolutely necessary.
660+
- **Provide clear reasons**: Always include a meaningful explanation in the skip comment to help reviewers understand why the test is being skipped.
661+
- **Consider alternatives**: Before skipping a test, consider whether refactoring the code to comply with the test would be better for long-term maintainability.
662+
- **Document exceptions**: If you skip a test, document the reason in your PR description or code comments.
663+
664+
### Related Configuration
665+
666+
For broader test control, use the configuration file settings:
667+
668+
- Skip all framework tests: `Test.PSModule.Skip: true`
669+
- Skip only source code tests: `Test.SourceCode.Skip: true`
670+
- Skip framework tests on specific OS: `Test.PSModule.Windows.Skip: true`
671+
672+
See the [Configuration](#configuration) section for more details.
568673

569674
## Repository structure
570675

0 commit comments

Comments
 (0)