diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Auto-Release.yml index ec157c9d..a8f1413e 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Auto-Release.yml @@ -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: diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index 5c9f300c..02f8fbac 100644 --- a/.github/workflows/Linter.yml +++ b/.github/workflows/Linter.yml @@ -1,6 +1,6 @@ name: Linter -run-name: "Linter - [${{ 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] diff --git a/.github/workflows/Workflow-Test.yml b/.github/workflows/Workflow-Test-Default.yml similarity index 74% rename from .github/workflows/Workflow-Test.yml rename to .github/workflows/Workflow-Test-Default.yml index 1dc8163a..4c86d5d7 100644 --- a/.github/workflows/Workflow-Test.yml +++ b/.github/workflows/Workflow-Test-Default.yml @@ -1,6 +1,6 @@ -name: Workflow-Test +name: Workflow-Test [Default] -run-name: "Workflow-Test - [${{ 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] diff --git a/.github/workflows/Workflow-Test-Unnamed.yml b/.github/workflows/Workflow-Test-Unnamed.yml new file mode 100644 index 00000000..9653a732 --- /dev/null +++ b/.github/workflows/Workflow-Test-Unnamed.yml @@ -0,0 +1,25 @@ +name: Workflow-Test [UnnamedFolder] + +run-name: "${{ 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: + contents: write + pull-requests: write + statuses: write + +jobs: + WorkflowTestUnnamedFolder: + uses: ./.github/workflows/workflow.yml + secrets: inherit + with: + Name: PSModuleTest + Path: tests/srcNo + ModulesOutputPath: tests/outputs/modules + DocsOutputPath: tests/outputs/docs + TestProcess: true diff --git a/tests/srcNo/assemblies/LsonLib.dll b/tests/srcNo/assemblies/LsonLib.dll new file mode 100644 index 00000000..36618070 Binary files /dev/null and b/tests/srcNo/assemblies/LsonLib.dll differ diff --git a/tests/srcNo/classes/Book.ps1 b/tests/srcNo/classes/Book.ps1 new file mode 100644 index 00000000..3e22c270 --- /dev/null +++ b/tests/srcNo/classes/Book.ps1 @@ -0,0 +1,132 @@ +class Book { + # Class properties + [string] $Title + [string] $Author + [string] $Synopsis + [string] $Publisher + [datetime] $PublishDate + [int] $PageCount + [string[]] $Tags + # Default constructor + Book() { $this.Init(@{}) } + # Convenience constructor from hashtable + Book([hashtable]$Properties) { $this.Init($Properties) } + # Common constructor for title and author + Book([string]$Title, [string]$Author) { + $this.Init(@{Title = $Title; Author = $Author }) + } + # Shared initializer method + [void] Init([hashtable]$Properties) { + foreach ($Property in $Properties.Keys) { + $this.$Property = $Properties.$Property + } + } + # Method to calculate reading time as 2 minutes per page + [timespan] GetReadingTime() { + if ($this.PageCount -le 0) { + throw 'Unable to determine reading time from page count.' + } + $Minutes = $this.PageCount * 2 + return [timespan]::new(0, $Minutes, 0) + } + # Method to calculate how long ago a book was published + [timespan] GetPublishedAge() { + if ( + $null -eq $this.PublishDate -or + $this.PublishDate -eq [datetime]::MinValue + ) { throw 'PublishDate not defined' } + + return (Get-Date) - $this.PublishDate + } + # Method to return a string representation of the book + [string] ToString() { + return "$($this.Title) by $($this.Author) ($($this.PublishDate.Year))" + } +} + +class BookList { + # Static property to hold the list of books + static [System.Collections.Generic.List[Book]] $Books + # Static method to initialize the list of books. Called in the other + # static methods to avoid needing to explicit initialize the value. + static [void] Initialize() { [BookList]::Initialize($false) } + static [bool] Initialize([bool]$force) { + if ([BookList]::Books.Count -gt 0 -and -not $force) { + return $false + } + + [BookList]::Books = [System.Collections.Generic.List[Book]]::new() + + return $true + } + # Ensure a book is valid for the list. + static [void] Validate([book]$Book) { + $Prefix = @( + 'Book validation failed: Book must be defined with the Title,' + 'Author, and PublishDate properties, but' + ) -join ' ' + if ($null -eq $Book) { throw "$Prefix was null" } + if ([string]::IsNullOrEmpty($Book.Title)) { + throw "$Prefix Title wasn't defined" + } + if ([string]::IsNullOrEmpty($Book.Author)) { + throw "$Prefix Author wasn't defined" + } + if ([datetime]::MinValue -eq $Book.PublishDate) { + throw "$Prefix PublishDate wasn't defined" + } + } + # Static methods to manage the list of books. + # Add a book if it's not already in the list. + static [void] Add([Book]$Book) { + [BookList]::Initialize() + [BookList]::Validate($Book) + if ([BookList]::Books.Contains($Book)) { + throw "Book '$Book' already in list" + } + + $FindPredicate = { + param([Book]$b) + + $b.Title -eq $Book.Title -and + $b.Author -eq $Book.Author -and + $b.PublishDate -eq $Book.PublishDate + }.GetNewClosure() + if ([BookList]::Books.Find($FindPredicate)) { + throw "Book '$Book' already in list" + } + + [BookList]::Books.Add($Book) + } + # Clear the list of books. + static [void] Clear() { + [BookList]::Initialize() + [BookList]::Books.Clear() + } + # Find a specific book using a filtering scriptblock. + static [Book] Find([scriptblock]$Predicate) { + [BookList]::Initialize() + return [BookList]::Books.Find($Predicate) + } + # Find every book matching the filtering scriptblock. + static [Book[]] FindAll([scriptblock]$Predicate) { + [BookList]::Initialize() + return [BookList]::Books.FindAll($Predicate) + } + # Remove a specific book. + static [void] Remove([Book]$Book) { + [BookList]::Initialize() + [BookList]::Books.Remove($Book) + } + # Remove a book by property value. + static [void] RemoveBy([string]$Property, [string]$Value) { + [BookList]::Initialize() + $Index = [BookList]::Books.FindIndex({ + param($b) + $b.$Property -eq $Value + }.GetNewClosure()) + if ($Index -ge 0) { + [BookList]::Books.RemoveAt($Index) + } + } +} diff --git a/tests/srcNo/data/Config.psd1 b/tests/srcNo/data/Config.psd1 new file mode 100644 index 00000000..fea44669 --- /dev/null +++ b/tests/srcNo/data/Config.psd1 @@ -0,0 +1,3 @@ +@{ + RandomKey = 'RandomValue' +} diff --git a/tests/srcNo/data/Settings.psd1 b/tests/srcNo/data/Settings.psd1 new file mode 100644 index 00000000..bcfa7b47 --- /dev/null +++ b/tests/srcNo/data/Settings.psd1 @@ -0,0 +1,3 @@ +@{ + RandomSetting = 'RandomSettingValue' +} diff --git a/tests/srcNo/finally.ps1 b/tests/srcNo/finally.ps1 new file mode 100644 index 00000000..e51c2260 --- /dev/null +++ b/tests/srcNo/finally.ps1 @@ -0,0 +1,3 @@ +Write-Verbose '------------------------------' -Verbose +Write-Verbose '--- THIS IS A LAST LOADER ---' -Verbose +Write-Verbose '------------------------------' -Verbose diff --git a/tests/srcNo/formats/CultureInfo.Format.ps1xml b/tests/srcNo/formats/CultureInfo.Format.ps1xml new file mode 100644 index 00000000..a715e08a --- /dev/null +++ b/tests/srcNo/formats/CultureInfo.Format.ps1xml @@ -0,0 +1,37 @@ + + + + + System.Globalization.CultureInfo + + System.Globalization.CultureInfo + + + + + 16 + + + 16 + + + + + + + + LCID + + + Name + + + DisplayName + + + + + + + + diff --git a/tests/srcNo/formats/Mygciview.Format.ps1xml b/tests/srcNo/formats/Mygciview.Format.ps1xml new file mode 100644 index 00000000..4c972c2c --- /dev/null +++ b/tests/srcNo/formats/Mygciview.Format.ps1xml @@ -0,0 +1,65 @@ + + + + + mygciview + + System.IO.DirectoryInfo + System.IO.FileInfo + + + PSParentPath + + + + + + 7 + Left + + + + 26 + Right + + + + 26 + Right + + + + 14 + Right + + + + Left + + + + + + + + ModeWithoutHardLink + + + LastWriteTime + + + CreationTime + + + Length + + + Name + + + + + + + + diff --git a/tests/srcNo/header.ps1 b/tests/srcNo/header.ps1 new file mode 100644 index 00000000..cc1fde9a --- /dev/null +++ b/tests/srcNo/header.ps1 @@ -0,0 +1,3 @@ +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains long links.')] +[CmdletBinding()] +param() diff --git a/tests/srcNo/init/initializer.ps1 b/tests/srcNo/init/initializer.ps1 new file mode 100644 index 00000000..f4121d25 --- /dev/null +++ b/tests/srcNo/init/initializer.ps1 @@ -0,0 +1,3 @@ +Write-Verbose '-------------------------------' -Verbose +Write-Verbose '--- THIS IS AN INITIALIZER ---' -Verbose +Write-Verbose '-------------------------------' -Verbose diff --git a/tests/srcNo/modules/OtherPSModule.psm1 b/tests/srcNo/modules/OtherPSModule.psm1 new file mode 100644 index 00000000..9e4353ba --- /dev/null +++ b/tests/srcNo/modules/OtherPSModule.psm1 @@ -0,0 +1,19 @@ +Function Get-OtherPSModule { + <# + .SYNOPSIS + Performs tests on a module. + + .DESCRIPTION + A longer description of the function. + + .EXAMPLE + Get-OtherPSModule -Name 'World' + #> + [CmdletBinding()] + param( + # Name of the person to greet. + [Parameter(Mandatory)] + [string] $Name + ) + Write-Output "Hello, $Name!" +} diff --git a/tests/srcNo/private/Get-InternalPSModule.ps1 b/tests/srcNo/private/Get-InternalPSModule.ps1 new file mode 100644 index 00000000..3366e44b --- /dev/null +++ b/tests/srcNo/private/Get-InternalPSModule.ps1 @@ -0,0 +1,18 @@ +Function Get-InternalPSModule { + <# + .SYNOPSIS + Performs tests on a module. + + .EXAMPLE + Test-PSModule -Name 'World' + + "Hello, World!" + #> + [CmdletBinding()] + param ( + # Name of the person to greet. + [Parameter(Mandatory)] + [string] $Name + ) + Write-Output "Hello, $Name!" +} diff --git a/tests/srcNo/private/Set-InternalPSModule.ps1 b/tests/srcNo/private/Set-InternalPSModule.ps1 new file mode 100644 index 00000000..11c2fa15 --- /dev/null +++ b/tests/srcNo/private/Set-InternalPSModule.ps1 @@ -0,0 +1,22 @@ +Function Set-InternalPSModule { + <# + .SYNOPSIS + Performs tests on a module. + + .EXAMPLE + Test-PSModule -Name 'World' + + "Hello, World!" + #> + [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!" +} diff --git a/tests/srcNo/public/Get-PSModuleTest.ps1 b/tests/srcNo/public/Get-PSModuleTest.ps1 new file mode 100644 index 00000000..0e9aacfe --- /dev/null +++ b/tests/srcNo/public/Get-PSModuleTest.ps1 @@ -0,0 +1,20 @@ +#Requires -Modules Utilities + +function Get-PSModuleTest { + <# + .SYNOPSIS + Performs tests on a module. + + .EXAMPLE + Test-PSModule -Name 'World' + + "Hello, World!" + #> + [CmdletBinding()] + param ( + # Name of the person to greet. + [Parameter(Mandatory)] + [string] $Name + ) + Write-Output "Hello, $Name!" +} diff --git a/tests/srcNo/public/New-PSModuleTest.ps1 b/tests/srcNo/public/New-PSModuleTest.ps1 new file mode 100644 index 00000000..7f26215f --- /dev/null +++ b/tests/srcNo/public/New-PSModuleTest.ps1 @@ -0,0 +1,24 @@ +#Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.0'} + +function New-PSModuleTest { + <# + .SYNOPSIS + Performs tests on a module. + + .EXAMPLE + Test-PSModule -Name 'World' + + "Hello, World!" + #> + [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!" +} diff --git a/tests/srcNo/public/Set-PSModuleTest.ps1 b/tests/srcNo/public/Set-PSModuleTest.ps1 new file mode 100644 index 00000000..a87ac117 --- /dev/null +++ b/tests/srcNo/public/Set-PSModuleTest.ps1 @@ -0,0 +1,22 @@ +function Set-PSModuleTest { + <# + .SYNOPSIS + Performs tests on a module. + + .EXAMPLE + Test-PSModule -Name 'World' + + "Hello, World!" + #> + [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!" +} diff --git a/tests/srcNo/public/Test-PSModuleTest.ps1 b/tests/srcNo/public/Test-PSModuleTest.ps1 new file mode 100644 index 00000000..26be2b9b --- /dev/null +++ b/tests/srcNo/public/Test-PSModuleTest.ps1 @@ -0,0 +1,18 @@ +function Test-PSModuleTest { + <# + .SYNOPSIS + Performs tests on a module. + + .EXAMPLE + Test-PSModule -Name 'World' + + "Hello, World!" + #> + [CmdletBinding()] + param ( + # Name of the person to greet. + [Parameter(Mandatory)] + [string] $Name + ) + Write-Output "Hello, $Name!" +} diff --git a/tests/srcNo/scripts/loader.ps1 b/tests/srcNo/scripts/loader.ps1 new file mode 100644 index 00000000..29ad42f6 --- /dev/null +++ b/tests/srcNo/scripts/loader.ps1 @@ -0,0 +1,3 @@ +Write-Verbose '-------------------------' -Verbose +Write-Verbose '--- THIS IS A LOADER ---' -Verbose +Write-Verbose '-------------------------' -Verbose diff --git a/tests/srcNo/types/DirectoryInfo.Types.ps1xml b/tests/srcNo/types/DirectoryInfo.Types.ps1xml new file mode 100644 index 00000000..aef538b2 --- /dev/null +++ b/tests/srcNo/types/DirectoryInfo.Types.ps1xml @@ -0,0 +1,21 @@ + + + + System.IO.FileInfo + + + Status + Success + + + + + System.IO.DirectoryInfo + + + Status + Success + + + + diff --git a/tests/srcNo/types/FileInfo.Types.ps1xml b/tests/srcNo/types/FileInfo.Types.ps1xml new file mode 100644 index 00000000..4cfaf6b8 --- /dev/null +++ b/tests/srcNo/types/FileInfo.Types.ps1xml @@ -0,0 +1,14 @@ + + + + System.IO.FileInfo + + + Age + + ((Get-Date) - ($this.CreationTime)).Days + + + + +