Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/Action-Test-Src-Default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Action-Test [Src-Default]

run-name: "Action-Test [Src-Default] - ${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"

on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: {}

jobs:
ActionTest:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
shell: [pwsh]
include:
- os: windows-latest
shell: powershell
name: Action-Test [Src-Default] - [${{ matrix.os }}@${{ matrix.shell }}]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Initialize environment
uses: PSModule/Initialize-PSModule@main
with:
Shell: ${{ matrix.shell }}

- name: Action-Test
uses: ./
env:
GITHUB_TOKEN: ${{ github.token }}
with:
Name: PSModuleTest
Path: tests/src
Shell: ${{ matrix.shell }}
TestType: SourceCode
42 changes: 42 additions & 0 deletions .github/workflows/Action-Test-Src-UnnamedFolder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Action-Test [Src-UnnamedFolder]

run-name: "Action-Test [Src-UnnamedFolder] - ${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"

on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: {}

jobs:
ActionTest:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
shell: [pwsh]
include:
- os: windows-latest
shell: powershell
name: Action-Test [Src-UnnamedFolder] - [${{ matrix.os }}@${{ matrix.shell }}]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Initialize environment
uses: PSModule/Initialize-PSModule@main
with:
Shell: ${{ matrix.shell }}

- name: Action-Test
uses: ./
env:
GITHUB_TOKEN: ${{ github.token }}
with:
Name: PSModuleTest
Path: tests/srcNo
Shell: ${{ matrix.shell }}
TestType: SourceCode
42 changes: 42 additions & 0 deletions .github/workflows/Action-Test-Src-UnnamedWithManifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Action-Test [Src-UnnamedWithManifest]

run-name: "Action-Test [Src-UnnamedWithManifest] - ${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"

on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: {}

jobs:
ActionTest:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
shell: [pwsh]
include:
- os: windows-latest
shell: powershell
name: Action-Test [Src-UnnamedWithManifest] - [${{ matrix.os }}@${{ matrix.shell }}]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Initialize environment
uses: PSModule/Initialize-PSModule@main
with:
Shell: ${{ matrix.shell }}

- name: Action-Test
uses: ./
env:
GITHUB_TOKEN: ${{ github.token }}
with:
Name: PSModuleTest
Path: tests/srcNoWithManifest
Shell: ${{ matrix.shell }}
TestType: SourceCode
42 changes: 42 additions & 0 deletions .github/workflows/Action-Test-outputs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Action-Test [outputs]

run-name: "Action-Test [outputs] - ${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"

on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: {}

jobs:
ActionTest:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
shell: [pwsh]
include:
- os: windows-latest
shell: powershell
name: Action-Test [outputs] - [${{ matrix.os }}@${{ matrix.shell }}]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Initialize environment
uses: PSModule/Initialize-PSModule@main
with:
Shell: ${{ matrix.shell }}

- name: Action-Test
uses: ./
env:
GITHUB_TOKEN: ${{ github.token }}
with:
Name: PSModuleTest
Path: tests/outputs/modules
Shell: ${{ matrix.shell }}
TestType: Module
70 changes: 0 additions & 70 deletions .github/workflows/Action-Test.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/Auto-Release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Auto-Release

run-name: "Auto-Release - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"
run-name: "${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"

on:
pull_request_target:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ jobs:
uses: super-linter/super-linter@latest
env:
GITHUB_TOKEN: ${{ github.token }}
FILTER_REGEX_EXCLUDE: ${{ github.workspace }}/tests
1 change: 1 addition & 0 deletions scripts/tests/PSScriptAnalyzer/Settings.SourceCode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
}
}
ExcludeRules = @(
'PSMissingModuleManifestField', # This rule is not applicable until the module is built.
'PSAvoidUsingCmdletAliases',
'PSUseToExportFieldsInManifest'
)
Expand Down
4 changes: 4 additions & 0 deletions tests/src/PSModuleTest/PSModuleTest.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@{
ModuleVersion = '0.0.0'
RootModule = 'PSModuleTest.psm1'
}
73 changes: 73 additions & 0 deletions tests/src/PSModuleTest/PSModuleTest.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[Cmdletbinding()]
param()

