diff --git a/pester/functions.Tests.ps1 b/pester/functions.Tests.ps1 index 1ec1e286f1..d02a31a02e 100644 --- a/pester/functions.Tests.ps1 +++ b/pester/functions.Tests.ps1 @@ -2,13 +2,35 @@ # 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 + } + + # Add the test to the Pester test suite + Describe $testName $testScript +} + Describe "Functions"{ Get-ChildItem .\functions -Recurse -File | ForEach-Object { context "$($psitem.BaseName)" { BeforeEach -Scriptblock { - . $fullname + . $psitem.FullName } It "Imports with no errors" -TestCases @{ diff --git a/pester/winutil.Tests.ps1 b/pester/winutil.Tests.ps1 deleted file mode 100644 index d9ecfe8a7a..0000000000 --- a/pester/winutil.Tests.ps1 +++ /dev/null @@ -1,23 +0,0 @@ -# Load Variables needed for testing - -./Compile.ps1 - -$script = Get-Content .\winutil.ps1 -ErrorAction Stop -# Remove the part of the script that shows the form, leaving only the variable and function declarations -$script[0..($script.count - 3)] | Out-File .\pester.ps1 -ErrorAction Stop - -Describe "Syntax" { - Context "pester.ps1" { - It "does not contain syntax errors" { - try { - . ./pester.ps1 - } - catch { - if ([System.Console]::IsOutputRedirected -eq $false) { - Write-Host "Error: $_" - } - throw $_ - } - } - } -} \ No newline at end of file