-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Unit Tests and Official Releases (#1854)
* Update Unit Tests * Update pester from 4 to 5 * Update compile and releases * Working on making release tags * Update release.yaml * Compile Winutil --------- Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com>
- Loading branch information
1 parent
88a622c
commit 9eceae6
Showing
4 changed files
with
5,585 additions
and
5,560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,55 @@ | ||
#=========================================================================== | ||
# Tests - Functions | ||
#=========================================================================== | ||
|
||
# Get all .ps1 files in the functions folder | ||
$ps1Files = Get-ChildItem -Path ./functions -Filter *.ps1 | ||
|
||
# Loop through each file | ||
foreach ($file in $ps1Files) { | ||
# Define the test name | ||
$testName = "Syntax check for $($file.Name)" | ||
|
||
# Define the test script | ||
$testScript = { | ||
# Import the script | ||
. $file.FullName | ||
|
||
# Check if any errors occurred | ||
$scriptError = $error[0] | ||
$scriptError | Should -Be $null | ||
Describe "Comprehensive Checks for PS1 Files in Functions Folder" { | ||
BeforeAll { | ||
# Get all .ps1 files in the functions folder | ||
$ps1Files = Get-ChildItem -Path ./functions -Filter *.ps1 -Recurse | ||
} | ||
|
||
# Add the test to the Pester test suite | ||
Describe $testName $testScript | ||
} | ||
foreach ($file in $ps1Files) { | ||
Context "Checking $($file.Name)" { | ||
It "Should import without errors" { | ||
{ . $file.FullName } | Should -Not -Throw | ||
} | ||
|
||
Describe "Functions"{ | ||
It "Should have no syntax errors" { | ||
$syntaxErrors = $null | ||
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path $file.FullName -Raw), [ref]$syntaxErrors) | ||
$syntaxErrors.Count | Should -Be 0 | ||
} | ||
|
||
It "Should not use deprecated cmdlets or aliases" { | ||
$content = Get-Content -Path $file.FullName -Raw | ||
# Example check for a known deprecated cmdlet or alias | ||
$content | Should -Not -Match 'DeprecatedCmdlet' | ||
# Add more checks as needed | ||
} | ||
|
||
Get-ChildItem .\functions -Recurse -File | ForEach-Object { | ||
It "Should follow naming conventions for functions" { | ||
$functions = (Get-Command -Path $file.FullName).Name | ||
foreach ($function in $functions) { | ||
$function | Should -Match '^[a-z]+(-[a-z]+)*$' # Enforce lower-kebab-case | ||
} | ||
} | ||
|
||
context "$($psitem.BaseName)" { | ||
BeforeEach -Scriptblock { | ||
. $psitem.FullName | ||
It "Should define mandatory parameters for all functions" { | ||
. $file.FullName | ||
$functions = (Get-Command -Path $file.FullName).Name | ||
foreach ($function in $functions) { | ||
$parameters = (Get-Command -Name $function).Parameters.Values | ||
$mandatoryParams = $parameters | Where-Object { $_.Attributes.Mandatory -eq $true } | ||
$mandatoryParams.Count | Should -BeGreaterThan 0 | ||
} | ||
} | ||
|
||
It "Imports with no errors" -TestCases @{ | ||
basename = $($psitem.BaseName) | ||
fullname = $psitem.FullName | ||
} { | ||
Get-ChildItem function:\$basename | Should -Not -BeNullOrEmpty | ||
} | ||
It "Should have all functions available after import" { | ||
. $file.FullName | ||
$functions = (Get-Command -Path $file.FullName).Name | ||
foreach ($function in $functions) { | ||
{ Get-Command -Name $function -CommandType Function } | Should -Not -BeNullOrEmpty | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.