Write-Verbose 'Importing subcomponents'
$Folders = 'init', 'classes', 'private', 'public'
# Import everything in these folders
Foreach ($Folder in $Folders) {
$Root = Join-Path -Path $PSScriptRoot -ChildPath $Folder
Write-Verbose "Processing folder: $Root"
if (Test-Path -Path $Root) {
Write-Verbose "Getting all files in $Root"
$Files = $null
$Files = Get-ChildItem -Path $Root -Include '*.ps1', '*.psm1' -Recurse
# dot source each file
foreach ($File in $Files) {
Write-Verbose "Importing $($File)"
Import-Module $File
Write-Verbose "Importing $($File): Done"
}
}
}

. "$PSScriptRoot\finally.ps1"

# Define the types to export with type accelerators.
$ExportableTypes = @(
[Book]
[BookList]
)

# Get the internal TypeAccelerators class to use its static methods.
$TypeAcceleratorsClass = [psobject].Assembly.GetType(
'System.Management.Automation.TypeAccelerators'
)
# Ensure none of the types would clobber an existing type accelerator.
# If a type accelerator with the same name exists, throw an exception.
$ExistingTypeAccelerators = $TypeAcceleratorsClass::Get
foreach ($Type in $ExportableTypes) {
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
$Message = @(
"Unable to register type accelerator '$($Type.FullName)'"
'Accelerator already exists.'
) -join ' - '

throw [System.Management.Automation.ErrorRecord]::new(
[System.InvalidOperationException]::new($Message),
'TypeAcceleratorAlreadyExists',
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$Type.FullName
)
}
}
# Add type accelerators for every exportable type.
foreach ($Type in $ExportableTypes) {
$TypeAcceleratorsClass::Add($Type.FullName, $Type)
}
# Remove type accelerators when the module is removed.
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
foreach ($Type in $ExportableTypes) {
$TypeAcceleratorsClass::Remove($Type.FullName)
}
}.GetNewClosure()

$Param = @{
Function = (Get-ChildItem -Path "$PSScriptRoot\public" -Include '*.ps1' -Recurse).BaseName
Variable = '*'
Cmdlet = '*'
Alias = '*'
}

Write-Verbose 'Exporting module members'

Export-ModuleMember @Param
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/src/PSModuleTest/finally.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Write-Verbose '------------------------------' -Verbose
Write-Verbose '--- THIS IS A LAST LOADER ---' -Verbose
Write-Verbose '------------------------------' -Verbose

$MyInvocation | ConvertTo-Json
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/src/PSModuleTest/init/initializer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Write-Verbose '-------------------------------' -Verbose
Write-Verbose '--- THIS IS AN INITIALIZER ---' -Verbose
Write-Verbose '-------------------------------' -Verbose

$MyInvocation | ConvertTo-Json
29 changes: 29 additions & 0 deletions tests/src/PSModuleTest/public/New-PSModuleTest.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.0'}

function New-PSModuleTest {
<#
.SYNOPSIS
Performs tests on a module.

.EXAMPLE
Test-PSModule -Name 'World'

"Hello, World!"

.NOTES
Testing if a module can have a [Markdown based link](https://example.com).
!"#¤%&/()=?`´^¨*'-_+§½{[]}<>|@£$€¥¢:;.,"
\[This is a test\]
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
Justification = 'Reason for suppressing'
)]
[CmdletBinding()]
param (
# Name of the person to greet.
[Parameter(Mandatory)]
[string] $Name
)
Write-Output "Hello, $Name!"
}
5 changes: 5 additions & 0 deletions tests/src/PSModuleTest/scripts/loader.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Write-Verbose '-------------------------' -Verbose
Write-Verbose '--- THIS IS A LOADER ---' -Verbose
Write-Verbose '-------------------------' -Verbose

$MyInvocation | ConvertTo-Json
Binary file added tests/srcNo/assemblies/LsonLib.dll
Binary file not shown.
Loading